1. 程式人生 > 實用技巧 >linux系統部署apache服務(測試不同inux主機訪問網站)

linux系統部署apache服務(測試不同inux主機訪問網站)

以下實驗中伺服器端為PC1,IP地址為192.168.10.10 ;客戶機端分別為PC2和PC3,IP地址分別為192.168.10.20和192.168.10.30

1、在PC1伺服器端安裝apache服務

[root@PC1 ~]# ifconfig | head -n 3  ## 檢視IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::20c:29ff:fe66:37f7  prefixlen 
64 scopeid 0x20<link> [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 5.9 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!

2、在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 21:35:02 CST; 17s ago  ## 已啟用
 Main PID: 3972 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─3972 /usr/sbin/httpd -DFOREGROUND
           ├─3973 /usr/sbin/httpd -DFOREGROUND
           ├─3974 /usr/sbin/httpd -DFOREGROUND
           ├─3975 /usr/sbin/httpd -DFOREGROUND
           ├─3976 /usr/sbin/httpd -DFOREGROUND
           └─3978 /usr/sbin/httpd -DFOREGROUND

Dec 16 21:35:02 PC1 httpd[3972]: AH00557: httpd: apr_sockaddr_info_get() fa...C1
Dec 16 21:35:02 PC1 httpd[3972]: AH00558: httpd: Could not reliably determi...ge
Dec 16 21:35:02 PC1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

3、在PC2和PC3客戶機端測試與PC1的網路連通性

[root@PC2 Desktop]# ifconfig | head -n 3
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.20  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::20c:29ff:fe25:bb3e  prefixlen 64  scopeid 0x20<link>
[root@PC2 Desktop]# ping -c 3 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.326 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.245 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.236 ms

--- 192.168.10.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.236/0.269/0.326/0.040 ms
[root@PC3 Desktop]# ifconfig | head -n 3
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.30  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::20c:29ff:fe7d:e711  prefixlen 64  scopeid 0x20<link>
[root@PC3 Desktop]# ping -c 3 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.316 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.231 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.177 ms

--- 192.168.10.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.177/0.241/0.316/0.058 ms

4、在PC2和PC3客戶機端測試PC1的apache服務(均無法連線)

5、在PC1伺服器端清空防火牆策略,並使其生效

[root@PC1 ~]# iptables -F
[root@PC1 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

6、在PC2和PC3客戶機端測試PC1的apache服務(都可以訪問)

7、在PC1伺服器端修改apache服務網站的首頁資料

[root@PC1 ~]# cd /var/www/html/
[root@PC1 html]# ls
[root@PC1 html]# echo "this is a test ! welcome to 192.168.10.10" > index.html
[root@PC1 html]# ls
index.html
[root@PC1 html]# cat index.html 
this is a test ! welcome to 192.168.10.10

8、 在PC2和PC3客戶機端測試PC1主機的配置的首頁資料效果(PC1的首頁資料配置生效)

以上實驗實現了伺服器端PC1配置Apache服務,PC2和PC3客戶機端訪問網站的效果(web服務)。