nginx的安装:
server1:
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0/src/core/
vim nginx.h
cd /root/nginx-1.14.0/auto/cc
vim gcc ##将图中光标所示注释掉
yum install pcre-devel
yum install openssl-devel
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
##此步骤需要gcc编译器,若没有需要下载
make
make install
cd /usr/local/nginx/
cd sbin/
ln -s /usr/local/nginx/sbin/nginx /sbin/
cd /usr/local/nginx/html ##此目录为nginx的默认发布目录
vim test.html ##nginx有自己的默认发布页面,所以需要自己创建一个新的页面
测试
网页测试
www.westos.org
www.westos.org
nginx -t ##检查语法
nginx ##开启服务
cd /usr/local/nginx/html/
lscpu
vim /etc/security/limits.conf
ngnin -s reload ##重载nginx
nginx -t
useradd -M -d /usr/local/nginx/ nginx ##创建一个nginx用户
id nginx ##查看用户是否创建成功
vim /nginx.conf ##编辑nginx主配置文件
nginx -s reload 编辑完成后重载
测试
curl www.westos.org
当weight =2时:
添加ip_hash;时
高可用
server1:
scp -r /usr/local/nginx/ server4:/usr/local/ ##将一中配置好的文件发送到四中
yum install -y luci ricci
chkconfig luci on ##设置开机自启动
/etc/init.d/luci start ##开启服务
chkconfig ricci on ###设置开机自启动
passwd ricci ##給ricci配置密码必须配置
/etc/init.d/ricci start
netstat -antlp | grep ricci ###查看ricci的端口号:11111
server4:
ln -s /usr/local/nginx/sbin/nginx /sbin/
useradd -M -d /usr/local/nginx/ nginx ##创建一个nginx用户
nginx ##开启服务
netstat -antlp | grep nginx ##可以查看nginx服务端口
yum install -y ricci
chkconfig ricci on
passwd ricci
/etc/init.d/ricci start
netstat -antlp | grep ricci #ricci的开启端口为11111
在浏览器访问:(需要先在物理机上做好解析)
页面编辑
Failover Domains:用来做节点隔离,业务切换
添加共享服务VIIP
添加nginx脚本:
由于ningx自己并没有启动脚本,所以需要自己制作
Vim /etc/init.d/nginx
内容如下:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
chmod a+x /etc/init.d/nginx ##给予权限
并在/etc/rc.d/rc.local中将其写入,实现开机自启
创建资源组:这里添加顺序应与服务启动顺序一致
测试:
通过clusta课题看到服务已经启动,此时停掉一个server中的服务,另一个会自动接管,
但是server1的优先级要高于server4,所以当server1坏掉重启后会将原本在server4中的服务再次接管