您的位置:首页 > 运维架构 > Nginx

nginx+keeplived

2014-03-16 10:50 330 查看
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名Keepalivedt做高可用,其高可用,都是站在服务器脚本去说的高可用,而不是服务的角度,也就是说,如果服务器DOWN机或者网络出现故障,高可用是可以实现自动切换的。如果运行的服务,比如Nginx挂掉,这些高可用软件是意识不到的,需要自己写脚本去实现服务的切换实验拓扑主nginx负载均衡器 192.168.0.102
辅nginx负载均衡器 192.168.0.100
VIP地址 192.168.0.103
实验环境centos-5.5
实验软件gcc gcc-c++pcre-8.10.tar.gznginx-1.1.1.tar.gzkeepalived-1.2.1.tar.gz
软件安装主nginx负载均衡器 192.168.0.102tar zxvf pcre-8.10.tar.gzcd pcre-8.10./configuremakemake install
tar zxvf nginx-1.1.1.tar.gzcd nginx-1.1.1./configure --prefix=/usr/local/nginx --with-http_stub_status_modulemake
make installcd /usr/local/nginx/sbin/./nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfu如果看到这行提示,证明nginx配置没有错误cd /usr/local/nginx/sbin/./nginx 启动nginx
tar zxvf keepalived-1.2.1.tar.gzcd keepalived-1.2.1./configure --prefix=/usr/local/keeplivedmakemake installcp -p /usr/local/keeplived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/cp -p /usr/local/keeplived/etc/sysconfig/keepalived /etc/sysconfig/cp -p /usr/local/keeplived/sbin/keepalived /bin/chkconfig --add keepalivedchmod 755 /etc/init.d/keepalivedchkconfig keepalived onservice keepalived startStarting keepalived: [ OK ]netstat -tuplna | grep nginxtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11343/nginx
验证输入 http://服务器ip

如果出现这个证明nginx,安装完成
辅nginx负载均衡器 192.168.0.100tar zxvf pcre-8.10.tar.gzcd pcre-8.10./configuremakemake install
tar zxvf nginx-1.1.1.tar.gzcd nginx-1.1.1./configure --prefix=/usr/local/nginx --with-http_stub_status_modulemake
make installcd /usr/local/nginx/sbin/./nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfu如果看到这行提示,证明nginx配置没有错误cd /usr/local/nginx/sbin/./nginx 启动nginx
tar zxvf keepalived-1.2.1.tar.gzcd keepalived-1.2.1./configure --prefix=/usr/local/keeplivedmakemake installcp -p /usr/local/keeplived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/cp -p /usr/local/keeplived/etc/sysconfig/keepalived /etc/sysconfig/cp -p /usr/local/keeplived/sbin/keepalived /bin/chkconfig --add keepalivedchmod 755 /etc/init.d/keepalivedchkconfig keepalived onservice keepalived startStarting keepalived: [ OK ]netstat -tuplna | grep nginxtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11343/nginx
验证输入 http://服务器ip

如果出现这个证明nginx,安装完成
配置主keeplive负载均衡器 192.168.0.102vim /etc/keepalived/keepalived.conf! Configuration File for keepalived
global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL }
vrrp_instance VI_1 { state MASTER 主机为MASTER,备用机为BACKUP interface eth0 HA监测网络接口 virtual_router_id 51 主、备机的virtual_router_id必须相同 priority 100 主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高 advert_int 1 VRRP Multicast广播周期秒数 authentication { auth_type PASS VRRP认证方式 auth_pass 1111 密码 } virtual_ipaddress { 192.168.200.16 VRRP HA虚拟地址
touch /root/nginx_pid.sh#!/bin/bash
if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]
then
/usr/local/nginx/sbin/nginx
sleep 5
if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]
then
killall keepalived
fi
fichmod +x nginx_pid.shservice keepalived restart Stopping keepalived: [ OK ]Starting keepalived: [ OK ]
备keeplive负载均衡器 192.168.0.100vim /etc/keepalived/keepalived.conf! Configuration File for keepalived
global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL }
vrrp_instance VI_1 { state BACKUP 主机为MASTER,备用机为BACKUP interface eth0 HA监测网络接口 virtual_router_id 51 主、备机的virtual_router_id必须相同 priority 90 主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高 advert_int 1 VRRP Multicast广播周期秒数 authentication { auth_type PASS VRRP认证方式 auth_pass 1111 密码 } virtual_ipaddress { 192.168.200.16 VRRP HA虚拟地址service keepalived restart Stopping keepalived: [ OK ]Starting keepalived: [ OK ]到此为止nginx+keep搭建完成
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx+keeplived