七、使用crmsh为corosync添加资源
1.创建drbd配置文件的软连接(两台机器均操作):
1 ln -sv /usr/local/drbd/etc/drbd.conf /etc/drbd.conf 2 ln -sv /usr/local/drbd/etc/drbd.d /etc/drbd.d
2.修改php-fpm启动脚本为如下内容,如不修改,则corosync无法识别(两台机器均操作):
1 #!/bin/sh 2 #======================================================================================= 3 # php-fpm - this script start and stop the php-fpm daemon 4 # 5 # chkconfig 35 on 6 # description: php-fpm is a FastCGI web server. 7 # processname: php-fpm 8 # config: /usr/local/php/etc/php-fpm.conf 9 # pidfile: /var/run/php-fpm.pid 10 #======================================================================================= 11 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 12 13 BINFILE="/usr/local/php/sbin/php-fpm" 14 CFGFILE="/usr/local/php/etc/php-fpm.conf" 15 PIDFILE="/var/run/php-fpm.pid" 16 LOCKFILE="/var/lock/php-fpm.lock" 17 18 RETVAL=0 19 20 start() { 21 [[ -x $BINFILE ]] || exit 5 22 [[ -f $CFGFILE ]] || exit 6 23 24 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -gt 0 ]]; then 25 echo "The php-fpm is already running." 26 return 1 27 fi 28 29 $BINFILE -t >/dev/null 2>&1 30 31 if [[ $? -ne 0 ]]; then 32 echo "The php-fpm configure has error." 33 return 1 34 fi 35 36 echo -n "Starting php-fpm......" 37 $BINFILE -y $CFGFILE -g ${PIDFILE} 38 RETVAL=$? 39 echo 40 [[ $RETVAL -eq 0 ]] && touch $LOCKFILE 41 42 return $RETVAL 43 } 44 45 stop() { 46 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0 ]]; then 47 echo "The php-fpm is not running." 48 return 1 49 fi 50 51 echo -n "Shutting down php-fpm......" 52 53 if [[ -f $PIDFILE ]]; then 54 kill -QUIT `cat ${PIDFILE}` 55 else 56 kill -QUIT `ps aux | grep php-fpm | awk '/master/{print $2}'` 57 fi 58 59 RETVAL=$? 60 echo 61 [[ $RETVAL -eq 0 ]] && rm -f $LOCKFILE $PIDFILE 62 63 return $RETVAL 64 } 65 66 restart() { 67 stop 68 sleep 1 69 70 while true 71 do 72 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0 ]]; then 73 start 74 break 75 fi 76 sleep 1 77 done 78 79 RETVAL=$? 80 echo 81 82 return $RETVAL 83 } 84 85 reload() { 86 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0 ]]; then 87 echo "The php-fpm is not running." 88 return 1 89 fi 90 91 echo -n $"Reloading php-fpm......" 92 93 if [[ -f $PIDFILE ]]; then 94 kill -USR2 `cat ${PIDFILE}` 95 else 96 kill -USR2 `ps aux | grep php-fpm | awk '/master/{print $2}'` 97 fi 98 99 RETVAL=$? 100 echo 101 102 return $RETVAL 103 } 104 105 case "$1" in 106 start) 107 start 108 ;; 109 110 stop) 111 stop 112 ;; 113 114 restart) 115 restart 116 ;; 117 118 reload) 119 reload 120 ;; 121 122 *) 123 echo "Usage: service php-fpm {start|stop|restart|reload}" 124 RETVAL=1 125 esac 126 127 exit $RETVAL
下面运行crm命令,进入crm命令行模式,非特殊注明情况下操作均在此模式下进行,在一台机器上操作即可。
3.关闭corosync的stonith检测和仲裁:
1 configure //进入配置菜单 2 property stonith-enabled=false //关闭stonith设备 3 property no-quorum-policy=ignore //关闭仲裁设备 4 verify //语法检测 5 commit //提交
4.添加资源(configure菜单下):
1 primitive mydrbd ocf:drbd params drbd_resource=web op monitor role=Master interval=20s timeout=30s op monitor role=Slave interval=30s timeout=20s op start timeout=240s op stop timeout=240s //定义drbd资源 2 primitive myfile Filesystem params device="/dev/drbd0" directory="/mydata" fstype="ext4" op monitor interval=30s timeout=60s op start timeout=60s op stop timeout=60s //定义文件系统资源 3 primitive myip IPaddr params ip=192.168.19.150 op monitor interval=30s timeout=60s //定义VIP资源 4 primitive mynginx lsb:nginx op monitor interval=30s timeout=20s //定义nginx资源 5 primitive mysql lsb:mysqld op monitor interval=30s timeout=60s //定义mysqld资源 6 primitive myphp lsb:php-fpm //定义php-fpm资源 7 group myserver myfile myip mynginx myphp mysql //定义资源组 8 verify //语法检测,如没问题,先不要提交
5.添加各种约束:
1 ms ms_mydrbd mydrbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=True //drbd主从资源配置 2 colocation myfile_with_mydrbd_master inf: myfile ms_mydrbd:Master //定义排列约束,myfile要和drbd的Master节点在一起 3 colocation mysql_with_myfile inf: mysql myfile //mysql要和myfile在一起 4 order myfile_after_ms_mydrbd_master Mandatory: ms_mydrbd:promote myfile:start //定义顺序约束,drbd主节点被提升,myfile才能启动 5 order myip_after_myfile Mandatory: myfile myip 6 order mynginx_after_myip Mandatory: myip mynginx 7 verify 8 commit
6.提交之后,可以看到,所有资源已经运行在coro2,打开进行操作也没问题:
7.下面操作让coro2成为备用节点。可以看到,资源全部转移到coro1上了,打开进行各种操作仍然OK:
1 cd .. 2 node standby coro2 //coro2成为备用 ----------------------------- 等待5秒 3 node online coro2 //重新上线 4 status //查看状态
至此,实验全部结束。因为时间原因,很多细节有待完善,欢迎大家提供宝贵意见,谢谢!
本文永久更新链接地址: