38_04_2_实验利用haresources进行资源管理

cat >>实验说明:<<EOF
web服务器:
192.168.122.162 node1.test.com
192.168.122.244 node2.test.com
nfs服务器:
192.168.122.27 nfs.test.com
EOF

#①提供主机名

1
2
3
4
5
6
7
8
9
10
11
hostname "node1.test.com" 
vim /etc/sysconfig/network
HOSTNAME=node1.test.com

hostname "node2.test.com"
vim /etc/sysconfig/network
HOSTNAME=node2.test.com

hostname "nfs.test.com"
vim /etc/sysconfig/network
HOSTNAME=nfs.test.com

#②web服务器能够基于公钥登陆

1
2
3
4
5
ssh-keygen -t rsa  -f ~/.ssh/id_rsa -P '' 
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.122.244

ssh-keygen -t rsa  -f ~/.ssh/id_rsa -P ''
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.122.162

#③提供hosts文件

1
2
3
4
5
cat >>/etc/hosts<<EOF 
192.168.122.162    node1.test.com
192.168.122.244    node2.test.com
EOF
scp /etc/hosts node2:/etc/

#④时间同步

1
2
3
4
5
6
7
8
ntpdate ntp.api.bz 
echo "*/5     *       *       *       *       ntpdate ntp.api.bz &>/dev/null" >> /etc/crontab
```
#⑤利用epel源,安装heartbeat
```bash
yum -y install epel-release
yum -y install heartbeat && chkconfig heartbeat on
yum -y install httpd && chkconfig httpd off

#⑥提供配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
cp -p /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} /etc/ha.d 
cd /etc/ha.d/
chmod 600 authkeys
dd if=/dev/random count=1 bs=512 | md5sum

cat >>authkeys<<EOF
auth1
1 md5 05d7ca80f950d1a7b41322bd39220d2a
EOF

cat >>ha.cf<<EOF
logfacility    local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport    694
mcast eth1 225.0.0.1 694 1 0
auto_failback on
node    node1.test.com
node    node2.test.com
ping 192.168.122.1
deadping 30
compression    bz2
compression_threshold 2
EOF

cat >>haresources<<EOF
node1.test.com IPaddr::192.168.122.100/24/eth1 httpd
EOF

scp  /etc/ha.d/{ha.cf,authkeys,haresources} node2:/etc/ha.d/

echo "node1.test.com" > /var/www/html/index.html
echo "node2.test.com" > /var/www/html/index.html

for x in {1..2};do ssh node$x 'service heartbeat start' start;done

#进行访问测试,然后转到/usr/share/heartbeat-3.0.4 && ./hb_standby 将自己转移为备节点,那么另外一个将成为主节点;

#提供nfs服务器文件共享:
yum -y install nfs-utils rpcbind
echo "<h1>success</h1>" > /web/htdocs/index.html
service nfs start
service rpcbind start
showmount -e 192.168.122.27

mount -t nfs 192.168.122.27:/web/htdocs /mnt
umount /mnt      #heartbeat会进行自动挂载,但是要注意:nfs服务不能关掉,否则资源不会被访问到;

cat >>haresources<<EOF
node1.test.com IPaddr::192.168.122.100/24/eth1 Filesystem::172.16.100.27:/web/htdocs::/var/www/html::nfs httpd
EOF

scp haresources node2:/etc/ha.d/
for x in {1..2};do ssh node$x 'service heartbeat start' start;done

1
2
3
4
5
6
7
#启动heartbeat会出现,稍微等一会,就会发现资源能够正常工作了,如果不行,那么service heartbeat restart即可;下面是首次启动时的输出样例; 
#Starting High-Availability services: INFO:  Resource is stoppedDone.


#如果开启了iptables服务器:
#iptables -A INPUT -p udp -dport 694 -j ACCEPT
#iptables -A OUTPUT -p udp --sport 694 -j ACCEPT

因为我的网卡是eth1,所以全文的网络接口指向的是eth1;;;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值