2012年6月14日 星期四

HA Active-Standby MySQL + Heartbeat 3.x + Coroysnc 1.x + Pacemaker 1.x on RHEL / CentOS - Section 2

- OS Pre-configuration task
Below listed items have to be done on both master nodes.

- Disable SELinux and iptables
[root@dbmaster-01~]# getenforce
Disabled
[root@dbmaster-01~]# service iptables stop
[root@dbmaster-01~]# chkconfig iptables off


- Network configuration

Each master node has to be configured with 2 network interfaces. One is external nic for external traffic (e.g. MySQL traffic, Internet traffic … etc) while another one is internal heartbeat nic which is used to connect 2 master nodes.

In our scenario the master nodes will have IP address like this.

dbmaster-01: IP 192.168.0.11/24, Gateway 192.168.0.1
dbmaster-02:  IP 192.168.0.12/24, Gateway 192.168.0.1

The VIP is 192.168.0.10/24 which will be floating between 2 nodes, depending on the server availability.

- Generate SSH-key and allow key-based authentication

[root@dbmaster-01~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
c7:50:ac:a4:09:fb:5d:f3:1e:13:ed:2e:21:d4:a7:f7 root@dbmaster-01
The key's randomart image is:
+--[ RSA 2048]----+
| .. |
| . ... |
| o +.. . . |
| . o .o+ o o |
| . .Sooo = |
| . ... * o |
| o * . |
| o . E|
| . |
+-----------------+
[root@dbmaster-01~]# ssh-copy-id -i .ssh/id_rsa.pub root@dbmaster-02 ##### replace dbmaster-02 with dbmaster-01 if you are doing it from dbmaster-02 to dbmaster-01
The authenticity of host dbmaster-02 (192.168.0.12)' can't be established.
RSA key fingerprint is 51:73:cb:48:c3:8e:9c:39:88:38:b8:a9:70:b8:fd:76.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'dbmaster-02' (RSA) to the list of known hosts.
root@dbmaster-02's password:
Now try logging into the machine, with "ssh 'root@dbmaster-02'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
[root@ dbmaster-01 ~]# ssh dbmaster-02 date##### replace dbmaster-02 with dbmaster-01 if you are doing it from dbmaster-02 to dbmaster-01
Tue Dec 27 22:08:44 EST 2011

 - Configure ntpd to make sure time are in sync
[root@dbmaster-01 ~]# service ntpd stop
Shutting down ntpd: [ OK ]
[root@dbmaster-01 ~]# ntpdate ntp.asia.pool.ntp.org
27 Dec 22:11:27 ntpdate[1796]: adjust time server x.x.x.x offset 0.000983 sec
[root@dbmaster-01 ~]# service ntpd start
Starting ntpd: [ OK ]


- Add host entries to host file to make sure both nodes see each other via dns name
[root@dbmaster-01 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

192.168.0.11 dbmaster-01 dbmaster-01.localdomain
192.168.0.12 dbmaster-02 dbmaster-02.localdomain
[root@dbmaster-01 ~]# ping dbmaster-01
PING dbmaster-01 (192.168.0.11) 56(84) bytes of data.
64 bytes from dbmaster-01 (192.168.0.11): icmp_seq=1 ttl=64 time=0.017 ms
^C
--- dbmaster-01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 588ms
rtt min/avg/max/mdev = 0.017/0.017/0.017/0.000 ms

[root@dbmaster-01 ~]# ping dbmaster-02
PING dbmaster-02 (192.168.0.12) 56(84) bytes of data.
64 bytes from dbmaster-02 (192.168.0.12): icmp_seq=1 ttl=64 time=0.017 ms
^C
--- dbmaster-01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 588ms
rtt min/avg/max/mdev = 0.017/0.017/0.017/0.000 ms


- Partition the shared-disk
The shared disk will be used to store MySQL db and have to be partition from master node (either one). If you are using vmware ESXi, you could simply mount the disk on both VM and the disk will probably be presented as second disk (e.g. /dev/sdb). Please be notice that no parallel run is allowed which means only one node could access and write the shared-disk at the same time or otherwise it will crash the disk. In our example, we will assume /dev/sdb as our shared-disk.

[root@dbmaster-01 ~]# mkfs.ext4 /dev/sdb #### /dev/sdb is the shared disk in this example

- Installing MySQL Packages.
This should be pretty striaght forward, given that your server could access the Internet with any issue.
[root@dbmaster-01 ~]# yum -y install mysql-server mysql
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.52-1.el6_0.1 will be installed
****************
**** skipped ****
****************
Dependency Installed:
perl-DBD-MySQL.x86_64 0:4.013-3.el6 perl-DBI.x86_64 0:1.609-4.el6

Complete!

- Configure MySQL
 Edit /etc/my.cnf as below.


[root@dbmaster-01 ~]# cat /etc/my.cnf
[mysqld]
datadir=/mysql
socket=/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
innodb_rollback_on_timeout=1
innodb_lock_wait_timeout=600
log-bin=mysql-bin  ## Just in case you want replication
binlog-format='ROW'  ## Just in case you want replication

[mysqld_safe]
log-error=/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

- Create the mount point and mount the shared disk
[root@dbmaster-01 ~]# mkdir /mysql
[root@dbmaster-01 ~]# mount /dev/sdb /mysql
[root@dbmaster-01 ~]# chown –R mysql:mysql /mysql

- Run mysql_install_db script to install the base-db, make sure this will only be run once only.

[root@ dbmaster-01 ~]# mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h test-db1.dpcloud.local password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[root@dbmaster-01 ~]# chown –R mysql:mysql /mysql

- Remember to unmount the shared-disk /mysql after that.

[root@ dbmaster-01 ~]# umount /mysql


沒有留言:

張貼留言