close

set node1,node2 hosts
---------------------------------------------------------------------
node1:
[root@node1 ~]# uname -n
node1
[root@node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.73.128 node1.test.com node1
192.168.73.129 node2.test.com node2

node2:
[root@node2 ~]# uname -n
node2
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.73.128 node1.test.com node1
192.168.73.129 node2.test.com node2

--------------------------------------------------------------------------------
ssh key ==>
[root@node1 ~]# ssh node1
[root@node1 ~]# ssh node2
[root@node2 ~]# ssh node1
[root@node2 ~]# ssh node2

node1:
[root@node1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2

node2:
[root@node2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1
---------------------------------------------------------------------------------
ntp sync ==>
node1:
[root@node1 ~]# ntpdate 202.120.2.101

node2:
[root@node2 ~]# ntpdate 202.120.2.101
----------------------------------------------------------------------------------
iptables & selinux set
node1:
[root@node1 ~]# service iptables stop
[root@node1 ~]# chkconfig iptables off
[root@node1 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled

node2:
[root@node2 ~]# service iptables stop
[root@node2 ~]# chkconfig iptables off
[root@node2 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
--------------------------------------------------------------------------------------
epel source set==>
node1:
[root@node1 src]# wget http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node1 src]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@node1 src]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@node1 ~]# rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@node1 ~]# yum list
[root@node1 ~]# yum install -y libaio

node2:
[root@node2 src]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node2 src]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@node2 src]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@node2 ~]# rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@node2 ~]# yum list
[root@node2 ~]# yum install -y libaio
------------------------------------------------------------------------------------------
install corosync ==>

node1:
[root@node1 ~]# yum install -y corosync

node2:
[root@node2 ~]# yum install -y corosync
------------------------------------------------------------------------------------------
corosync setup ==>
[root@node1 ~]# cd /etc/corosync/
[root@node1 ~]# cp corosync.conf.example corosync.conf
[root@node1 corosync]# cat corosync.conf
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.73.0
mcastaddr: 226.94.10.10
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
to_syslog: no
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}

-------------------------------------------------------------
corosync key ==>
[root@node1 corosync]# mv /dev/{random,random.bak}
[root@node1 corosync]# ln -s /dev/urandom /dev/random
[root@node1 corosync]# corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits for key from /dev/random.
Press keys on your keyboard to generate entropy.
Writing corosync key to /etc/corosync/authkey.

----------------------------------------------------------------
corosync set to node2 ==>
[root@node1 corosync]# scp authkey corosync.conf node2:/etc/corosync/

---------------------------------------------------------------
pacemaker install ==>

node1:
[root@node1 ~]# yum install -y pacemaker

node2:
[root@node2 ~]# yum install -y pacemaker
------------------------------------------------------------------
crmsh install ==>
[root@node1 ~]# yum install -y python-dateutil python-lxml
[root@node1 ~]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/network:/ha-clustering:/Stable/openSUSE_12.2/x86_64/crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
[root@node1 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm --nodeps
[root@node1 ~]# scp crmsh-1.2.6-0.rc2.2.1.x86_64.rpm node2:/root/
[root@node1 ~]# ssh "/root/rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm --nodeps"
------------------------------------------------------------------
[root@node1 ~]# ssh node2 "service corosync start;service corosync start"
[root@node1 ~]# /etc/init.d/pacemaker start;service corosync start
[root@node1 ~]# crm status
-------------------------------------------------------------------
[root@node1 ~]# wget -P /etc/yum.repos.d/ http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/network:ha-clustering:Stable.repo
[root@node1 ~]# yum install crmsh
[root@node2 ~]# wget -P /etc/yum.repos.d/ http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/network:ha-clustering:Stable.repo
[root@node2 ~]# yum install crmsh
------------------------------------------------------------------
DRBD install ==>
node1:
[root@node1 ~]# yum -y install drbd84 kmod-drbd84

node2:
[root@node1 ~]# yum -y install drbd84 kmod-drbd84

------------------------------------------------------------------
configure drbd node1 node2 ==> /etc/drbd.d/global_common.conf

global {
usage-count no;
# minor-count dialog-refresh disable-ip-verification
}
common {
handlers {
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
# fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
# split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup {
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
}
options {
# cpu-mask on-no-data-accessible
}
disk {
# size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes
# disk-drain md-flushes resync-rate resync-after al-extents
# c-plan-ahead c-delay-target c-fill-target c-max-rate
# c-min-rate disk-timeout
on-io-error detach;
}
net {
# protocol timeout max-epoch-size max-buffers unplug-watermark
# connect-int ping-int sndbuf-size rcvbuf-size ko-count
# allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
# after-sb-1pri after-sb-2pri always-asbp rr-conflict
# ping-timeout data-integrity-alg tcp-cork on-congestion
# congestion-fill congestion-extents csums-alg verify-alg
# use-rle
cram-hmac-alg "sha1";
shared-secret "mydrbdlab";
}
}
------------------------------------------------------------------------
hdd resource ==>

[root@node2 ~]# cat /etc/drbd.d/web.res
resource web {
on node1 {
device /dev/drbd0;
disk /dev/sda3;
address 192.168.73.128:7789;
meta-disk internal;
}
on node2 {
device /dev/drbd0;
disk /dev/sda3;
address 192.168.73.129:7789;
meta-disk internal;
}
}
--------------------------------------------------------------------------
sync to node2 ==>
[root@node1 ~]# scp global_common.conf web.res node2:/etc/drbd.d/
---------------------------------------------------------------------------
init drbd hdd ==>

node1:
[root@node1 ~]# dd if=/dev/zero of=/dev/sdb1 bs=1M count=128
[root@node1 ~]# drbdadm create-md web
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.

node2:
[root@node2 ~]# dd if=/dev/zero of=/dev/sdb1 bs=1M count=128
[root@node2 ~]# drbdadm create-md web
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.

------------------------------------------------------------------------
start drbd ==>

node1:
[root@node1 ~]# service drbd start

node2:
[root@node2 ~]# service drbd start
-------------------------------------------------------------------------
show drbd status ==>

node1:
[root@node1 ~]# drbd-overview
0:web/0Connected Secondary/SecondaryInconsistent/InconsistentC r-----

node2:
[root@node2 ~]# drbd-overview
0:web/0Connected Secondary/SecondaryInconsistent/InconsistentC r-----
-------------------------------------------------------------------------
set node1 to primary ==>
[root@node1 ~]# drbdadm -- --overwrite-data-of-peer primary web
[root@node1 ~]# drbd-overview
0:web/0 SyncSource Primary/Secondary UpToDate/Inconsistent C r-----
[>...................] sync'ed: 6.7% (1961372/2097052)K
--------------------------------------------------------------------------
format drbd hdd ==>

[root@node1 ~]# mkfs.ext3 /dev/drbd0
[root@node1 ~]# mkdir /mydata
[root@node1 ~]# mount /dev/drbd0 /mydata
[root@node1 ~]# umount /mydata
[root@node1 ~]# drbdadm secondary web


[root@node2 ~]# drbdadm primary web
[root@node2 ~]# mkdir /mydata
[root@node2 ~]# mount /dev/drbd0 /mydata
[root@node2 ~]# umount /mydata

----------------------------------------------------------------------------
node1 mysql install ==>

[root@node1 ~]# wget http://mysql.llarian.net/Downloads/MySQL-5.5/mysql-5.5.33-linux2.6-x86_64.tar.gz
[root@node1 ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@node1 ~]# groupadd -g 3306 mysql
[root@node1 ~]# useradd -u 3306 -g mysql -s /sbin/nologin -M mysql
[root@node1 ~]# cd /usr/local/
[root@node1 local]# drbdadm primary web
[root@node1 local]# mount /dev/drbd0 /mydata
[root@node1 local]# ln -s /mydata/ mysql
[root@node1 local]# cd /usr/local/mysql-5.5.33-linux2.6-x86_64
[root@node1 mysql-5.5.33-linux2.6-x86_64]# tar cvf - . |(cd ../mysql;tar xf -)
[root@node1 mysql-5.5.33-linux2.6-x86_64]# cd
[root@node1 ~]# chown -R root:mysql /usr/local/mysql/*
[root@node1 ~]# id mysql
uid=3306(mysql) gid=3306(mysql) groups=3306(mysql)
[root@node1 ~]# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
[root@node1 ~]# /usr/local/mysql/scripts/mysql_install_db --datadir=/mydata/data/ --basedir=/usr/local/mysql --user=mysql
[root@node1 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@node1 ~]# chmod +x /etc/init.d/mysqld
[root@node1 ~]# service mysqld start
[root@node1 ~]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.08 sec)
mysql>exit
[root@node1 ~]# /etc/init.d/mysqld stop
[root@node1 ~]# umount /mydata
[root@node1 ~]# drbdadm secondary web
[root@node1 ~]#
------------------------------------------------------------------------------
[root@node2 ~]# groupadd -g 3306 mysql
[root@node2 ~]# useradd -u 3306 -g mysql -s /sbin/nologin -M mysql
[root@node2 ~]# cd /usr/local/
[root@node2 local]# drbdadm primary web
[root@node2 local]# mount /dev/drbd0 /mydata
[root@node2 local]# ln -s /mydata/ mysql
[root@node2 mysql]# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@node2 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld ysqld
[root@node2 mysql]# chmod +x /etc/init.d/mysqld
[root@node2 mysql]# /etc/init.d/mysqld start
[root@node2 mysql]# /etc/init.d/mysqld stop
[root@node2 mysql]# umount /mydata
[root@node2 mysql]# drbdadm secondary web

-------------------------------------------------------------------------------
crmsh set drbd off ==>

node1:
[root@node1 ~]# service drbd stop
Stopping all DRBD resources: .
[root@node1 ~]# chkconfig drbd off

node2:
[root@node2 ~]# service drbd stop
Stopping all DRBD resources: .
[root@node2 ~]# chkconfig drbd off

---------------------------------------------------------------
crm set ==>
[root@node1 ~]# crm configure property stonith-enabled=false
[root@node1 ~]# crm configure property no-quorum-policy=ignore
[root@node1 ~]#

-------------------------------------------------------------------
crm set ==>

[root@node1 ~]# crm configure primitive drbd_mysql ocf:linbit:drbd params drbd_resource="web" op monitor interval="15s"
[root@node1 ~]# crm configure primitive fs_mysql ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/mydata" fstype="ext3"
[root@node1 ~]# crm configure primitive ip_mysql ocf:heartbeat:IPaddr2 params ip="192.168.73.200" nic="eth0:0"
[root@node1 ~]# crm configure primitive mysqld lsb:mysqld
[root@node1 ~]# crm configure group mysql fs_mysql ip_mysql mysqld
[root@node1 ~]# crm configure ms ms_drbd_mysql drbd_mysql meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
[root@node1 ~]# crm configure colocation mysql_on_drbd inf: mysql ms_drbd_mysql:Master
[root@node1 ~]# crm configure order mysql_after_drbd inf: ms_drbd_mysql:promote mysql:start

------------------------------------------------------------------------------------------------
Reconnecting...[root@node1 ~]# crm_mon -1
Last updated: Thu Nov 28 08:56:26 2013
Last change: Thu Nov 28 08:51:01 2013 via cibadmin on node1
Stack: classic openais (with plugin)
Current DC: node1 - partition with quorum
Version: 1.1.10-1.el6_4.4-368c726
2 Nodes configured, 2 expected votes
5 Resources configured


Online: [ node1 node2 ]

Resource Group: mysql
fs_mysql (ocf::heartbeat:Filesystem): Started node1
ip_mysql (ocf::heartbeat:IPaddr2): Started node1
mysqld (lsb:mysqld): Started node1
Master/Slave Set: ms_drbd_mysql [drbd_mysql]
Masters: [ node1 ]
Slaves: [ node2 ]
[root@node1 ~]#

 

 

arrow
arrow

    echochio 發表在 痞客邦 留言(2) 人氣()