Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Cobar mysql High availability

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-

Server2 IP:172.25.38.2

Server5 IP:172.25.38.5

-

1) install mysql [server2], [server5]

Yum install-y mysql-server

Rpm-qa | when grep mysql## is installed, you can see the installed packages

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] # # Edit mysql configuration file

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

When configuring server2 as the master and server5 as the slave, remove the # that starts with #

[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## Open the database

Mysqladmin-u root password westos## set password

[root@server5 ~] # mysql-packs # enter database settings

Enter password:

Mysql > create user ly@'172.25.38.5' identified by 'westos';## create the user and set the password

Mysql > grant all on *. * to ly@'172.25.38.5';## Grant permissions

Mysql > flush privleges;## refresh

Mysql > show master status;## master node 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;## enable slave node

Mysql > show slave status\ Gternal status # View the status of slave

* * 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

# # do the same, and finally make a two-way master-slave synchronization

[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) install heartbeat [server2], [server5]

Get the following installation package

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-yearly # solves dependencies

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## Editing configuration

34 logfacility local0

48 keepalive 2

56 deadtime 30

61 warntime 10

71 initdead 60

76 udpport 694 port

91 bcast eth0 # Linux

157 auto_failback on

211 node server5.example.com

212 node server2.example.com

222 ping 172.25.38.250 gateway # an ping-capable IP on the same network segment, preferably a gateway

255 respawn hacluster / usr/lib64/heartbeat/ipfail

261 apiauth ipfail gid=haclient uid=hacluster

Vim / etc/ha.d/haresources## resource configuration

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!

The configuration of the two sets is the same, just scp it directly.

-

3) configure drbd

Add hard drives to two hosts, preferably the same size, easy to operate

/

Get the following package

Drbd-8.4.2.tar.gz

Or 8 installation packages as follows

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

Install as a tar package as follows:

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

Get two files in the current directory

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

And execute 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# view synchronization status on two hosts

Create a file system after mkfs.ext4 / dev/drbd1# data synchronization finishes

Mount / dev/drbd1 / var/www/html# mount file system

-

4) install jdk

Get

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/

Test:

Vim test.java

Class test {

Public static void main (String [] args)

{

System.out.println ("Hello world!")

}

}

Java test

-

5) install 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

172.25.38.5:3306/dbtest

172.25.38.5:3306/dbtest

Root

Westos

STRICT_TRANS_TABLES

Vim server.xml

Westos

Dbtest

Id

two

five hundred and twelve

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: mtu 16436 qdisc noqueue state UNKNOWN

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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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 / 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 / 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: mtu 16436 qdisc noqueue state UNKNOWN

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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

-

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report