linux系统安装nginx及高可用

  • Post author:
  • Post category:linux


1、下载pcre    https://ftp.pcre.org/pub/pcre/

下载nginx   http://nginx.org/en/download.html

2、安装pcre

解压:tar -xvf pcre-8.44.tar.gz

验证:./configure

安装:make && make install

3、安装其他插件

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

4、安装nginx

解压:tar -xvf nginx-1.18.0.tar.gz

验证:./configure

安装:make && make install

5、启动

进入  /usr/local/nginx/sbin

启动:./nginx


常用命令:

启动:./nginx

停止:./nginx -s stop

重载:./nginx -s reload



keepalived 安装

:https://www.jianshu.com/p/a6b5ab36292a

1、yum install keepalived -y

安装后位置 /etc/keepalived

2、启动:systemctl start keepalived.service

(1)修改keepalived.conf文件

global_defs {
	notification_email {
	  acassen@firewall.loc
	  failover@firewall.loc
	  sysadmin@firewall.loc
	}
	notification_email_from Alexandre.Cassen@firewall.loc
	smtp_ server 127.0.0.1
	smtp_connect_timeout 30
	router_id LVS_DEVEL	# LVS_DEVEL这字段在/etc/hosts文件中看;通过它访问到主机,主备要保持一致
}

vrrp_script chk_http_ port {
	script "/usr/local/src/nginx_check.sh"
	interval 2   # (检测脚本执行的间隔)2s
	weight 2  #权重,如果这个脚本检测为真,服务器权重+2
}

vrrp_instance VI_1 {
	state BACKUP   # 备份服务器上将MASTER 改为BACKUP
	interface ens33 //网卡名称
	virtual_router_id 51 # 主、备机的virtual_router_id必须相同
	priority 100   #主、备机取不同的优先级,主机值较大,备份机值较小
	advert_int 1	#每隔1s发送一次心跳
	authentication {	# 校验方式, 类型是密码,密码1111
        auth type PASS
        auth pass 1111
    }
	virtual_ipaddress { # 虛拟ip
		192.168.17.50 // VRRP H虛拟ip地址
	}
}

(2)在路径/usr/local/src/ 下新建检测脚本     touch nginx_check.sh

#! /bin/bash
A=`ps -C nginx -no-header | wc - 1`
if [ $A -eq 0];then
	/usr/local/nginx/sbin/nginx
	sleep 2
	if [`ps -C nginx --no-header| wc -1` -eq 0 ];then
		killall keepalived
	fi
fi



版权声明:本文为weixin_44990255原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。