Haproxy搭建Web集群 (2)

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/    #路径优化
[root@localhost nginx-1.12.2]# ls -l /usr/local/sbin/nginx 
lrwxrwxrwx 1 root root 27 5 月 16 16:50 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx

2.启动、 停止 Nginx

killall -1 nginx             ####安全重启
killall -3 nginx            ###停止服务

如果出现: -bash: killall: command not found

yum -y install psmisc

[root@localhost ~]# nginx ####启动

[root@localhost ~]# netstat -anpt | grep nginx

tcp    0          0 0.0.0.0:80              0.0.0.0:*              LISTEN            7180/nginx: master

3.添加 Nginx 系统服务

[root@localhost ~]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx ####描述
After=network.target ####描述服务类别
[Service]
Type=forking ####后台运行形式
PIDFile=http://www.likecs.com/usr/local/nginx/logs/nginx.pid ####PID 文件位置
ExecStart=http://www.likecs.com/usr/local/nginx/sbin/nginx ####启动服务
ExecReload=http://www.likecs.com/usr/bin/kill -s HUP $MAINPID ####根据 PID 重载配置
ExecStop=http://www.likecs.com/usr/bin/kill -s QUIT $MAINPID ####根据 PID 终止进程
PrivateTmp=true
[Install]
WantedBy=multi-user.target

[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service
[root@localhost ~]# systemctl enable nginx.service

[root@localhost ~]# killall -3 nginx ###停止服务
[root@localhost ~]# systemctl start nginx.service

4.安装httpd 挂载测试页

[root@localhost ~]# showmount -e 192.168.100.44 ####如果还没发布,请到存储服务器发布下,exportfs -rv
Export list for 192.168.100.44:
/opt/51xit (everyone)
/opt/52xit (everyone)

[root@localhost ~]# mount 192.168.100.44:/opt/51xit /usr/local/nginx/html/
[root@localhost ~]# vi /etc/fstab
192.168.100.44:/opt/51xit/ /usr/local/nginx/html/ nfs rw,tcp,intr 0 1 ###开机自动挂载,注意格式对齐

[root@localhost nginx-1.12.2]# systemctl restart nginx

4.4  编译安装Nginx服务器2  192.168.100.43

###nginx安装流程同1一样###

1.安装httpd 挂载测试页

[root@localhost ~]# showmount -e 192.168.100.44 ####如果还没发布,请到存储服务器发布下,exportfs -rv
Export list for 192.168.100.44:
/opt/51xit (everyone)
/opt/52xit (everyone)

[root@localhost ~]# mount 192.168.100.44:/opt/52xit/ /usr/local/nginx/html/
[root@localhost ~]# vi /etc/fstab
192.168.100.44:/opt/52xit/ /usr/local/nginx/html/ nfs rw,tcp,intr 0 1 ###开机自动挂载,注意格式对齐

[root@localhost ~]# systemctl restart nginx

4.5 调试存储服务器  192.168.100.44

1.安装nfs-utils rpcbind

yum -y install nfs-utils   ### nfs必须安装的,不然无法识别nfs格式,

yum -y install rpcbind

2.创建共享测试目录,和网页文件

mkdir /opt/51xit /opt/52xit
[root@localhost ~]# echo "this is " >/opt/51xit/index.html   ###写数据定义服务器1
[root@localhost ~]# echo "this is " >/opt/52xit/index.html   ###写数据定义服务器2

 

3.添加共享目录

vi /etc/exports     ####将共享目录添加在配置内发布
/opt/51xit 192.168.100.0/24 (rw,sync) 
/opt/52xit 192.168.100.0/24 (rw,sync)

systemctl restart nfs  ###重启服务
systemctl restart rpcbind
systemctl enable nfs   ###设置开机自启
systemctl enable rpcbind

#####测试网站#####
192.168.100.41 切换 会发现不同的网站页面 说明已经实现了负载均衡

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wppgdy.html