apache服務即為網頁服務,apache服務的軟件包叫httpd。
以下實驗在PC1主機中完成
1、測試配置前網頁服務
2、在PC1主機中安裝apache軟件包
[root@PC1 ~]# yum install httpd -y Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast rhel7 | 4.1 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed --> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64 --> Running transaction check ---> Package apr.x86_64 0:1.4.8-3.el7 will be installed ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed ---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.6-17.el7 rhel7 1.2 M Installing for dependencies: apr x86_64 1.4.8-3.el7 rhel7 103 k apr-util x86_64 1.5.2-6.el7 rhel7 92 k httpd-tools x86_64 2.4.6-17.el7 rhel7 77 k mailcap noarch 2.1.41-2.el7 rhel7 31 k Transaction Summary ================================================================================ Install 1 Package (+4 Dependent packages) Total download size: 1.5 M Installed size: 4.3 M Downloading packages: -------------------------------------------------------------------------------- Total 8.2 MB/s | 1.5 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : apr-1.4.8-3.el7.x86_64 1/5 Installing : apr-util-1.5.2-6.el7.x86_64 2/5 Installing : httpd-tools-2.4.6-17.el7.x86_64 3/5 Installing : mailcap-2.1.41-2.el7.noarch 4/5 Installing : httpd-2.4.6-17.el7.x86_64 5/5 rhel7/productid | 1.6 kB 00:00 Verifying : mailcap-2.1.41-2.el7.noarch 1/5 Verifying : httpd-tools-2.4.6-17.el7.x86_64 2/5 Verifying : apr-1.4.8-3.el7.x86_64 3/5 Verifying : apr-util-1.5.2-6.el7.x86_64 4/5 Verifying : httpd-2.4.6-17.el7.x86_64 5/5 Installed: httpd.x86_64 0:2.4.6-17.el7 Dependency Installed: apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-17.el7 mailcap.noarch 0:2.1.41-2.el7 Complete!
3、在PC1主機中啟動Apache服務,設定為開機啟動
[root@PC1 ~]# systemctl start httpd [root@PC1 ~]# systemctl enable httpd ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service' [root@PC1 ~]# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: active (running) since Wed 2020-12-16 19:40:28 CST; 20s ago Main PID: 31941 (httpd) …………
4、在PC1主機中查看web服務
5、在PC1主機中查看主配置文件,查看web數據目錄(web數據目錄為/var/www/html)
………… 115 # DocumentRoot: The directory out of which you will serve your 116 # documents. By default, all requests are taken from this directory, but 117 # symbolic links and aliases may be used to point to other locations. 118 # 119 DocumentRoot "/var/www/html"
120
121 # 122 # Relax access to content within /var/www. 123 # 124 <Directory "/var/www">
125 AllowOverride None 126 # Allow open access: 127 Require all granted …………
6、在PC1主機中編輯web數據首頁目錄
[root@PC1 ~]# cd /var/www/html/ [root@PC1 html]# ls [root@PC1 html]# echo "aaabbbccc" > index.html [root@PC1 html]# ls index.html [root@PC1 html]# cat index.html aaabbbccc
7、在PC1主機中測試首頁效果
8、在PC1主機中指定web首頁路徑,並寫入首頁內容
[root@PC1 html]# mkdir /home/wwwroot
[root@PC1 html]# echo "xxxyyyzzz" > /home/wwwroot/index.html [root@PC1 html]# vim /etc/httpd/conf/httpd.conf 117 # symbolic links and aliases may be used to point to other locations. 118 # 119 DocumentRoot "/home/wwwroot"
120
121 # 122 # Relax access to content within /var/www. 123 # 124 <Directory "/home/wwwroot">
125 AllowOverride None 126 # Allow open access:
9、在PC1主機中重啟web服務
[root@PC1 html]# systemctl restart httpd [root@PC1 html]# systemctl status httpd | head -n 5 httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: active (running) since Wed 2020-12-16 19:57:00 CST; 15s ago Process: 32238 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Main PID: 32242 (httpd)
10、在PC1主機中測試web服務
11、在PC1中檢查SELinux服務
[root@PC1 html]# getenforce ## 說明為啟用狀態
Enforcing
12、在PC1主機中關閉SELinux服務
[root@PC1 html]# setenforce 0 [root@PC1 html]# getenforce Permissive
13、在PC1主機中測試web服務(此處說明SELinux服務導致web無法啟用)
14、在PC1主機中啟用SELinux
[root@PC1 html]# getenforce Permissive [root@PC1 html]# setenforce 1 [root@PC1 html]# getenforce Enforcing
15、在PC1主機中查看web服務默認web數據目錄的selinux上下文值和新設定的web數據目錄的selinux上下文值
[root@PC1 html]# ll -ldZ /var/www/html/ drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/ [root@PC1 html]# ll -ldZ /home/wwwroot/ drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/wwwroot/
16、在PC1主機中修改新設定的web目錄的selinux上下文值
[root@PC1 html]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot [root@PC1 html]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/* [root@PC1 html]# restorecon -Rv /home/wwwroot/ restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 [root@PC1 html]# ll -ldZ /home/wwwroot/ drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 /home/wwwroot/ ## 修改成功
17、在PC1主機中測試web服務
以上實驗實現了在linux部署web服務,同時進行了web數據目錄的修改,並定義了web首頁的內容。