server2:172.25.51.2
server1:172.25.51.1
server4:172.25.51.4
具体配置详情:https://blog.csdn.net/Hannah_zh/article/details/80841684
server4安装nginx服务过程,参考:https://blog.csdn.net/Hannah_zh/article/details/80845382
server4设置启动脚本,并添加可执行权限:
[root@server4 ~]# cd /etc/init.d/
[root@server4 init.d]# chmod +x nginx
#!/bin/bash
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
#
# Source function library.
. /etc/rc.d/init.d/functions
nginx=${NGINX-/usr/local/nginx/sbin/nginx}
prog=nginx
pidfile=${PIDFILE-/usr/local/nginx/logs/nginx.pid}
lockfile=${LOCKFILE-/var/lock/subsys/nginx}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $nginx $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $nginx
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if [ $RETVAL -eq 7 ]; then
failure $"nginx shutdown"
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $nginx
RETVAL=$?
;;
restart)
stop
start
;;
reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status}"
RETVAL=2
esac
exit $RETVAL
[root@server1 ~]# cd /etc/init
[root@server1 init.d]# useradd nginx
[root@server1 init.d]# id nginx
uid=500(nginx) gid=500(nginx) groups=500(nginx)
[root@server1 ~]# vim /etc/security/limits.conf
nginx - nofile 65536
示图:server1上开启nginx服务
示图:vip浮动在server1上
示图:真机DNS
示图:server1上实现nginx负载均衡
[root@server1 ~]# echo c > /proc/sysrq-trigger