部署两台keepalived, master和backup, 两台realserver, 一台sorry_server. 操作系统为centos6.8
ip: master: 192.168.254.129
back: 192.168.254.131
real_server: 192.168.254.128
real_server: 192.168.254.130
sorry_server: 192.168.254.132
1.安装master的keepalived
1.1.下载keepalived安装包keepalived-1.2.15.tar.gz, 下载地址:http://www.keepalived.org/download.html
1.2 安装之前先装工具包:yum install curl gcc openssl-devel libnl3-devel net-snmp-devel
1.3 执行以下命令:
tar -xzvf keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
mkdir /usr/local/keepalived-1.2.15
./configure --prefix=/usr/local/keepalived-1.2.15
make
mak install
1.4 拷贝各文件至相应目录
mv /usr/local/keepalived-1.2.15/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
mv /usr/local/keepalived-1.2.15/etc/sysconfig/keepalived /etc/sysconfig/
mv /usr/local/keepalived-1.2.15/sbin/keepalived /usr/sbin/
1.5 创建目录: /etc/keepalived, 将/usr/local/keepalived-1.2.15/etc/keepalived/keepalived.conf放至此目录,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
# lvs_id LVS_MAIN
#}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 2
advert_int 1
authentication {
auth_type PASS
auth_pass kevin
}
virtual_ipaddress {
192.168.254.80
}
}
virtual_server 192.168.254.80 8080 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 50
protocol TCP
sorry_server 192.168.254.129 8080
real_server 192.168.254.128 8080 {
weight 2
HTTP_GET {
url {
path /heartcheck
status_code 200
}
connect_timeout 6
retry 3
delay_before_retry 3
}
}
real_server 192.168.254.130 8080 {
weight 1
HTTP_GET {
url {
path /heartcheck
status_code 200
}
connect_timeout 6
retry 3
delay_before_retry 3
}
}
}
1.6 启动keepalived: service keepalived start
2.安装backup的keepalived, 步骤同1. keepalived.conf配置文件中,修改以下内容:
state BACKUP
priority 1
3.启动backup的keepalived: service keepalived start
4. 安装real_server: 在/etc/init.d目录下增加lvsrs文件,内容如下:
#!/bin/bash
#description : Start Real Server
VIP=192.168.254.80
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo " Start LVS of Real Server "
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Director server"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
5. 启动各real_server, 增加VIP: service lvsrs start
6. 注意sorry_server所在机器,配置同real_server, 也需要启动: service lvsrs start
备注:各配置文件在附件中.
相关推荐
为了提高安全性,可以设置防火墙规则限制VRRP协议的通信,同时监控CPU和内存使用情况,优化keepalived配置,减少资源占用。 总之,keepalived 1.2.18版本在Linux环境中的应用,为构建高可用、负载均衡的网络服务...
在CentOS系统中,首先需要更新系统软件库,然后使用`yum`或`dnf`命令安装LVS和Keepalived: ``` sudo yum update -y sudo yum install -y ipvsadm keepalived ``` 4. 配置LVS: LVS的配置主要在`/etc/sysconfig/...
在Debian或Ubuntu系统中,可以使用`apt-get install keepalived`进行安装。然后根据业务需求定制配置文件,最后启动服务`systemctl start keepalived`。 6. 监控与维护 Keepalived提供了丰富的日志输出,便于故障...
使用`apt`安装Keepalived:`sudo apt-get install keepalived` **2. Master主机配置** 编辑`/etc/keepalived/keepalived.conf`,配置VIP(虚拟IP)和监控: ```conf vrrp_script check_apache { script "/usr/...
这可能需要你提前准备相应的库文件或使用其他服务器上的包管理器(如yum或apt-get)来获取。 5. **编译与安装**:进入Keepalived源码目录,执行`./configure`来配置安装路径,然后运行`make`进行编译,最后使用`...
1. 安装Keepalived:在两台服务器上执行相应的安装命令,例如在Debian/Ubuntu系统中使用`apt-get install keepalived`,在CentOS/RHEL系统中使用`yum install keepalived`。 2. 配置Keepalived:编辑 `/etc/...
在Debian/Ubuntu系统中,使用`apt-get install keepalived`;在CentOS/RHEL系统中,使用`yum install keepalived`或`dnf install keepalived`。 4. **配置Keepalived**:安装完成后,需要编辑配置文件`/etc/...
1. 安装 Keepalived:通常使用 `yum install keepalived` 或 `apt-get install keepalived` 命令进行安装。 2. 配置 Keepalived:编辑 `/etc/keepalived/keepalived.conf` 文件,定义虚拟 IP(VIP,如 172.31.98.201...
sudo apt-get install keepalived ``` #### 编写 Keepalived 配置文件 最后一步是编写 Keepalived 的配置文件。 1. **Server1 (Master) 配置文件**: ```keepalived vrrp_script chk_http_port { script "/opt...
可以通过包管理器(如yum或apt-get)进行安装,然后下载并编译keepalived源代码,执行以下步骤: 1. 解压下载的keepalived-1.4.2压缩包。 2. 进入解压后的目录:`cd keepalived-1.4.2` 3. 配置编译环境:`./...
在系统集群中,Keepalived与Nginx、HAProxy等配合使用,可以确保当主服务器出现故障时,服务能够自动切换到备用服务器,从而保证业务的连续性。 **一、Keepalived的功能** 1. **虚拟IP漂移**:Keepalived通过VRRP...
在Linux系统中,我们通常使用包管理器来安装Nginx,如在Ubuntu上使用`apt-get install nginx`,在CentOS上使用`yum install nginx`。安装完成后,可以通过`nginx -t`检查配置文件的正确性,`systemctl start nginx`...
Keepalived 可以从源代码编译安装,也可以使用 yum 或 apt-get 等包管理器安装。 2. 安装 Nginx Nginx 可以从源代码编译安装,也可以使用 yum 或 apt-get 等包管理器安装。 3. 安装 Tomcat Tomcat 可以从源代码...
1. **安装LVS和Keepalived**:首先在所有涉及的服务器上安装LVS和Keepalived软件包,如`apt-get install lvs keepalived`(对于Debian/Ubuntu)或`yum install lvs keepalived`(对于CentOS/RHEL)。 2. **配置LVS**...
在构建大型、高可用性的FTP(File Transfer Protocol)服务时,使用LVS(Linux Virtual Server)、Keepalived和VSFTPd的组合是一个常见的解决方案。LVS提供负载均衡,Keepalived确保服务高可用,而VSFTPd是常用的FTP...
4. **安装Keepalived**:在CentOS上使用`sudo yum install keepalived`,在Ubuntu上使用`sudo apt-get install keepalived`。 【配置Keepalived】 1. **配置文件**:Keepalived的主要配置文件是`/etc/keepalived/...
在Linux平台上,可以使用yum或apt-get等包管理工具来安装Redis。 在配置Redis时,需要注意以下几点: * bind 127.0.0.1:需要注释掉以便slave服务器可以同步数据。 * protected-mode yes:需要开启保护模式,以...