vm01:192.168.122.1 vm25:192.168.122.25 vm26:192.168.122.26 vm35:192.168.122.35 陪软件仓库: vim /etc/yum.r
vm01:192.168.122.1
vm25:192.168.122.25
vm26:192.168.122.26
vm35:192.168.122.35
陪软件仓库:
vim /etc/yum.repos.d/cluster.repo
1 [rhel-server]
2 name=Server
3 baseurl=file:///iso/Server
4 gpgcheck=0
5 enabled=1
6
7 [rhel-LoadBalancer]
8 name=LoadBalancer
9 baseurl=file:///iso/LoadBalancer
10 gpgcheck=0
11 enabled=1
12
13 [rhel-HighAvailability]
14 name=HighAvailability
15 baseurl=file:///iso/HighAvailability
16 gpgcheck=0
17 enabled=1
18
19 [rhel-ResilientStorage]
20 name=HighAvailability
21 baseurl=file:///iso/ResilientStorage
22 gpgcheck=0
23 enabled=1
24
25 [rhel-ScalableFileSystem]
26 name=ScalableFileSystem
27 baseurl=file:///iso/ScalableFileSystem
28 gpgcheck=0
29 enabled=1
vm01: yum install haproxy
vim /etc/haproxy/haproxy.cfg
87 listen serverweb *:80
88 balance roundrobin
89 server vm25 192.168.122.25 check
90 server vm36 192.168.122.36 check
91
92 stats enable
93 #stats uri /stat /haproxy?stats
94 stats admin if LOCALHOST
95 stats auth admin:admin
96 stats refresh 5s
或者:
frontend main *:80
default_backend app
backend app
balance roundrobin
server vm25 192.168.122.25 check
server vm36 192.168.122.36 check
stats enable
#stats uri /stat /haproxy?stats
stats admin if LOCALHOST
stats auth admin:admin
stats refresh 5s
service haproxy restart
vim /etc/rsyslog.conf
13 $ModLoad imudp
14 $UDPServerRun 514
36 local.* /var/log/haproxy.log
37 local.* ~
service rsyslog restart
访问 127.0.0.1/haproxy?stats 可以管理
yum install keepalived
vim /etc/keepalived/keepalived.conf
1 ! Configuration File for keepalived
2
3 global_defs {
4 notification_email {
5 [email protected]
6 [email protected]
7 [email protected]
8 }
9 notification_email_from [email protected]
10 smtp_server 192.168.200.1
11 smtp_connect_timeout 30
12 router_id LVS_DEVEL
13 }
14
15 vrrp_script chk_haproxy {
16 script "killall -0 haproxy" #cheaper than pidof
17 interval 2 #check every 2 seconds
18 weight 2
19 }
20
21 vrrp_instance VI_1 {
22 state MASTER
23 interface virbr0
24 virtual_router_id 55
25 priority 100
26 advert_int 1
27 authentication {
28 auth_type PASS
29 auth_pass 123321
30 }
31 virtual_ipaddress {
32 192.168.122.200
33 }
34
35 track_script {
36 chk_haproxy
37 }
38 }
service keepalived restart
vm25: 配置haproxy 和vm01 一样
配置日志一样
配置keepalived 和vm01不一样的地方
state MASTER
priority 99
interface eth0 这个用 ifconfig 看产生VIP的网卡是哪个
service keepalived restart
service haproxy restart
vm26和vm36
yum install httpd
vim /etc/httpd/conf/httpd.conf
ServerName localhost
vim /var/www/html/index.html
写入内容
service httpd restart
测试: http://192.168.122.200