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模块用于生成和修改常见配置文档,当前模块的名称 ...
随机推荐
- commonJS — 数字操作(for Number)
for Number github: https://github.com/laixiangran/commonJS/blob/master/src/forNumber.js 代码 /** * Cre ...
- visual studio 自带单元测试demo
0) 创建类,编写方法类1) 在方法点击鼠标右键,在运行测试(T)和调试测试(D)之间会有一个 <创建单元测试>选项.有则进入2,没有则看1.01.0) 菜单栏 工具-->自定义-- ...
- 求出数组前面k个元素或数组中元素大于一半的元素(快速排序与堆排序的灵活运用)
写这个的目的在于,说明快速排序的灵活运用.我们来看下关于快速排序中的一部分关键代码: 快速排序代码: int a[101],n;//定义全局变量,这两个变量需要在子函数中使用 void quickso ...
- 不能使用tpcc-mysql测试OneProxy
因为Proxy类的中间件不适合实现prepared statement,所以无法测试,导致我们无法使用标准的测试工具去发布OneProxy的测试结果
- 扩展Date的DateAdd方法--计算日期
Date.prototype.DateAdd = function(strInterval, Number) { var dtTmp = this; switch (strInterval) { ca ...
- (10)odoo控制器操作
-----------------更新时间11:17 2016-09-18 星期日 完善讲解17:44 2016-02-17 星期三-----------------* 控制器Controlle ...
- mysql知识初篇(一)
mysql介绍 (1) mysql数据库是瑞典AB开发. (2) mysql--> sun --> oracle. (3) mysql数据库的特点. 1. 开源. 2. 免费. 3. 跨平 ...
- 初学java之StringBuffer类的常用方法
import java.text.*; public class Gxjun { public static void main(String atgs[]) { StringBuffer str= ...
- Sql server 日期函数和日期转换
时间函数 SQL Server Date 函数 下面的表格列出了 SQL Server 中最重要的内建日期函数: 函数 描述 GETDATE() 返回当前日期和时间 DATEPART(Type,dat ...
- 初始jQuery
JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF1.5+, Safari 2.0+, Opera ...