对于一些企业,我们不用花费大把的资金去购进负载均衡设备,也可以进行负载均衡的实现。现在我们来说一下nginx负载均衡器,这种适合于中小型企业的设备,同样可以达到负载平衡的效果,现在我们就来介绍一下nginx负载均衡器的相关安装和设置问题。
一、拓扑环境:
用途 IP
主nginx负载均衡器 192.168.0.154
辅nginx负载均衡器 192.168.0.155
VIP地址 192.168.0.188
二、安装keepalived
- wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
- tar zxvf keepalived-1.1.15.tar.gz
- cd keepalived-1.1.15
- ./configure --prefix=/usr/local/keepalived
- make
- make install
- cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
- cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
- cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
- mkdir /etc/keepalived
- cd /etc/keepalived/
- vim keepalived.conf
- ! Configuration File for keepalived
- global_defs {
- notification_email {
- yuhongchun027@163.com
- }
- notification_email_from keepalived@chtopnet.com
- smtp_server 127.0.0.1
- smtp_connect_timeout 30
- router_id LVS_DEVEL
- }
- vrrp_instance VI_1 {
- state MASTER
- interface eth0
- virtual_router_id 51
- mcast_src_ip 192.168.0.154<==主nginx负载均衡器的IP地址
- priority 100
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass chtopnet
- }
- virtual_ipaddress {
- 192.168.0.188<==vip地址
- }
- }
- #service keepalived start
主nginx负载均衡器日志:
- [root@ltos ~]# tail /var/log/messages
- Oct 6 03:25:03 ltos avahi-daemon[2306]: Registering new address record for 192.168.0.188 on eth0.
- Oct 6 03:25:03 ltos avahi-daemon[2306]: Registering new address record for 192.168.0.154 on eth0.
- Oct 6 03:25:03 ltos avahi-daemon[2306]: Registering HINFO record with values 'I686'/'LINUX'.
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Withdrawing address record for fe80::20c:29ff:feb9:eeab on eth0.
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Withdrawing address record for 192.168.0.154 on eth0.
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Host name conflict, retrying with <ltos-31>
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Registering new address record for fe80::20c:29ff:feb9:eeab on eth0.
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Registering new address record for 192.168.0.188 on eth0.
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Registering new address record for 192.168.0.154 on eth0.
- Oct 6 03:25:23 ltos avahi-daemon[2306]: Registering HINFO record with values 'I686'/'LINUX'.