Fork me on GitHub
瞬间的惊奇真是种确幸,每种确幸都是支玄妙的俳句。吊桥抬起,退回到内心幽静的花园,邂逅的还是那种熟悉的冷冷清清又轰轰烈烈的美妙质感。这真令人欢喜。

Nginx+Keepalived部署


-----------ReProxy-------------------------Client-----------
192.168.56.200 nginx+keepalived 192.168.56.202 nginx
192.168.56.201 nginx+keepalived

1、编译安装Nginx
[root@localhost ~]# yum -y install pcre-devel zlib-devel
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# tar -zxvf nginx-1.12.0.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.12.0/
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost ~]# nginx -t
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep 80

2、创建nginx服务启动脚本
[root@localhost ~]# vim /etc/init.d/nginx
添加:
#!/bin/bash
#### welcome to nginx ####
# chkconfig: - 99 20
# description: this is nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

3、编译安装keepalived
[root@localhost keepalived-1.2.13]#./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
[root@localhost keepalived-1.2.13]# make && make install
[root@localhost ~]#chkconfig --add keepalived
[root@localhost ~]#chkconfig keepalived on
[root@localhost ~]#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@localhost ~]#vim /etc/keepalived/keepalived.conf
[root@localhost conf]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email { //通知电子邮件
}
vrrp_instance VI_1 { //VRRP热备
state MASTER state BACKUP //热备状态master为主,backup为辅
interface eth0 //承载VIP的物理接口
virtual_router_id 51 //虚拟路由编号,每组一个
priority 100 priority 55 //优先级,越大越优先
advert_int 1 //心跳频率,单位秒
authentication { //认证信息,每组内一致
auth_type PASS //认证类型
auth_pass 1111 //认证字符串
}
virtual_ipaddress { //漂移地址VIP。可以有多个
192.168.56.10
}
notify_master "/etc/init.d/nginx start" //成为MASTER之后执行的动作
notify_backup "/etc/init.d/nginx stop" //成为BACKUP之后执行的动作
notify_fault "/etc/init.d/nginx stop" //FAULT之后执行的动作
}
[root@localhost ~]#/etc/init.d/keepalived start
[root@localhost ~]#ip addr show
inet 192.168.56.201/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.10/32 scope global eth0
[root@localhost ~]#netstat -anput | grep 80

4、反向代理设置
vim /etc/nginx/conf.d/default.conf
----------------------------------------------
location / { //增加此段
proxy_pass http://192.168.56.202;
}
#location / { //将此段注释掉
# root /usr/share/nginx/html;
# index index.html index.htm;
# example
#ModSecurityEnabled on;
#ModSecurityConfig /etc/nginx/modsecurity.conf;
#}
----------------------------------------------
service nginx restart
service keepalived restart
5、日志查看
[root@localhost conf]# tailf /var/log/messages

posted @ 2018-10-01 10:04  干嘛那么贪睡  阅读(296)  评论(0编辑  收藏  举报