Rhel6-keepalived+lvs配置文档
系统环境: rhel6 x86_64 iptables and selinux disabled
主机: 192.168.122.119 server19.example.com
192.168.122.25 server25.example.com
192.168.122.163 server63.example.com
192.168.122.193 server93.example.com
所需的包:keepalived-1.2.7.tar.gz
Realserver1
192.168.122.163:apache
Realserver2
192.168.122.193:apache
Load
Balance 192.168.122.119:keepalived
Load
Balance 192.168.122.25:keepalived
Virtual
IP 192.168.122.178
以下步骤在server19和server25上实施:
[root@server19
~]# yum install kernel-devel make gcc -y
[root@server19
~]# yum install openssl-devel popt-devel -y
[root@server19
~]# yum install libnl-devel -y
以下步骤在server19或server25上实施:
[root@server19
kernel]# tar zxf keepalived-1.2.7.tar.gz
[root@server19
kernel]# cd keepalived-1.2.7
[root@server19
keepalived-1.2.7]# ./configure –prefix=/usr/local/keepalived
[root@server19
keepalived-1.2.7]# make && make install
[root@server19
keepalived-1.2.7]# scp -r /usr/local/keepalived/
root@192.168.122.25:/usr/local/
以下步骤在server19和server25上实施:
[root@server19
keepalived-1.2.7]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/
[root@server19
keepalived-1.2.7]# ln -s
/usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@server19
keepalived-1.2.7]# ln -s
/usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@server19
keepalived-1.2.7]# ln -s /usr/local/keepalived/sbin/keepalived
/sbin/
注:系统镜像的负载均衡套件中也集成了keepalived,也可以直接使用yum
install keepalived -y进行安装。但需先配置yum源:
[LoadBalancer]
name=Instructor
Server Repository
baseurl=ftp://192.168.122.1/pub/yum/LoadBalancer
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled=1
以下步骤在server19实施:
[root@server19
~]# vim /etc/keepalived/keepalived.conf
global_defs
{
notification_email {
root@localhost 错误发送至此邮箱
}
notification_email_from keepalived@server19.example.com
发信人
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance
VI_1 {
state MASTER 角色:(1)MASTER
(2)BACKUP
interface eth0
virtual_router_id 51 (主备的配置需要一致)
priority 100 优先级(数字越大,优先级越高)
advert_int 1
authentication {
auth_type PASS 认证类型
auth_pass 1111 认证密码
}
virtual_ipaddress {
192.168.122.178 虚拟IP,可设置多个
}
}
virtual_server
192.168.122.178 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#
nat_mask 255.255.255.0
#
persistence_timeout 50
protocol TCP
real_server 192.168.122.163 80 {
weight 1
TCP_CHECK {
(注:TCP_CHECK和大括号之间要有空格)
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.122.193 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
以下步骤在server25实施:
[root@server25
~]# vim /etc/keepalived/keepalived.conf
global_defs
{
notification_email {
root@localhost 错误发送至此邮箱
}
notification_email_from keepalived@server25.example.com
发信人
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance
VI_1 {
state BACKUP 角色:(1)MASTER
(2)BACKUP
interface eth0
virtual_router_id 51 (主备的配置需要一致)
priority 50 优先级(数字越大,优先级越高)
advert_int 1
authentication {
auth_type PASS 认证类型
auth_pass 1111 认证密码
}
virtual_ipaddress {
192.168.122.178 虚拟IP,可设置多个
}
}
virtual_server
192.168.122.178 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#
nat_mask 255.255.255.0
#
persistence_timeout 50
protocol TCP
real_server 192.168.122.163 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.122.193 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
以下步骤在server63上实施:
[root@server63
~]# yum install arptables_jf httpd -y
[root@server63
~]# arptables -A IN -d 192.168.122.178 -j DROP
[root@server63
~]# arptables -A OUT -s 192.168.122.178 -j mangle --mangle-ip-s
192.168.122.163
[root@server63
~]# /etc/init.d/arptables_jf save
[root@server63
~]# ifconfig eth0:0 192.168.122.178 netmask 255.255.255.255 up
或
[root@server63
~]# ip addr add 192.168.122.178 dev eth0
注:可用ip
addr show查看
[root@server63
~]# echo `hostname` > /var/www/html/index.html
[root@server63
~]# /etc/init.d/httpd start
以下步骤在server93上实施:
[root@server93
~]# yum install arptables_jf httpd -y
[root@server93
~]# arptables -A IN -d 192.168.122.178 -j DROP
[root@server93
~]# arptables -A OUT -s 192.168.122.178 -j mangle --mangle-ip-s
192.168.122.193
[root@server93
~]# /etc/init.d/arptables_jf save
[root@server93
~]# ifconfig eth0:0 192.168.122.178 netmask 255.255.255.255 up
或
[root@server93
~]# ip addr add 192.168.122.178 dev eth0
注:可用ip
addr show查看
[root@server93
~]# echo `hostname` > /var/www/html/index.html
[root@server93
~]# /etc/init.d/httpd start
以下步骤在server19和server25上实施:
[root@server19
~]# /etc/init.d/keepalived start
测试:
执行ip
addr show可查看虚拟IP,执行ipvsadm
-l查看规则是否加载,访问192.168.122.178反复刷新网页,每次出现的页面都不同说明配置成功.
当主备挂掉后可由另一台接管,当两台都正常时由Master充当调度器.
#配置多个服务(apache+ftp)
以下步骤在server19实施:
[root@server19
~]# vim /etc/keepalived/keepalived.conf
global_defs
{
notification_email {
root@localhost
}
notification_email_from keepalived@server19.example.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 (主备的配置需要一致)
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.122.178 虚拟IP,可设置多个
}
}
virtual_server
192.168.122.178 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#
nat_mask 255.255.255.0
#
persistence_timeout 50
protocol TCP
real_server 192.168.122.163 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.122.193 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server
192.168.122.178 21 {
delay_loop 6
lb_algo rr
lb_kind DR
#
nat_mask 255.255.255.0
persistence_timeout 50 持续连接时间为50s
protocol TCP
real_server 192.168.122.163 21 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.122.193 21 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
以下步骤在server25实施:
[root@server25
~]# vim /etc/keepalived/keepalived.conf
global_defs
{
notification_email {
root@localhost
}
notification_email_from keepalived@server25.example.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance
VI_1 {
state BACKUP
interface eth0
virtual_router_id 51 (主备的配置需要一致)
priority
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.122.178 虚拟IP,可设置多个
}
}
virtual_server
192.168.122.178 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#
nat_mask 255.255.255.0
#
persistence_timeout 50
protocol TCP
real_server 192.168.122.163 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.122.193 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server
192.168.122.178 21
{
delay_loop 6
lb_algo rr
lb_kind DR
#
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.122.163 21 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.122.193 21 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
以下步骤在server63上实施:
[root@server63
~]# yum install arptables_jf httpd vsftpd -y
[root@server63
~]# arptables -A IN -d 192.168.122.178 -j DROP
[root@server63
~]# arptables -A OUT -s 192.168.122.178 -j mangle --mangle-ip-s
192.168.122.163
[root@server63
~]# /etc/init.d/arptables_jf save
[root@server63
~]# ifconfig eth0:0 192.168.122.178 netmask 255.255.255.255 up
或
[root@server63
~]# ip addr add 192.168.122.178 dev eth0
注:可用ip
addr show查看
[root@server63
~]# echo `hostname` > /var/www/html/index.html
[root@server63
~]# /etc/init.d/httpd start
[root@server63
~]# touch /var/ftp/server63
[root@server63
~]# /etc/init.d/vsftpd start
以下步骤在server93上实施:
[root@server93
~]# yum install arptables_jf httpd vsftpd -y
[root@server93
~]# arptables -A IN -d 192.168.122.178 -j DROP
[root@server93
~]# arptables -A OUT -s 192.168.122.178 -j mangle --mangle-ip-s
192.168.122.193
[root@server93
~]# /etc/init.d/arptables_jf save
[root@server93
~]# ifconfig eth0:0 192.168.122.178 netmask 255.255.255.255 up
或
[root@server93
~]# ip addr add 192.168.122.178 dev eth0
注:可用ip
addr show查看
[root@server93
~]# echo `hostname` > /var/www/html/index.html
[root@server93
~]# /etc/init.d/httpd start
[root@server93
~]# touch /var/ftp/server93
[root@server93
~]# /etc/init.d/vsftpd start
以下步骤在server19和server25上实施:
[root@server19
~]# /etc/init.d/keepalived start
Rhel6-keepalived+lvs配置文档的更多相关文章
- Rhel6-heartbeat+lvs配置文档
系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.119 server19.example.com 192.168.12 ...
- 最详细的keepalived+lvs-dr配置文档
四台台机器: 分发器主:192.168.0.154 分发器备:192.168.0.171 rs_1:192.168.0.131 rs_2:192.168.0.132 keepalived安装: yum ...
- MYSQL服务器my.cnf配置文档详解
MYSQL服务器my.cnf配置文档详解 硬件:内存16G [client] port = 3306 socket = /data/3306/mysql.sock [mysql] no-auto-re ...
- 转!!Java代码规范、格式化和checkstyle检查配置文档
为便于规范各位开发人员代码.提高代码质量,研发中心需要启动代码评审机制.为了加快代码评审的速度,减少不必要的时间,可以加入一些代码评审的静态检查工具,另外需要为研发中心配置统一的编码模板和代码格式化模 ...
- Hibernate配置文档详解
Hibernate配置文档有框架总部署文档hibernate.cfg.xml 和映射类的配置文档 ***.hbm.xml hibernate.cfg.xml(文件位置直接放在src源文件夹即可) (在 ...
- Java代码规范、格式化和checkstyle检查配置文档
http://www.blogjava.net/amigoxie/archive/2014/05/31/414287.html 文件下载: http://files.cnblogs.com/files ...
- Spring Hibernate4 整合配置文档
1 applicationContext.xml配置文档 <?xml version="1.0" encoding="UTF-8"?><bea ...
- Kerberos主从配置文档
Kerberos主从配置文档 1. Kerberos主从同步机制 在Master上通过以下命令同步数据: kdb5_util dump /var/kerberos/krb5kdc/slave_db ...
- python常用模块-配置文档模块(configparser)
python常用模块-配置文档模块(configparser) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. ConfigParser模块用于生成和修改常见配置文档,当前模块的名称 ...
随机推荐
- Android Contacts (android通讯录读取)-content provider
Content Provider 在数据处理中,Android通常使用Content Provider的方式.Content Provider使用Uri实例作为句柄的数据封装的,很方便地访问地进行数据 ...
- Android 自定义Toast
自定义Toast 其实就是自定义布局文件 感觉利用Dialog或者PopupWindow做也差不多 上图上代码 public class MainActivity extends Activity { ...
- Redhat Linux 性能 - 内置的 sar
缺省 / 默认 Redhat Linux 会自动使用 sar 采集系统性能信息,并记录到 /var/log/sa 每 10分钟采集一次, 记录 CPU / Memory / Disk / Networ ...
- 根据用户输入的二代身份证号码自动为其计算生成出生日期的javascript方法
if(idTypeIsChecked.checked == true){//如果选中的是二代身份证 var birthDateValue = document.getElementById('idNu ...
- C#实现文件下载
1,Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下:Content-Disposition: attachment;filename=filename.ext以 ...
- commonJS — 通用方法(for COM)
for COM github: https://github.com/laixiangran/commonJS/blob/master/src/forCOM.js 代码 /** * Created b ...
- Canu FAQ常见问题
链接:Canu FAQ Q: What resources does Canu require for a bacterial genome assembly(细菌基因组组装)? A mammal ...
- const修饰指针
关于const修饰指针的情况,一般分为如下4种情况: ; const int *a =&b; //情况1 int const *a =&b; //情况2 int* const a =& ...
- Eclipse 配置Tomcat
1.Eclipse EE 配置Tomcat Eclipse EE 主要用于Java Web开发和J2EE项目开发.Eclipse EE中配置Tomcat比较简单,新建一个Tomcat Server即可 ...
- Unity5.1 新的网络引擎UNET(二) UNET 官方推荐Demo案例
http://blog.csdn.net/u010019717/article/details/46873153 视频 http://www.iqiyi.com/playlist391685502.h ...