luci简介
LuCI框架是一个嵌入式设备的Web框架
HA( 高可用,双机热备,对外只有一个主机,但是两个主机都活着 )
luci安装配置
安装luci和ricci
- yum源配置
[root@server1 ~]# vim /etc/yum.repos.d/rhel-source.reponame=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.8.250/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release[HighAvailability]
name=Red Hat Enterprise Linux HighAvailability
baseurl=http://172.25.8.250/rhel6.5/HighAvailability
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release[LoadBalancer]
name=Red Hat Enterprise Linux LoadBalancer
baseurl=http://172.25.8.250/rhel6.5/LoadBalancer
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release[ResilientStorage]
name=Red Hat Enterprise Linux ResilientStorage
baseurl=http://172.25.8.250/rhel6.5/ResilientStorage
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release[ScalableFileSystem]
name=Red Hat Enterprise Linux ScalableFileSystem
baseurl=http://172.25.8.250/rhel6.5/ScalableFileSystem
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release[root@server1 ~]# yum clean all
[root@server1 ~]# yum repolist
[root@server1 ~]# scp /etc/yum.repos.d/rhel-source.repo server2:/etc/yum.repos.d/
[root@server1 ~]# yum repolist
[root@server1 ~]# yum search ricci
[root@server1 ~]# yum install ricci -y
[root@server1 ~]# passwd ricci
[root@server1 ~]# /etc/init.d/ricci start
[root@server1 ~]# chkconfig ricci on
[root@server2 ~]# yum install luci -y
[root@server2 ~]# /etc/init.d/luci start
Start luci... [ OK ]
Point your web browser to https://server2:8084 (or equivalent) to access luci ##复制网址到真机浏览器打开
用server2 的root用户和密码登陆
选择 create
create cluster之后,两台虚拟机都会重启,登陆server2,查看luci服务状态
开启luci服务后就进入管理系统了
安装nginx
传送门 : http://t.cn/RpBJ2LW
Fence简介
ricci1 主机为主,管理资源,但是如果出现问题,如硬盘损坏,ricci2主机接管ricci1主机上的资源,但是ricci1主机会抓住资源不放,当ricci1主机好了以后会继续管理主机上的资源,现在ricci1和ricci2主机都在管理同一资源,同时查看资源没有问题,但是同时写入会出现问题,这种现象称为脑裂,fence可以解决这个问题。fence设备属于第三方,如果ricci1和ricci2主机同时在管理资源,fence会让ricci1主机断电,重启。当 ricci1 主机再次开启时,发现资源被ricci2主机接管,ricci1主机就称为备机
安装fence
[root@server2 ~]# clustat
Cluster Status for my_HA @ Sun Sep 17 20:28:28 2017
Member Status: QuorateMember Name ID Status------ ---- ---- ------server2 1 Online, Localserver3 2 Online
[root@foundation20 Desktop]# yum install -y fence-virtd.x86_64
[root@foundation20 Desktop]# yum install -y fence-virtd-libvirt.x86_64
[root@foundation20 Desktop]# yum install -y fence-virtd-serial.x86_64
[root@foundation20 Desktop]# yum install -y fence-virtd-multicast.x86_64[root@foundation20 Desktop]# fence_virtd -c ##获取fence_xvm.keyModule search path [/usr/lib64/fence-virt]:
Listener module [multicast]:
Multicast IP Address [225.0.0.12]:
Multicast IP Port [1229]:
Interface [virbr0]: br0
Key File [/etc/cluster/fence_xvm.key]:
Replace /etc/fence_virt.conf with the above [y/N]? y[root@foundation20 Desktop]# mkdir -p /etc/cluster/ ##建立存放目录
[root@foundation20 cluster]# dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=128 count=1 ##获取key
1+0 records in
1+0 records out
128 bytes (128 B) copied, 0.000151728 s, 844 kB/s
[root@foundation20 cluster]# ls ##查看key
fence_xvm.key
[root@foundation20 cluster]# scp fence_xvm.key root@server2:/etc/cluster/ ##key复制给被管理主机
[root@foundation20 cluster]# systemctl restart fence_virtd ##重启服务
[root@foundation20 cluster]# systemctl status fence_virtd
[root@foundation20 cluster]# netstat -anulp | grep :1229 ##查看端口
udp 0 0 0.0.0.0:1229 0.0.0.0:* 6723/fence_virtd
图形添加fence等操作
选 Fence Devices
会同步到配置文件中
回到 Nodes,并选择 server2
add
粘到这里
server3 同上
server2
[root@server2 ~]# vim /etc/init.d/nginx#!/bin/sh
#
# nginx Startup script for nginx
#
# chkconfig: - 85 15
# processname: nginx
# config: /usr/local/nginx/conf/nginx/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# description: nginx is an HTTP and reverse proxy server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop nginx
### END INIT INFO# Source function library.
. /etc/rc.d/init.d/functionsif [ -L $0 ]; theninitscript=`/bin/readlink -f $0`
elseinitscript=$0
fi#sysconfig=`/bin/basename $initscript`#if [ -f /etc/sysconfig/$sysconfig ]; then
# . /etc/sysconfig/$sysconfig
#finginx=${NGINX-/usr/local/nginx/sbin/nginx}
prog=`/bin/basename $nginx`
conffile=${CONFFILE-/usr/local/nginx/conf/nginx.conf}
lockfile=${LOCKFILE-/var/lock/subsys/nginx}
pidfile=${PIDFILE-/usr/local/nginx/logs/nginx.pid}
SLEEPMSEC=${SLEEPMSEC-200000}
UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}
RETVAL=0start() {echo -n $"Starting $prog: "daemon --pidfile=${pidfile} ${nginx} -c ${conffile}RETVAL=$?echo[ $RETVAL = 0 ] && touch ${lockfile}return $RETVAL
}stop() {echo -n $"Stopping $prog: "killproc -p ${pidfile} ${prog}RETVAL=$?echo[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}reload() {echo -n $"Reloading $prog: "killproc -p ${pidfile} ${prog} -HUPRETVAL=$?echo
}upgrade() {oldbinpidfile=${pidfile}.oldbinconfigtest -q || returnecho -n $"Starting new master $prog: "killproc -p ${pidfile} ${prog} -USR2echofor i in `/usr/bin/seq $UPGRADEWAITLOOPS`; do/bin/usleep $SLEEPMSECif [ -f ${oldbinpidfile} -a -f ${pidfile} ]; thenecho -n $"Graceful shutdown of old $prog: "killproc -p ${oldbinpidfile} ${prog} -QUITRETVAL=$?echoreturnfidoneecho $"Upgrade failed!"RETVAL=1
}configtest() {if [ "$#" -ne 0 ] ; thencase "$1" in-q)FLAG=$1;;*);;esacshiftfi${nginx} -t -c ${conffile} $FLAGRETVAL=$?return $RETVAL
}rh_status() {status -p ${pidfile} ${nginx}
}# See how we were called.
case "$1" instart)rh_status >/dev/null 2>&1 && exit 0start;;stop)stop;;status)rh_statusRETVAL=$?;;restart)configtest -q || exit $RETVALstopstart;;upgrade)rh_status >/dev/null 2>&1 || exit 0upgrade;;condrestart|try-restart)if rh_status >/dev/null 2>&1; thenstopstartfi;;force-reload|reload)reload;;configtest)configtest;;*)echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"RETVAL=2
esacexit $RETVAL[root@server2 init.d]# chmod +x nginx
[root@server2 init.d]# scp nginx root@server3:/etc/init.d/
[root@server2 init.d]# clusvcadm -r my_group -m server3 ##将服务转移到server3上
Trying to relocate service:my_group to server3...Success
service:my_group is now running on server3
[root@server2 init.d]# clustat
Cluster Status for my_HA @ Sun Sep 17 21:17:07 2017
Member Status: QuorateMember Name ID Status------ ---- ---- ------server2 1 Online, Local, rgmanagerserver3 2 Online, rgmanagerService Name Owner (Last) State ------- ---- ----- ------ ----- service:my_group server3 started
[root@server3 ~]# echo c > /proc/sysrq-trigger ##使内核崩溃,测试fence是否生效
iscsi共享存储搭建
第一种存储方式 ( mkfs.ext4 )( 只可以在server2和server3上其中一个在同一个挂载点操作,不能多点同时挂载,但是支持多个不同的挂载点
[root@server3 ~]# clustat
Cluster Status for my_HA @ Sun Sep 17 23:13:32 2017
Member Status: QuorateMember Name ID Status------ ---- ---- ------server2 1 Online, rgmanagerserver3 2 Online, Local, rgmanagerService Name Owner (Last) State ------- ---- ----- ------ ----- service:my_group server3 started
[root@server3 ~]# clusvcadm -s my_group
Local machine stopping service:my_group...Success###server4(共享存储服务)
[root@server4 ~]# yum install -y scsi-*
[root@server4 ~]# vim /etc/tgt/targets.conf <target iqn.2017-09.com.example:server.target1>backing-store /dev/vdbinitiator-address 172.25.20.2initiator-address 172.25.20.3
</target>[root@server4 ~]# /etc/init.d/tgtd start
Starting SCSI target daemon: [ OK ][root@server4 ~]# tgt-admin -s
[root@server4 ~]# ps -ax
[root@server2 ~]# yum install -y iscsi-initiator-utils.x86_64
[root@server2 ~]# iscsiadm -m discovery -t st -p 172.25.20.4
Starting iscsid: [ OK ]
172.25.20.4:3260,1 iqn.2017-09.com.example:server.target1
[root@server2 ~]# ls /var/lib/iscsi/nodes/
iqn.2017-09.com.example:server.target1
[root@server2 ~]# iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2017-09.com.example:server.target1, portal: 172.25.20.4,3260] (multiple)
Login to [iface: default, target: iqn.2017-09.com.example:server.target1, portal: 172.25.20.4,3260] successful.##server 3 上照做这几步
[root@server2 ~]# pvcreate /dev/sda1dev_is_mpath: failed to get device for 8:1Physical volume "/dev/sda1" successfully created
[root@server2 ~]#
[root@server2 ~]# vgcreate clustervg /dev/sda1Clustered volume group "clustervg" successfully created
[root@server2 ~]# lvcreate -n my_lv -L 2G clustervgLogical volume "my_lv" created
[root@server2 ~]# mkfs.ext4 /dev/clustervg/my_lv
[root@server2 ~]# mount /dev/clustervg/my_lv /mnt
[root@server2 ~]# yum install mysql-server -y
[root@server2 ~]# /etc/init.d/mysqld start
[root@server2 ~]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock test
[root@server2 ~]# /etc/init.d/mysqld stop
Stopping mysqld: [ OK ]
[root@server2 ~]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql test
[root@server2 ~]# cp -a /var/lib/mysql/* /mnt
[root@server2 ~]# mount /dev/clustervg/my_lv /var/lib/mysql
[root@server2 ~]# chown mysql.mysql /var/lib/mysql
[root@server2 ~]# /etc/init.d/mysqld stop
[root@server2 ~]# umount /mnt
[root@server2 ~]# clustat
[root@server2 ~]# clusvcadm -d my_group
[root@server2 ~]# clusvcadm -e db
[root@server3 ~]# clusvcadm -r db -m server2
Trying to relocate service:db to server2...Success
service:db is now running on server2
数据储存第二种方式(网络文件系统gfs2,支持多点同时挂载)
###首先需要停止资源
[root@server2 ~]# clustat
Cluster Status for my_HA @ Mon Sep 18 10:28:51 2017
Member Status: QuorateMember Name ID Status------ ---- ---- ------server2 1 Online, Local, rgmanagerserver3 2 Online, rgmanagerService Name Owner (Last) State ------- ---- ----- ------ ----- service:db server2 started service:my_group (server3) disabled
[root@server2 ~]# clusvcadm -s db
Local machine stopping service:db...Success
[root@server2 ~]# clusvcadm -d db
Local machine disabling service:db...Success[root@server2 ~]# df -h ##确保两边都没有挂载
###格式化成gfs2,可同时挂载
[root@server2 ~]# mkfs.gfs2 -p lock_dlm -t my_HA:mygfs2 -j 3 /dev/clustervg/my_lv ##my_HA是集群创建的时候的名字,-j 3 代表有三份日志
This will destroy any data on /dev/clustervg/my_lv.
It appears to contain: symbolic link to `../dm-2'Are you sure you want to proceed? [y/n] yDevice: /dev/clustervg/my_lv
Blocksize: 4096
Device Size 2.00 GB (524288 blocks)
Filesystem Size: 2.00 GB (524288 blocks)
Journals: 3
Resource Groups: 8
Locking Protocol: "lock_dlm"
Lock Table: "my_HA:mygfs2"
UUID: eeb3e3d1-9214-2c9d-85c3-4255b6350d21[root@server2 ~]# mount /dev/clustervg/my_lv /mnt
[root@server2 ~]# ls /mnt/
[root@server2 ~]# cp -ap /var/lib/mysql/* /mnt/
[root@server2 ~]# ls /mnt/
ibdata1 ib_logfile0 ib_logfile1 mysql test
[root@server2 ~]# umount /mnt/
[root@server2 ~]# mount /dev/clustervg/my_lv /var/lib/mysql/
[root@server2 ~]# /etc/init.d/mysqld start
[root@server2 ~]# mysql
[root@server2 ~]# df
[root@server2 ~]# /etc/init.d/mysqld stop
[root@server2 ~]# umount /var/lib/mysql
[root@server2 ~]# df
[root@server2 ~]# blkid ##查看uid
[root@server2 ~]# vim /etc/fstab
UUID="eeb3e3d1-9214-2c9d-85c3-4255b6350d21 /var/lib/mysql/ gfs2 _netdev 0 0 ##最后加上这一行,自动挂载
[root@server2 ~]# mount -a ##挂载
[root@server2 ~]# df ##查看是否挂载成功
[root@server2 ~]# clustat
[root@server2 ~]# clusvcadm -e db
[root@server2 ~]# df
[root@server2 ~]# ls /var/lib/mysql
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock test
[root@server2 ~]# clusvcadm -r db -m server3
[root@server2 ~]# ls /var/lib/mysql