####################10.HTTPS虛擬主機####################
>測試:https://news.westos.com/
-->I Understand the Risks-->Add Exception-->Confirm Security Exception
>顯示:www.westos.com
[root@web1 conf.d]# vim news.conf
-----------------------------------------------
:sp /etc/httpd/conf.d/ssl.conf ##將兩個文件分屏顯示,使用"ctrl+w 上|下"來切換
9 <Virtualhost *:443>
10 Servername news.westos.com
11 Documentroot /var/www/virtual/news/html
12 Customlog logs/news-443.log combined
13 SSLEngine on
14 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
15 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
16 </Virtualhost>
:wq
-----------------------------------------------
/13行到15行的內容是從"ssl.conf"中拷貝過來的,以切換分屏來實現複製粘貼
[root@web1 conf.d]# systemctl reload httpd
>測試:https://news.westos.com(需清空緩存:ctrl+shift+delete)
>顯示:news.westos.com
####################11.網頁重寫####################
[root@web1 conf.d]# vim news.conf
-----------------------------------------------
1 <Virtualhost *:80>
2 Servername news.westos.com
3 RewriteEngine on
4 RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
5 </Virtualhost>
:wq
-----------------------------------------------
[root@web1 conf.d]# systemctl reload httpd
>測試:news.westos.com
>重定向到:https://news.westos.com
####################12.php####################
http默認支持html,php,cgi,wsgi
[root@web1 conf.d]# ls
autoindex.conf manual.conf news.conf ssl.conf userdir.conf
default.conf music.conf README tmprequest welcome.conf
[root@web1 conf.d]# cd /var/www/html/
[root@web1 html]# ls
index.html
[root@web1 html]# vim index.php
-----------------------------------------------
1 <?php
2 phpinfo ();
3 ?>
:wq
-----------------------------------------------
[root@web1 html]# vim /etc/httpd/conf/httpd.conf
-----------------------------------------------
164 DirectoryIndex index.php index.html
:wq
-----------------------------------------------
[root@web1 html]# systemctl reload httpd.service
>測試:http://172.25.50.100(需清空緩存:ctrl+shift+delete)
>無任何顯示
[root@web1 html]# yum install php -y
......
[root@web1 html]# ls /etc/httpd/conf.d/
autoindex.conf manual.conf news.conf README tmprequest welcome.conf
default.conf music.conf php.conf ssl.conf userdir.conf
##多了php.conf
[root@web1 html]# systemctl reload httpd.service ##"reload"無法使php生效
>測試:http://172.25.50.100
>無任何顯示
[root@web1 html]# systemctl restart httpd.service ##"restart"才能使php生效
>測試:http://172.25.50.100
>顯示:php測試頁面
####################13.cgi####################
[root@web1 html]# mkdir cgi
[root@web1 html]# ls
cgi index.html index.php
[root@web1 html]# cd cgi/
>firefox打開http://172.25.50.100/manual/-->CGI: Dynamic Content
[root@web1 cgi]# vim index.cgi
-----------------------------------------------
1 #!/usr/bin/perl
2 print "Content-type: text/html\n\n";
3 print `date`;
:wq
-----------------------------------------------
/以上內容是從Apache手冊中拷貝過來的,並將"Hello, World."改爲`date`
[root@web1 cgi]# perl index.cgi ##使用perl命令執行
Content-type: text/html
Mon Dec 12 20:30:14 EST 2016 ##執行成功!表示index.cgi的內容正確,可以使用
[root@web1 cgi]# chmod +x index.cgi
[root@web1 cgi]# cd /etc/httpd/conf.d/
[root@web1 conf.d]# vim default.conf
-----------------------------------------------
5 <Directory "/var/www/html/cgi">
6 Options +ExecCGI
7 AddHandler cgi-script .cgi
8 </Directory>
:wq
-----------------------------------------------
[root@web1 conf.d]# systemctl reload httpd
>測試:http://172.25.50.100/cgi/inde.cgi
>顯示:Internal Server Error
[root@web1 conf.d]# ls -Zd /var/www/cgi-bin/
drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 /var/www/cgi-bin/
[root@web1 conf.d]# ls -Zd /var/www/html/cgi/
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/cgi/
[root@web1 conf.d]# semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'
[root@web1 conf.d]# restorecon -FvvR /var/www/html/cgi/
restorecon reset /var/www/html/cgi context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_script_exec_t:s0
restorecon reset /var/www/html/cgi/index.cgi context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_script_exec_t:s0
>測試:http://172.25.50.100/cgi/index.cgi
>顯示:Mon Dec 12 20:59:34 EST 2016
>點擊刷新
>顯示:Mon Dec 12 20:59:52 EST 2016
>點擊刷新
>顯示:Mon Dec 12 20:59:59 EST 2016
####################14.搭建論壇####################
[root@web1 conf.d]# yum install mariadb-server -y
......
[root@web1 conf.d]# vim /etc/my.cnf
-----------------------------------------------
10 skip-networking=1
:wq
-----------------------------------------------
[root@web1 conf.d]# systemctl start mariadb
[root@web1 conf.d]# mysql_secure_installation
......
>Set root password "westos"
[root@web1 conf.d]# cd /var/www/html/
[root@web1 html]# ls
cgi index.html index.php
[root@foundation50 pub]# pwd
/root/Documents/RHCE/老李LFTP/pub
[root@foundation50 pub]# scp Discuz_X3.2_SC_UTF8.zip [email protected]:/var/www/html/
[email protected]'s password:
Discuz_X3.2_SC_UTF8.zip 100% 12MB 11.9MB/s 00:01
[root@web1 html]# ls
cgi Discuz_X3.2_SC_UTF8.zip index.html index.php
[root@web1 html]# unzip Discuz_X3.2_SC_UTF8.zip
......
[root@web1 html]# ls
cgi Discuz_X3.2_SC_UTF8.zip index.html index.php readme upload utility
[root@web1 html]# less readme/readme.txt
-----------------------------------------------
截取重要內容:
+----------------------------------+
Discuz! X 社區軟件的安裝
+----------------------------------+
1. 上傳 upload 目錄中的文件到服務器
2. 設置目錄屬性(windows 服務器可忽略這一步)
以下這些目錄需要可讀寫權限
./config
./data 含子目錄
3. 執行安裝腳本 /install/
請在瀏覽器中運行 install 程序,即訪問 http://您的域名/論壇目錄/install/
4. 參照頁面提示,進行安裝,直至安裝完畢
-----------------------------------------------
[root@web1 html]# chmod 777 upload/data/ upload/config/
>測試:http://172.25.50.100/upload/
-->我同意
>所有文件不可寫,mysql不支持
[root@web1 html]# setenforce 0
>刷新網頁
>只有前4個文件顯示可寫,mysql不支持
[root@web1 html]# chmod 777 upload/ -R
>刷新網頁
>所有文件可寫,mysql不支持
[root@web1 html]# yum install php-mysql -y
......
[root@web1 html]# systemctl reload httpd
>刷新網頁
>所有文件可寫,mysql支持
-->下一步-->下一步
-->數據庫密碼:westos-->管理員密碼:(自行設定)-->下一步
>等待安裝完成,重新輸入網址:http://172.25.50.100/upload/
>安裝成功!!!
--安裝完成,以下爲體驗--
-->輸入管理員密碼-->登陸-->輸入驗證碼-->登陸
-->用戶組:管理員
-->模塊管理
-->管理中心
####################15.squid正向代理####################
[root@foundation50 ~]# ls /etc/httpd/conf.d/
autoindex.conf README userdir.conf welcome.conf
[root@foundation50 ~]# yum install squid -y
......
[root@foundation50 ~]# ls /etc/httpd/conf.d/
autoindex.conf README squid.conf userdir.conf welcome.conf
[root@foundation50 ~]# vim /etc/squid/squid.conf
-----------------------------------------------
56 http_access allow all
62 cache_dir ufs /var/spool/squid 100 16 256
:wq
-----------------------------------------------
[root@foundation50 ~]# ls /var/spool/squid/
##什麼都沒有
[root@foundation50 ~]# systemctl start squid
[root@foundation50 ~]# systemctl enable squid.service
Created symlink from /etc/systemd/system/multi-user.target.wants/squid.service to /usr/lib/systemd/system/squid.service.
[root@foundation50 ~]# netstat -antlpe |grep squid
tcp6 0 0 :::3128 :::* LISTEN 0 531476 7398/(squid-1)
[root@web1 conf.d]# firefox &
>測試:www.baidu.com
>提示:一直是"Connecting..."狀態
-->Edit-->Preferences-->Advanced-->Network-->Settings...
-->Manual proxy configuration-->HTTP Proxy:172.25.50.250-->Port:3128
-->OK-->Close
>再次測試:www.baidu.com
>打開百度成功!!!
--取消代理--
-->Edit-->Preferences-->Advanced-->Network-->Settings...
-->Manual proxy configuration-->No proxy
-->OK-->Close
--刪除squid服務--
[root@foundation50 ~]# systemctl stop squid
[root@foundation50 ~]# yum remove squid -y
......
[root@foundation50 ~]# rm -fr /etc/squid/
在亞馬遜租一臺Linux服務器,裝上squid,然後在本機指定代理後,就能訪問國外的網站
####################16.squid反向代理####################
CDN加速
交叉存儲
[root@web1 ~]# yum remove httpd -y
......
[root@web1 ~]# netstat -antlpe |grep :80
[root@web1 ~]# yum install squid -y
......
[root@web1 ~]# vim /etc/squid/squid.conf
-----------------------------------------------
56 http_access allow all
59 http_port 80 vhost vport
60 cache_peer 172.25.50.165 parent 80 0 no-query
62 cache_dir ufs /var/spool/squid 100 16 256
:wq
-----------------------------------------------
[root@web1 ~]# systemctl start squid
[root@web1 ~]# netstat -antlpe |grep :80
tcp6 0 0 :::80 :::* LISTEN 0 41808 2069/(squid-1)
>分別爲虛擬機172.25.50.165和虛擬機172.25.50.171搭建好http服務,然後使用真機進行測試
[root@foundation50 Desktop]# firefox &
>測試:172.25.50.165
>顯示:172.25.50.165
>測試:172.25.50.171
>顯示:172.25.50.171
注意:同時開啓三臺虛擬機會有點卡,可以使用"init 3"關閉圖形。需要時,再使用"init 5"打開圖形
>測試:172.25.50.100
>顯示:172.25.50.165
[root@web1 ~]# vim /etc/squid/squid.conf
-----------------------------------------------
/修改
60 cache_peer 172.25.50.165 parent 80 0 no-query originserver round-robin name=web1
/插入
61 cache_peer 172.25.50.171 parent 80 0 no-query originserver round-robin name=web2
62 cache_peer_domain web1 web2 www.taobao.com
:wq
-----------------------------------------------
[root@web1 ~]# systemctl restart squid
[root@foundation50 Desktop]# vim /etc/hosts
-----------------------------------------------
4 172.25.50.100 www.taobao.com
:wq
-----------------------------------------------
>真機斷開外網
[root@foundation50 Desktop]# firefox &
--> Ctrl+Shift+Delete --> 把最後兩項打鉤 --> Clear Now(清空緩存)
>測試:172.25.50.100
>顯示:172.25.50.165
>刷新
>顯示:172.25.50.171
>刷新
>顯示:172.25.50.165
>刷新
>顯示:172.25.50.171
輪詢生效!!!
#####################
##### bash腳本 #####
#####################
/lib是系統庫文件存放的位置,所謂"庫"就是函數的集合
執行腳本是打開一個新的shell,完成後關閉這個shell
==bash==
[root@localhost mnt]# vim 1.sh
-----------------------------------------------
#!/bin/bash
echo hello world
:wq
-----------------------------------------------
[root@localhost mnt]# sh 1.sh
hello world
[root@localhost mnt]# chmod +x 1.sh
[root@localhost mnt]# /mnt/1.sh
hello world
[root@localhost mnt]# ./1.sh
hello world
==tcsh==
[root@localhost ~]# ps aux |grep tcsh
root 2118 0.0 0.0 112640 936 pts/1 R+ 22:03 0:00 grep --color=auto tcsh
[root@localhost mnt]# vim 2.sh
-----------------------------------------------
#!/bin/tcsh
watch -n 1 date
:wq
-----------------------------------------------
[root@localhost mnt]# sh 2.sh
[root@localhost ~]# ps aux |grep tcsh
root 2142 0.0 0.0 112640 940 pts/1 R+ 22:04 0:00 grep --color=auto tcsh
[root@localhost mnt]# chmod +x 2.sh
[root@localhost mnt]# /mnt/2.sh
[root@localhost ~]# ps aux |grep tcsh
root 2255 0.1 0.2 120228 2112 pts/0 S+ 22:05 0:00 /bin/tcsh /mnt/2.sh
root 2283 0.0 0.0 112640 940 pts/1 S+ 22:05 0:00 grep --color=auto tcsh
[root@localhost ~]#
==env==
[root@localhost mnt]# which env
/usr/bin/env
[root@localhost mnt]# vim 1.sh
-----------------------------------------------
#!/usr/bin/env bash ##表示不知道bash在哪兒,通過env去找
echo hello world
:wq
-----------------------------------------------
[root@localhost mnt]# ./1.sh
hello world
[root@localhost mnt]# vim 2.sh
-----------------------------------------------
#!/usr/bin/env tcsh ##表示不知道tcsh在哪兒,通過env去找
watch -n 1 date
:wq
-----------------------------------------------
[root@localhost mnt]# ./1.sh
>開啓watch監控
==腳本調式模式"-x"==
[root@localhost mnt]# sh -x 1.sh
+ echo hello world
hello world
[root@localhost mnt]# vim 3.sh
-----------------------------------------------
#!/bin/bash -x
cat /mnt/3.sh
:wq
-----------------------------------------------
[root@localhost mnt]# sh 3.sh
#!/bin/bash -x
cat /mnt/3.sh
[root@localhost mnt]# chmod +x 3.sh
[root@localhost mnt]# ./3.sh
+ cat /mnt/3.sh
#!/bin/bash -x
cat /mnt/3.sh
==單引用和雙引用==
單引號是強引用,引號內全部被引用
雙引用是弱引用,不能引用$ ! `` \
[root@localhost mnt]# echo $USER
root
[root@localhost mnt]# echo "$USER"
root
[root@localhost mnt]# echo '$USER'
$USER
[root@localhost mnt]# echo '"$USER"'
"$USER"
[root@localhost mnt]# echo "'$USER'"
'root'
[root@localhost mnt]# echo $5
[root@localhost mnt]# echo $"5"
5
[root@localhost mnt]# echo "$"5
$5
[root@localhost mnt]# echo '$'5
$5
[root@localhost mnt]# echo \$5 ##\和''的作用差不多
$5
[root@localhost mnt]# echo "\$5"
$5
[root@localhost mnt]# echo '\$5'
\$5
[root@localhost mnt]# echo '''' ##單引號就近引用
[root@localhost mnt]# echo """" ##雙引號就近引用
[root@localhost mnt]# echo '""'
""
[root@localhost mnt]# echo "''"
''
[root@localhost mnt]# echo \'\'
''
[root@localhost mnt]# echo # hello #
[root@localhost mnt]# echo \# hello #
# hello
[root@localhost mnt]# echo \# hello \#
# hello #
[root@localhost mnt]# echo '`date`'
`date`
[root@localhost mnt]# echo "`date`"
Tue Dec 13 22:45:05 EST 2016
[root@localhost mnt]# echo * ##"*"顯示當前目錄下的所有文件名
1.sh 2.sh 3.sh
[root@localhost mnt]# echo * *
1.sh 2.sh 3.sh 1.sh 2.sh 3.sh
[root@localhost mnt]# echo "*"
*
[root@localhost mnt]# echo "*****`date`*****"
*****Tue Dec 13 22:56:52 EST 2016*****
==變量==
--1.shell下直接定義--
[root@localhost mnt]# a=1
[root@localhost mnt]# echo $a
1
[root@localhost mnt]# echo $ab
[root@localhost mnt]# echo ${a}b
1b
[root@localhost mnt]# a=`date`
##`date`當下已被執行,所以a的值恆定
[root@localhost mnt]# echo $a
Wed Dec 14 01:28:12 EST 2016
[root@localhost mnt]# echo $a
Wed Dec 14 01:28:12 EST 2016
--2.export--
[root@localhost mnt]# vim 4.sh
-----------------------------------------------
#!/bin/bash
echo $a
:wq
-----------------------------------------------
[root@localhost mnt]# chmod +x 4.sh
[root@localhost mnt]# ./4.sh
[root@localhost mnt]# export a=1
[root@localhost mnt]# ./4.sh
1
[root@localhost mnt]# exit
logout
Connection to 172.25.50.100 closed.
[root@foundation50 Desktop]# ssh [email protected]
[email protected]'s password:
[root@localhost ~]# /mnt/4.sh
--3.環境變量配置文件--
~/.bash_profile ##用戶級別
/etc/profile ##系統級別
[root@localhost ~]# vim .bash_profile
-----------------------------------------------
13 export a=1
:wq
-----------------------------------------------
[root@localhost ~]# source .bash_profile
[root@localhost ~]# /mnt/4.sh
1
##用戶級別生效
[root@localhost ~]# su - student
[student@localhost ~]$ /mnt/4.sh
[student@localhost ~]$ logout
[root@localhost ~]# vim /etc/profile
-----------------------------------------------
77 export a=5
:wq
-----------------------------------------------
[root@localhost ~]# source /etc/profile
[root@localhost ~]# /mnt/4.sh
5
##這是因爲"/etc/profile"是後讀的,所以後讀的生效
[root@localhost ~]# logout
Connection to 172.25.50.100 closed.
[root@foundation50 Desktop]# ssh [email protected]
[email protected]'s password:
[root@localhost ~]# /mnt/4.sh
1
##重新登陸,用戶級別的生效。所以一般情況下,用戶級別優先於系統級別
[root@localhost ~]# su - student
[student@localhost ~]$ /mnt/4.sh
5
##系統級別生效
[student@localhost ~]$ logout
--4.PATH--
[root@localhost ~]# 4.sh
bash: 4.sh: command not found...
[root@localhost ~]# 1.sh
bash: 3.sh: command not found...
[root@localhost ~]# vim .bash_profile
-----------------------------------------------
14 export PATH=$PATH:/mnt
:wq
-----------------------------------------------
[root@localhost ~]# source .bash_profile
[root@localhost ~]# 4.sh
1
[root@localhost ~]# 1.sh
hello world
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/mnt
##包含"/mnt"
--5.故意寫錯,測試效果--
[root@localhost ~]# vim .bash_profile
-----------------------------------------------
14 export PATH=$PAITH:/mnt ##故意寫錯成"PAITH"
:wq
-----------------------------------------------
[root@localhost ~]# source .bash_profile
[root@localhost ~]# ls
bash: ls: command not found...
Similar command is: 'lz'
[root@localhost ~]# /bin/ls
anaconda-ks.cfg
[root@localhost ~]# echo $PATH
:/mnt ##只有"/mnt"
[root@localhost ~]# 4.sh
1
[root@localhost ~]# /bin/vim .bash_profile
-----------------------------------------------
/刪除
14 export PATH=$PAITH:/mnt
:wq
-----------------------------------------------
[root@localhost ~]# /bin/source .bash_profile
-bash: /bin/source: No such file or directory
[root@localhost ~]# /sbin/source .bash_profile
-bash: /sbin/source: No such file or directory
......(各種嘗試)
##找不到source命令
[root@localhost ~]# logout
Connection to 172.25.50.100 closed.
[root@foundation50 Desktop]# ssh [email protected]
[email protected]'s password:
[root@localhost ~]# which source
/usr/bin/which: no source in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
##因爲source命令是shell裏的內建命令,所以找不着
Linux課程第二十三天學習筆記
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.