一、nginx安装配置
http://nginx.org/en/download.html
Mainline version:主线版本
Stable version:稳定版本
Legacy versions:旧版本
yum -y install pcre-devel
yum -y install zlib-devel
tar -zxvf nginx.tar.gz
cd nginx
支持socket: ./configure --prefix=/usr/local/nginx --with-stream
make & make install
安装编译后默认路径:/usr/local/nginx
启动:./sbin/nginx
指定配置文件启动:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止:./sbin/nginx -s stop
重启:./sbin/nginx -s reload
二、keepalived安装配置(1.2.7)
解压:tar -xvzf keepalived-1.3.4.tar.gz
创建运行文件夹:mkdir keepalived
下载安装openssl: yum install openssl-devel
安装:cd /usr/local/keepalived-1.3.4
./configure --prefix=/usr/local/keepalived --sysconf=/etc
Please install libnfnetlink headers.
rpm -i libnfnetlink-devel-0.0.40-1.el5.rf.x86_64.rpm --force --nodeps
编译:make && make install
创建快捷方式:
ln -s /usr/local/keepalived/sbin/keepalived /sbin/ --建立软链接
cp /usr/local/keepalived-1.3.4/keepalived/etc/init.d/keepalived /etc/init.d
chkconfig –add keepalived -- 添加到系统服务
chkconfig keepalived on -- 检测是否添加成功
启动keepalived:service keepalvied start|stop|restart
/etc/keepalived/目录下加载keepalived.conf配置文件
日志:/var/log/messages
三、Keepalived配置:
! Configuration File for keepalived
global_defs {
## 设置lvs的id,在一个网络内唯一
router_id LVS_V1
}
vrrp_instance VI_1 {
## 主机配置,从机为BACKUP
state MASTER
## 网卡名称(ifconfig查看ip地址对应的网卡)
interface ens33
virtual_router_id 51
## 权重值,值越大,优先级越高,backup设置比master小,这样就能在master宕机后讲backup变为master,而master回复后就可以恢复.
priority 100(备节点可以为50)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
## 同一网段虚拟IP
192.168.0.100
}
}
#虚拟服务地址
virtual_server 192.168.0.100 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
#真实的服务地址
real_server 192.168.0.129 80 {
weight 1
TCP_CHECK{
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}