Linux系统架构

1.1 HA集群配置-1

iptables -F

getenforce

iptables -nvL

hostname

vim /etc/hosts   添加

192.168.1.33 mastar
192.168.1.199 slace

wget www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_32.noarch.rpm

rpm -ivh epel-release-6-8_32.noarch.rpm

yum -y install heartabeat

yum install -y libnet

1.2 HA集群配置-2

cd /usr/share/

cd /usr/share/doc/heartbeat-3.0.4/
cp authkeys ha.cf  haresources  /etc/ha.d

cd /etc/ha.d/

cd /etc/ha.d

vim authkeys

修改 auth   3

下面把 3  md5 Hello!   前面# 去掉

chmod 600 authkeys

master 192.168.1.34/24/eth0:0    nginx 配置一个虚拟网卡地址

虚拟网卡ip 配置

 cd /etc/sysconfig/network-scripts/

ls

cp ifcfg-eth0  ifcfg-eth0\:1

vim !$

DECICE=eth0:1

#HWADDR=

IPADDR=192.168.1.34

#UUID

 #GATEWAY

/etc/init.d/network restart

vim ha.cf

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility localo
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport  694
ucast eth1 192.168.1.33
auto_failback on
node master
node slave
ping 192.168.1.1
respawn hacluster /usr/lib/heartbeat/ipfail

scp authkeys haresources ha.cf  slave:/etc/ha.d/

 从 配置

cd /etc/ha.d

vim ha.cf  

ip

yum install -y nginx

1.3 HA集群配置-3 

 启动顺序  先启动主 再启动从

 /etc/init.d/heartbeat start    主

 ps aux |grep nginx

 /etc/init.d/heartbeat start    从

echo "11111111master" > /usr/share/nginx/html/index.html

 iptables -A INPUT -P icmp -j DROP

tail /var/log/ha-log

 iptables -D INPUT -P icmp -j DROP

/etc/init.d/heartbeat stop

 LB集群之LVS介绍

 LVS的NAT模式

hostname dir

hostname rs1

hostname rs2

dir 

yum install -y ipvsadm

vi /usr/local/sbin/lvs_nat.sh

添加配置

sh /usr/local/sbin/lvs_nat.sh

ipvsadm -ln

rs1

vi/etc/../ifcfg-etho

指定网关192.168.21.190

rs2 同样

curl 192.168.1.190

LVS的DR设置

先删除之前的配置信息 网关改会以前的

ipvsadm -ln

ipvsadm -c

iptables -t nat -F


LVS结合keepalived配置

1.8 nginx的负载均衡集群 

 cd /usr/local/nginx/conf/vhosts/

vim lb.conf

upstream aming {

   server 192.168.1.33:80  weight=2;

   server 192.168.1.199:80 weight=1;

}

tream aming {

   server 192.168.1.33:80  weight=2;

   server 192.168.1.199:80 weight=1;

}


server {

   listen 80;

   server_name www.123.com;

   location / {

       proxy_pass http://aming/;

       proxy_set_header Host $host;

    }

}

 /etc/init.d/nginx restart

  curl -xlocalhost:80  www123.com