Deploying mysql*******************************************
Yum-y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* Mak E CMake bison*
Useradd mysql-d/usr/local/mysql-s/sbin/nologin
TAR-ZXVF mysql-5.1.72.tar.gz
CD mysql-5.1.72.tar.gz
./configure--prefix=/usr/local/mysql/--with-charset=utf8
Make && make install
Chown-r Mysql.mysql/usr/local/mysql
Cd/usr/local/mysql/scripts
./mysql_install_db--user=mysql--basedir=/usr/local/mysql/--datadir=/data/mysql
Copy configuration file to/etc directory
[email protected] mysql-5.1.72]# CP support-files/my-medium.cnf/etc/my.cnf
Copy startup script to resource Directory
CP Support-files/mysql.server/etc/rc.d/init.d/mysqld
Add MySQL Service
[[email protected] mysql-5.1.72] #chmod +x/etc/rc.d/init.d/mysqld
Mysqladmin–u root password 123456//Set Roo password
10. Start MySQL
[[email protected] mysql-5.1.72] #service mysqld start
#配置库文件搜索路径
#echo "/usr/local/mysql/lib/mysql" >>/etc/ld.so.conf
#ldconfig
#添加/usr/local/mysql/bin to the environment variable path
#export path= $PATH:/usr/local/mysql/bin
Cp-r/data/mysql
Chown-r Mysql.mysql/data/mysql
# #编辑Mysql的配置文件/ETC/MY.CNF
[Email protected] ~]# sed-n "/^[^#]/p"/etc/my.cnf
[Mysqld]
Server-id=1 # #保证全局唯一
Log-bin=mysql-bin# #开启记录二进制日志的功能
Relay-log=mysql-relay-bin
datadir=/data/mysql/
Socket=/data/mysql/mysql.sock
User=mysql
Symbolic-links=0
[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
To manage MySQL boot to heartbeat, create a soft link to the MySQL startup script in the Heartbeat resource script directory
Ln-s/etc/init.d/mysqld/etc/ha.d/resource.d/mysqld
# # # # #重启mysql服务 #######
Service mysqld Restart
############# #配置mysql的主从复制 ####################
Add an account for replication on master
Mysql>grant REPLICATION SLAVE on * * to ' repl ' @ ' 10.0.0.2 ' identified by ' repl123456 ';
To back up the data on master, first execute the following statement:
Mysql>flush TABLES with READ LOCK;
Mysql>reset master;
Do not exit the terminal, or the lock will fail, in the case of not exiting the terminal, and then open a terminal directly packaged compressed data files or use the Mysqldump tool to export data.
Cd/data/mysql
Tar zcvf mysql.tar.gz/data/mysql
SCP mysql.tar.gz [Email protected]:/root/
After the data transfer is complete, execute the following command on the master terminal that just executed the flushtables with READ LOCK command:
Mysql> UNLOCK TABLES;
To view the status of master:
Mysql>show Master Status\g #以下面列出的配置, set the Master_log_file value of the slave, and the Master_log_pos value.
Setting up the slave host
Turn on master and slave synchronization and execute the following statement on slave:
Mysql>change MASTER to master_host= ' 10.0.0.1 ',
->master_user= ' Repl ',
->master_password= ' repl123456 ',
->master_log_file= ' mysql-bin.000001 ',
->master_log_pos=106;
When you are done, turn on slave
Mysql>slave start;
View slave status
Mysql>show slave Status\g
When both slave_io_running and slave_sql_running are yes, the configuration is successful.
A few problems to be noted ********************************
1) If the Log-bin, relay-log parameters are defined in the MY.CNF, then ensure that the definitions are independent of the hostname,
Because if the log file names of these two classes are related to the hostname, the switchover process causes the slave host to not continue to synchronize, which can be set as follows:
Log-bin=mysql-bin
Relay-log=mysql-relay-bin
Ensure that the names of two files on both hosts are the same
2) To ensure that MySQL can pass start\stop\status three parameters, the default heartbeat is in the LSB style,
A return value that contains OK or running indicates that the resource is healthy, that the return value contains stopped or no indicates that the resource is unhealthy, and that other resource scripts are similar.
3) do not set MySQL to start automatically when the machine restarts, mysqld as a resource of heartbeat, Heartbeat will be unified management.
4) Ensure that each MySQL my.cnf configuration file is identical to other configuration items except Server-id.
Heartbeat Deployment ****************************************
The heartbeat card for both hosts is eth1
Node1 's heartbeat IP is: 10.0.0.1
Node2 's heartbeat IP is: 10.0.0.2
Install Heartbeat:
1. Create users and Groups first
Groupadd-g haclient
Useradd-u 2000-g haclient Hacluster
Packages required to install heartbeat:
Yum-y Install pkgconfig glib2-devel e2fsprogs libxml2* PyXML
Recompile and install Libnet
TAR-ZXVF libnet-1.1.2.1.tar.gz-c./
./configure
Make && make install
Installing Heartbeat
TAR-ZXVF heartbeat-2.1.2.tar.gz-c./
./configureme Configure
make&& make Install
Configure Heartbeat
There are three configuration files required: HA.CF, Haresources, Authkeys.
These three configuration files need to be under the/ETC/HA.D directory, but the default is no three files, so you want to:
Copy storage Path/heartbeat-2.1.2/doc/ha.cf/etc/ha.d/
Copy storage Path/heartbeat-2.1.2/doc/haresources/etc/ha.d/
Copy storage Path/heartbeat-2.1.2/doc/authkeys/etc/ha.d/
The permission to modify Authkeys is 600
chmod 600/etc/ha.d/authkeys
Configure HA.CF
[Email protected] ~]# sed-n "/^[^#]/p"/etc/ha.d/ha.cf
LogFile/var/log/ha-log #指定heartbeat日志的位置
Logfacilitylocal0
KeepAlive 1 #每秒检测心跳
Deadtime#备用节点15s内没有检测到主机心跳 to confirm the failure of each other
Warntime 5#警告5次
Initdead#守护进程启动30s后, start service resources
Ucast eth1 10.0.0.1#另一台主机的eth1和eth0的ip地址 with two different networks to detect heartbeat availability
Ucast eth0 10.2.16.254
Auto_failback off #当主节点切换到备节点之后, when the primary node returns to normal, no failback is done because the cost of switching mysql-master is high
Respawn Hacluster/usr/lib64/heartbeat/ipfail
Respawn hacluster/usr/lib64/heartbeat/dopd #开启dopd功能
Apiauth Ipfail gid=haclient Uid=hacluster
Apiauth DOPD gid=haclient Uid=hacluster
Node Node1 defines the host name of the nodes
Node Node2 defines the host name of the nodes
Configuring Resource Files Haresources
/etc/ha.d/haresources
Node1 drbddisk::r0 filesystem::/dev/drbd0::/data mysqld ipaddr::10.2.16.250/24/eth0
Node1 is the host name of the master node
Drbddisk is a script to manage DRBD, default heartbeat not, need to copy this script to/etc/ha.d/resource.d/drbddisk (at the end of this script, copy and paste directly)
R0 is the startup resource for DRBD, "drbddisk::r0" can switch the host for DRBD to primary node or secondary node, only nodes with a status of primary can mount the DRBD partition
The Drbddisk script is equivalent to performing a DRBDADM primary r0 or Drbdadm secondary r0 operation to change and mount the resource role of DRBD
Mysqld means the MySQL service that started the machine
Ipaddr::10.2.16.250/24/eth0 indicates IP drift for virtual IP 250
Configuring Authkeys Certification Files
/etc/ha.d/authkeys
Auth 1
1 SHA1 ha_cluster #使用sha1验证, Password: ha_cluster
#将drbddisk脚本加执行权限:
Chmod+x/etc/ha.d/resource.d/drbddisk
After setting the master node, copy the HA.CF haresources Authkeys and Drbddisk file to the standby node directly.
SCP ha.cf haresources authkeys resources.d/drbddisk [email protected]:/root/
After moving to the HA.D directory on the standby node, modify the Ucast value of the HA.CF to be the primary node IP, the other does not change
Verify that the MySQL service is turned off, and that the heartbeat service is turned on on both hosts
Service Heartbeat Start
Observe the startup process of heartbeat by looking at/var/log/ha-log
This article is from the "Fate" blog, make sure to keep this source http://czybl.blog.51cto.com/4283444/1426063