mysql+heartbeat

一.依賴環境安裝
yum install gcc-c++  gcc ncurses-devel
tar zxvf cmake-2.8.9.tar.gz
cd cmake-2.8.9
./configure
make;make install
二.mysql安裝與配置
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.5.27.tar.gz
cd mysql-5.5.27
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.27 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0
make
make install
=======================mysql配置=================================
cd /usr/local/mysql-5.5.27/
cp ./support-files/my-huge.cnf /etc/my.cnf
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
mkdir -p /data/mysql
mkdir -p /data/mysql/3306/logs/binlog/
chown -R mysql:mysql /data/mysql
/usr/local/mysql-5.5.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.5.27 --datadir=/data/mysql/3306/data
mv /etc/my.cnf /data/mysql/3306/
ln -s /data/mysql/3306/my.cnf /etc/my.cnf
service mysqld start
cp -rf /usr/local/mysql-5.5.27/bin/* /usr/bin/
mysqladmin -u root password 'pinla2012'
======================主從配置============================
【master1】
====主數據庫設置====
vim /etc/my.cnf
在mysqld中追加
#********master1*********
server-id=1
log-bin=mysql-bin
read-only=0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
#binlog-do-db=pinladb
binlog_ignore_db=mysql
binlog_ignore_db=test
binlog_ignore_db=information_schema
replicate-ignore-db=test
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1

service mysqld restart
mysql -uroot -p
GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER,RELOAD ON *.* TO pl_backup@'%'IDENTIFIED by 'pinla2012';
==pinla_backup賬號測試==
mysql -h192.168.10.240 -upinla_backup -p

change master to master_host='192.168.10.245',master_user='pl_backup',master_password='pinla2012', master_log_file='mysql-bin.000005';
flush privileges;
slave start;
show slave status\G

【master2】
#********master2*********
server-id=2
log-bin=mysql-bin
read-only=0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
#binlog-do-db=pinladb
binlog_ignore_db=mysql
binlog_ignore_db=test
binlog_ignore_db=information_schema
replicate-ignore-db=test
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2

service mysqld restart
mysql -uroot -p
GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER,RELOAD ON *.* TO pl_backup@'%'IDENTIFIED by 'pinla2012';
==pinla_backup賬號測試==
mysql -h192.168.10.245 -upinla_backup -p

change master to master_host='192.168.10.240',master_user='pl_backup',master_password='pinla2012', master_log_file='mysql-bin.000008';
flush privileges;
slave start;
show slave status\G

show processlist \G;

【slave】
===從數據庫設置====
#****slave******
server-id=10
log-bin=mysql-bin
binlog_format=mixed
replicate-ignore-db=test
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
relay-log=db-server-2-relay-bin
log-slave-updates
===設置備份點===
mysql -uroot -p
slave stop;
change master to master_host='192.168.10.240',master_user='pl_backup',master_password='pinla2012', master_log_file='mysql-bin.000008';
slave start;
show slave status\G
==================heartbeat配置===========================
vip:192.168.10.244
master1-eth3:192.168.10.240
master1-eth2:10.10.10.100
master2-eth0:10.10.10.200
master2-eth1:192.168.10.245

1.雙master服務器網卡設置
使用網線直接連接兩個master,並且配置兩個服務器的IP
2.安裝HA與HA依賴包
yum install libnet heartbeat* heartbeat-devel heartbeat-pils heartbeat-stonith heartbeat-ldirectord ipvsadm
cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
==配置心跳加密方式:authkeys==
vim /etc/ha.d/authkeys
auth 1
1 crc

chmod 600 /etc/ha.d/authkeys
==配置心跳的監控:haresources==
vim /etc/ha.d/haresources
追加
PL100 IPaddr::192.168.10.245 ipvsadm mysqld
#PL100 爲主主機名(可以使用uname -n獲得) ipvsadm mysqld爲啓動心跳同時啓動該服務。
#IPaddr:: 爲VIP
mkdir -p /var/log/ha_log
chmod 777 /var/log/ha_log
==配置心跳的配置文件:ha.cf==
vi /etc/ha.d/ha.cf
#ha的日誌文件記錄位置
logfile /var/log/ha_log/ha-log.log
#使用eth3做心跳監測
bcast eth3
#設定心跳(監測)時間時間爲2秒
keepalive 2
warntime 10
deadtime 30
initdead 120
hopfudge 1
#使用udp端口694進行心跳監測
udpport 694
auto_failback on
#節點1,必須要與 uname -n 指令得到的結果一致。
node PL100
#節點2
node PL102
ping 192.168.10.1 #通過ping網關來監測心跳是否正常
#respawn hacluster /usr/lib/heartbeat/ipfail
#apiauth ipfail gid=root uid=root
debugfile /var/log/ha_log/ha-debug.log

#創建日誌文件
touch /var/log/ha_log/ha-log.log
==設置ipvsadm的巡迴監測==
ipvsadm -A -t 192.168.10.244:3306 -s rr
ipvsadm -a -t 192.168.10.244:3306 -r 10.10.10.100:3306 -m
ipvsadm -a -t 192.168.10.244:3306 -r 10.10.10.200:3306 -m
執行後則開始進行監測
ipvsadm --list
service heartbeat start
chkconfig --add heartbeat
==防火牆設置==
iptables -I INPUT -p udp --dport 694 -j ACCEPT
=======到此爲止以上爲mysql+hearbeat配置========

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章