System: CentOS 6.5 mysql version 5.6.30
MySQL Segment
Two-machine mutual trust 192.168.0.31
Ssh-keygen-t Rsa-p '
Ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected]
Two-machine mutual trust 192.168.0.30
Ssh-keygen-t Rsa-p '
Ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected]
Both machines need to be installed in the following configuration, exactly the same.
Yum-y Install CMake
Tar XF mysql-5.6.30.tar.gz
CD mysql-5.6.30
Cmake-dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/mysqldata/data-dsysconfdir=/etc-dwith_myisam_ Storage_engine=1-dwith_innobase_storage_engine=1-dwith_memory_storage_engine=1-dwith_readline=1-dwith_ Partition_storage_engine=1-dmysql_unix_addr=/tmp/mysql/mysql.sock-dmysql_tcp_port=3306-ddefault_charset=utf8- Ddefault_collation=utf8_general_ci-denabled_local_infile=1-dextra_charsets=all
Make-j 2 && make-j 2 Install
Mkdir/mydata/data-pv
Create a MySQL user
GROUPADD-G 3030 MySQL
Useradd-u 3030-g 3030-r-s/sbin/nologin MySQL
Chown Mysql.mysql/mydata/data-r
Chown mysql.mysql/usr/local/mysql/*-R
echo "Export path= $PATH:/usr/local/mysql/bin" >>/etc/profile.d/mysql.sh
Vim/etc/man.config Update man file, 48 line Plus
Manpath/usr/local/mysql/man
Mv/etc/my.cnf{,.bak}
Cd/usr/local/mysql Copy the profile startup file into the MySQL installation directory
CP SUPPORT-FILES/MY-DEFAULT.CNF/ETC/MY.CNF
Start the configuration file, if there is ha, do not need to boot the service
CP Support-files/mysql.server/etc/init.d/mysqld
chmod +x/etc/init.d/mysqld
Chkconfig mysqld on
Configuring the My.cnf File
Vim/etc/my.cnf
[Mysqld] Add the following content
Basedir =/usr/local/mysql
DataDir =/mydata/data
Port = 3306
Socket =/tmp/mysql/mysql.sock
./scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql/--datadir=/mydata/data/ initialization configuration
[[email protected] mysql]# MySQL
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)
After the configuration startup is complete, the following error configuration file appears when there is a specified Mysql.sock file directory and then
Mkdir/var/lib/mysql If Mysql.sock is not in the TMP file, find/-name Mysql.sock
Ln-sv/tmp/mysql/mysql.sock/var/lib/mysql/mysql.sock
Simple master-Slave configuration:
Primary server
Configure the Log_bin log to open the binary log first
Log_bin =/mysql/master/masterbin
Binlog_format = Mixed
SERVER_ID = 111
Open permissions
Grant all on * * to ' master ' @ ' 192.168.0.% ' identified by ' Masterss '
Show master status;
From the server
Configuring the Relay_bin log to turn on the relay log
Relay_log =/mysql/relay/relay_log
Binlog_format = mixed format is promiscuous mode
SERVER_ID = 222 Server ID master and slave need not from
First Test whether the server can connect to the primary server Mysql-u master-h 192.168.0.x-pmasterss
Can continue, cannot please check whether Iptables and SELinux open, open please close or release 3306 port
Enter MySQL to define the primary server configuration user is defined in the primary server, logfile must be consistent with the primary server, the query mode show master logs;
Change Master to master_user= ' 192.168.0.x ', master_user= ' master ', master_password= ' Masterss ', master_log_file= ' Masterbin.000003 ', master_log_pos=120;
start slave; open slave
show slave status; The following two must be yes, if there is a synchronous IO error, please check log_file and log_pos the two must remain the same as the primary server log
Slave_io_running:yes
Slave_sql_running:yes
Then check if it is successful, create a new database in the primary server create databases Xxtest;
Use show databases from the server; The query can query to the database to indicate that it has been created successfully, and if not, recheck the slave status
Define script to monitor whether slave is normal
#!/bin/bash
Status= ' mysql-uroot-pxiongge-e ' show slave status\g ' | grep "Slave_io_running" | Awk-f: ' {print $NF} ' | Sed ' s/\ (yes\)/\1/'
if [$Status! = "yes"]; Then
echo "can define mailbox here" #如果有sendmail可以直接mail: XXX.com.
Else
echo "123" &>/dev/null
Fi
Two states will make grep change a bit, write two scripts better, then define a scheduled task in crontab, send mail for no, Yesi output information
Crontab-e
Monitor */1 per minute * * * * xx/xx.sh
This article from "Xiong" blog, reproduced please contact the author!
MySQL 5.6.30