cobarmysql高可用
---------------------------------------------
创新互联建站服务项目包括江州网站建设、江州网站制作、江州网页制作以及江州网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,江州网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到江州省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
server2 IP:172.25.38.2
server5 IP:172.25.38.5
---------------------------------------------
1)安装MySQL [server2]、[server5]
yum install -y mysql-server
rpm -qa|grep mysql##安装好,可见已安装的包
mysql-libs-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
[server2] ##编辑mysql配置文件
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server-id=2
binlog-do-db=dbtest
binlog-ignore-db=mysql
log-bin=mysql-bin
master-host=172.25.38.5
master-user=ly
master-password=westos
master-port=3306
replicate-ignore-db=mysql
replicate-do-db=dbtest
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
当配置server2为主时,server5为从时,把以#开头的,把#去掉
[server5]
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
server-id=5
log-bin=mysql-bin
binlog-do-db=dbtest
binlog-ignore-db=mysql
#master-host=172.25.38.2
#master-user=ly
#master-password=westos
#master-port=3306
#replicate-ignore-db=mysql
#replicate-do-db=dbtest
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log
/etc/init.d/mysqld start##开启数据库
mysqladmin -u root password westos##设置密码
[root@server5 ~]# mysql -p##进入数据库设置
Enter password:
mysql> create user ly@'172.25.38.5' identified by 'westos';##创建用户并设置密码
mysql> grant all on *.* to ly@'172.25.38.5';##授予权限
mysql> flush privleges;##刷新
mysql> show master status;##主节点状态
+------------------+----------+--------------+------------------+
| File |Position |Binlog_Do_DB | Binlog_Ignore_DB|
+------------------+----------+--------------+------------------+
| mysql-bin.000004| 254 | dbtest | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
[root@server2 ~]# mysql -p
Enter password:
mysql> change master to master_host='172.25.38.2',master_user='ly',master_password='westos';
mysql> start slave;##开启从节点
mysql> show slave status\G;##查看从的状态
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.25.38.5
Master_User: ly
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 254
Relay_Log_File: mysqld-relay-bin.000005
Relay_Log_Pos: 399
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: dbtest
Replicate_Ignore_DB: mysql
##做同样类似操作,最后做出双向主从同步
[root@server2 ~]# mysql -p
Enter password:
mysql> create user ly@'172.25.38.2' identified by 'westos';
mysql> grant all on *.* to ly@'172.25.38.2';
mysql> flush privileges;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position| Binlog_Do_DB| Binlog_Ignore_DB|
+------------------+----------+--------------+------------------+
| mysql-bin.000012| 106 | dbtest | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
[root@server5 ~]# mysql -p
Enter password:
mysql> change master to master_host='172.25.38.2',master_user='ly',master_password='westos';
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.25.38.5
Master_User: ly
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.0000012
Read_Master_Log_Pos: 254
Relay_Log_File: mysqld-relay-bin.0000013
Relay_Log_Pos: 106
Relay_Master_Log_File: mysql-bin.0000012
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: dbtest
Replicate_Ignore_DB: mysql
---------------------------------------------
2)安装heartbeat [server2]、[server5]
得到如下安装包
heartbeat-3.0.4-2.el6.x86_64.rpm
heartbeat-devel-3.0.4-2.el6.x86_64.rpm
heartbeat-libs-3.0.4-2.el6.x86_64.rpm
ldirectord-3.9.5-3.1.x86_64.rpm
yum install openssl perl-Net-SSLeay perl-TimeDate perl-libwww-perl perl-Compress-Zlib perl-HTML-Parser perl-HTML-Tagset ipvsadm -y##解决依赖性
rpm -ivh heartbeat-libs-3.0.4-2.el6.x86_64.rpm ldirectord-3.9.5-3.1.x86_64.rpm heartbeat-3.0.4-2.el6.x86_64.rpm heartbeat-devel-3.0.4-2.el6.x86_64.rpm
vim /etc/ha.d/ha.cf##编辑配置
34 logfacility local0
48 keepalive 2
56 deadtime 30
61 warntime 10
71 initdead 60
76 udpport 694##端口
91 bcast eth0 # Linux
157 auto_failback on
211 node server5.example.com
212 node server2.example.com
222 ping 172.25.38.250##一个同一网段可ping的IP,最好是网关
255 respawn hacluster /usr/lib64/heartbeat/ipfail
261 apiauth ipfail gid=haclient uid=hacluster
vim /etc/ha.d/haresources##资源配置
server5.example.com IPaddr::172.25.38.100/24/eth0 drbddisk::example Filesystem::/dev/drbd1::/var/lib/mysql::ext4 mysqld
vim /etc/ha.d/authkeys
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!
两台配置一样,直接scp过去就好。
---------------------------------------------
3)配置drbd
在两台主机上添加硬盘,最好一样大小,方便操作
////////////////////
得到如下包
drbd-8.4.2.tar.gz
或者8个如下安装包
drbd-8.4.2-2.el6.x86_64.rpm
drbd-xen-8.4.2-2.el6.x86_64.rpm
drbd-udev-8.4.2-2.el6.x86_64.rpm
drbd-utils-8.4.2-2.el6.x86_64.rpm
drbd-pacemaker-8.4.2-2.el6.x86_64.rpm
drbd-heartbeat-8.4.2-2.el6.x86_64.rpm
drbd-bash-completion-8.4.2-2.el6.x86_64.rpm
drbd-km-2.6.32_431.el6.x86_64-8.4.2-2.el6.x86_64.rpm
以tar包方式进行安装如下:
rpm -ivh drbd-*
yum install gcc flex rpm-build kernel-devel -y
cp /root/drbd-8.4.0.tar.gz /root/rpmbuild/SOURCES/
tar zxf drbd-8.4.0.tar.gz
cd drbd-8.4.0
./configure --enable-spec
./configure --enable-spec --with-km
在当前目录下得到两个文件
drbd.spec drbd-km.spec
rpmbuild -bb drbd.spec
rpmbuild -bb drbd-km.spec
cd /root/rpmbuild/RPMS/x86_64
rpm -ivh *
scp /root/rpmbuild/RPMS/x86_64/* 172.25.38.5:/root
并且执行 rpm -ivh drbd-*
vim /etc/drbd.d/example.res
1 resource example {
2 meta-disk internal;
3 device /dev/drbd1;
4 syncer {
5 verify-alg sha1;
6 }
7 on server5.example.com {
8 disk /dev/vdb;
9 address 172.25.38.5:7789;
10 }
11 on server2.example.com {
12 disk /dev/vdb;
13 address 172.25.38.2:7789;
14 }
15 }
drbdadm create-md example
/etc/init.d/drbd start
drbdadm primary example
cat /proc/drbd#在两台主机上查看同步状态
mkfs.ext4 /dev/drbd1#数据同步结束后创建文件系统
mount /dev/drbd1 /var/www/html#挂载文件系统
---------------------------------------------
4)安装jdk
得到
jdk-6u32-linux-x64.bin
sh jdk-6u32-linux-x64.bin
mv jdk-6u32-linux-x64 java
mv java /usr/local
vim /etc/profile
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/bin:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
cd /home/
测试:
vim test.java
class test {
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
java test
---------------------------------------------
5) 安装cobar
cobar-server-1.2.6.zip
unzip cobar-server-1.2.6.zip
cd /root/cobar-server-1.2.6/conf
vim schema.xml
vim server.xml
cd /root/cobar-server-1.2.6/bin
[root@server2 bin]# ./startup.sh
"/usr/local/java/bin/java" -Dcobar.home="/root/cobar-server-1.2.6" -classpath "/root/cobar-server-1.2.6/conf:/root/cobar-server-1.2.6/lib/classes:/root/cobar-server-1.2.6/lib/cobar-common-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-config-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-net-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-parser-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-route-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-server-1.2.6.jar:/root/cobar-server-1.2.6/lib/log4j-1.2.16.jar:/root/cobar-server-1.2.6/lib/slf4j-api-1.6.4.jar:/root/cobar-server-1.2.6/lib/slf4j-log4j12-1.6.4.jar" -server -Xms1024m -Xmx1024m -Xmn256m -Xss128k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+UseFastAccessorMethods -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=75 com.alibaba.cobar.CobarStartup >> "/root/cobar-server-1.2.6/logs/console.log" 2>&1 &
[root@server2 bin]# /etc/init.d/drbd start
Starting DRBD resources: [
]
.
[root@server2 bin]# ip addr show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:
link/ether 52:54:00:f6:11:cd brd ff:ff:ff:ff:ff:ff
inet 172.25.38.2/24 brd 172.25.38.255 scope global eth0
inet 172.25.38.100/24 brd 172.25.38.255 scope global secondary eth0
inet6 fe80::5054:ff:fef6:11cd/64 scope link
valid_lft forever preferred_lft forever
[root@server2 bin]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 15006084 1723528 12520292 13% /
tmpfs 203008 0 203008 0% /dev/shm
/dev/vda1 495844 33452 436792 8% /boot
/dev/drbd1 4128284 95208 3823372 3% /var/lib/mysql
[root@server2 bin]#./shutdown.sh
[root@server5 conf]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 17069948 1602508 14600320 10% /
tmpfs 251136 0 251136 0% /dev/shm
/dev/vda1 495844 33467 436777 8% /boot
/dev/drbd1 4128284 95232 3823348 3% /var/lib/mysql
[root@server5 conf]# ip addr show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:
link/ether 52:54:00:6e:00:88 brd ff:ff:ff:ff:ff:ff
inet 172.25.38.5/24 brd 172.25.38.255 scope global eth0
inet 172.25.38.100/24 brd 172.25.38.255 scope global secondary eth0
inet6 fe80::5054:ff:fe6e:88/64 scope link
valid_lft forever preferred_lft forever
-------------------------------------
网页题目:cobarmysql高可用
网站链接:http://pwwzsj.com/article/jdhhjg.html