拓扑
1、 基本配置
根据拓扑配置IP
2、 调度器配置
-安装ipvsadm,并启用ip_vs模块
[[email protected] ~]# yum -y install ipvsadm [[email protected] ~]# modprobe ip_vs [[email protected] ~]# echo "modproce ip_vs" >>/etc/rc.local
-修改内核参数
[[email protected] ~]# sysctl –p net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.eth0.send_redirects = 0
-安装keepalived,并修改配置文件
--安装
[[email protected]~]# cd /usr/src/ [[email protected] src]# tar zxfkeepalived-1.2.13.tar.gz [[email protected] src]# cd keepalived-1.2.13 [[email protected] keepalived-1.2.13]#./configure --prefix=/--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ && make&& make install
--修改配置文件-全局配置
global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL_1 #调度器名称 }
--修改配置文件-热备配置
vrrp_instance VI_1 { #热备组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.1.11 #群集VIP地址 } } vrrp_instance VI_2 { #热备组2 state BACKUP interface eth0 virtual_router_id 52 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.22 } }
--修改配置文件-web服务器配置
irtual_server 192.168.1.11 80 { #虚拟服务器地址(VIP),端口’ delay_loop 6 #健康检查时间间隔(s) lb_algo rr #调度算法-轮询 lb_kind DR #集群工作模式 ! persistence_timeout 50 #连接保持时间(s),去掉!启用 protocol TCP #应用服务采用的是TCP协议 real_server 192.168.1.2 80 { #第一个web节点的地址,端口 weight 1 #节点的权重 TCP_CHECK { #健康检查方式 connect_timeout 3 #连接超时 nb_get_retry 3 #重试次数 delay_before_retry 3 #重试间隔 } } real_server 192.168.1.3 80 { #第二个web节点的地址,端口 weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } virtual_server 192.168.1.22 80 { delay_loop 6 lb_algo rr lb_kind DR ! persistence_timeout 50 protocol TCP real_server 192.168.1.2 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.1.3 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
--重启服务
service keepalived restart
--同理配置另一调度器
3、 节点服务器配置
-修改内核参数
[[email protected] network-scripts]# sysctl–p net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.default.arp_ignore = 1 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_announce = 2
-配置lo:0,lo:1虚接口
[[email protected] ~]# cat/etc/sysconfig/network-scripts/ifcfg-lo:0 DEVICE=lo:0 ONBOOT=yes IPADDR=192.168.1.11 NETMASK=255.255.255.255 [[email protected] ~]# cat/etc/sysconfig/network-scripts/ifcfg-lo:1 DEVICE=lo:1 ONBOOT=yes IPADDR=192.168.1.22 NETMASK=255.255.255.255
-添加本地路由
[[email protected] ~]# route add -host192.168.1.11 dev lo:0 [[email protected] ~]# route add -host192.168.1.22 dev lo:1 [[email protected] ~]# echo "route add-host 192.168.1.11 dev lo:0" >> /etc/rc.local [[email protected] ~]# echo "route add-host 192.168.1.22 dev lo:1" >> /etc/rc.local
-启动web服务
4、 NFS配置
[[email protected] ~]# cat /etc/exports /var/www/html 192.168.2.0/24(rw,sync,no_root_squash) [[email protected] ~]# service rpcbindrestart 停止 rpcbind: [确定] 正在启动 rpcbind: [确定] [[email protected] ~]# servie nfs restart -bash: servie: command not found [[email protected] ~]# service nfs restart 关闭 NFS 守护进程: [失败] 关闭 NFS mountd: [失败] 关闭 NFS quotas: [失败] Shutting down RPC idmapd: [失败] 启动 NFS 服务: [确定] 关掉 NFS 配额: [确定] 启动 NFS mountd: [确定] 启动 NFS 守护进程: [确定] 正在启动 RPC idmapd: [确定] [[email protected] ~]# showmount -e192.168.2.1 Export list for 192.168.2.1: /var/www/html 192.168.2.0/24 [[email protected] ~]# mount192.168.2.1:/var/www/html/ /var/www/html/
5、 内部服务器发布—NAT
服务配置防火墙代替路由器测试
Eth0配置两个ip
[[email protected] network-scripts]# catifcfg-eth0 DEVICE=eth0 HWADDR=00:0C:29:D5:AD:1B TYPE=Ethernet UUID=d3db1bd9-b0f5-4cc2-a5bb-3f0c28430ee0 ONBOOT=yes IPADDR0=200.0.0.11 NETMASK=255.255.255.0 IPADDR1=200.0.0.22 NETMASK=255.255.255.0
--NAT
[[email protected] ~]# iptables -t nat -APREROUTING -i eth0 -d 200.0.0.11 -p tcp --dport 80 -j DNAT --to 192.168.1.11 [[email protected] ~]# iptables -t nat -APREROUTING -i eth0 -d 200.0.0.22 -p tcp --dport 80 -j DNAT --to 192.168.1.22
附:DNS配置
[[email protected] ~]# cat /var/named/abc.com $TTL 1D @ INSOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H) ; minimum in ns dns dns in a 200.0.0.2 www in a 200.0.0.11 in a 200.0.0.22
--启动nfs前
--启动nfs后
--调度器1
--调度器2
时间: 2024-10-17 10:04:05