首页 > 代码库 > Nginx(十一)-- keepalived简介
Nginx(十一)-- keepalived简介
1. 什么是keepalived
基于VRRP(虚拟路由器冗余协议)来实现对web服务的高可用方案。
keepalived下载地址:http://download.csdn.net/detail/u010821757/9892484
2.安装keepalived服务器
1.将keepalived-1.3.4.zip解压到/usr/java目录
unzip keepalived-1.3.4.zip
2.进入到keepalived
cd keepalived
3.编译安装
./conf 按 Tab键提示不出来,不能自动补全
4.发现没有权限,接下来就要赋权
chmod +x configure
5.在/usr/java中创建一个文件夹 keepalived
mkdir keepalived
6.进入 keepalived-1.3.4文件夹中,然后编译安装
./configure --prefix=/usr/java/keepalived --sysconf=/etc
说明:当keepalived启动的时候,会默认读取 etc下的keepalived.conf,所以安装的时候就指向/etc
7.执行6的时候,可能会出现缺少依赖openssl,解决方法,安装openssl
yum install openssl-devel
8.安装
make && make install
出现上图,表示安装成功!
9.设置成系统服务
1) 进入到源码包,即 /usr/java/keepalived-1.3.4
2) 建立软连接(相当于快捷方式)
2.1) 把启动脚本添加到系统/sbin中,ln -s /usr/java/keepalived/sbin/keepalived /sbin
2.2) 复制源码路径中的keepalived复制到/etc/init.d中:cp /usr/java/keepalived-1.3.4/keepalived/etc/init.d/keepalived /etc/init.d/
3) 添加到系统服务中
chkconfig --add keepalived
4) 设置服务启动
chkconfig keepalived on
5) 启动服务
service keepalived start,出现:
说明没有权限,赋权:chmod +x /etc/init.d/keepalived
重新启动:service keepalived start
出现上图,即启动成功,我们可以查看进程:ps -ef|grep keepalived
3.keepalived配置文件
- global_defs 全局配置
- vrrp_instance VI_1
- virtual_server lvs配置
1) global_defs 全局配置
global_defs { notification_email { # 设置报警的邮件,如果keepalived出现问题,会发邮件到下面的邮箱 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 # 唯一的一个名字,运行keepalived的唯一标识 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 }
2) vrrp_instance VI_1
vrrp_instance VI_1 { state MASTER #当前keepalived的状态 interface eth0 # 高可用的检测端口 和 网卡名称 virtual_router_id 51 # 虚拟路由的标识 priority 100 # 权重,节点优先级 advert_int 1 # 主备服务器检查的时间,单位秒 authentication { # master和backup的通讯验证, auth_type PASS auth_pass 1111 } virtual_ipaddress { # 虚拟IP地址 192.168.200.16 192.168.200.17 192.168.200.18 } }
3) virtual_server lvs配置
virtual_server 192.168.200.100 443 { # 虚拟IP对应的真实IP delay_loop 6 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.201.100 443 { weight 1 SSL_GET { url { path / digest ff20ad2481f97b1754ef3e12ecd3a9cc } url { path /mrtg/ digest 9b3a0c85a887a256d6939da88aabd8cd } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
Nginx(十一)-- keepalived简介