Mysql主主
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql主主相关的知识,希望对你有一定的参考价值。
mysql主主同步实现
1,基本的思路是排除数据库单点故障,保障数据高可用性。
2,前期对于要求不高的话可以用主主同步来实现,后期如果不能满足要求可以在后面加从数据库。
3,实验需要的环境及数据库的版本如下表格:
序号 | 名称 | IP地址 | 数据库版本 | 系统版本 |
1 | MySQL-Master01 | 10.93.58.72 | mysql-5.5.32 | CentOS release 6.9 |
2 | MySQL-Master02 | 10.93.58.73 | mysql-5.5.32 | CentOS release 6.9 |
3 | Test | 10.93.58.70 | 无 | CentOS release 6.9 |
4 | virtual IP | 10.93.58.74 | 无 | 无 |
4,正式安装数据步骤:
1)我是用了一个脚本来安装这个Mysql-5.5.32数据库,脚本如下:
#!/bin/bash
#auto_install_mysql
#auth by tony date 2018-07-31
yum -y install gcc gcc-c++ make ncurses ncurses-devel libaio-devel cmake
groupadd mysql
useradd mysql -s/sbin/nologin -M -g mysql
mkdir /application
wget http://10.93.58.70/lamp/mysql-5.5.32.tar.gz
tar xvf mysql-5.5.32.tar.gz
cd mysql-5.5.32
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32
-DMYSQL_DATADIR=/data/mysql
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii
-DENABLED_LOCAL_INFILE=ON
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
-DWITH_FAST_MUTEXES=1
-DWITH_ZLIB=bundled
-DENABLED_LOCAL_INFILE=1
-DWITH_READLINE=1
-DWITH_EMBEDDED_SERVER=1
-DWITH_DEBUG=0
if [ $? -eq 0 ];then
make && make install
ln -s /application/mysql-5.5.32/ /application/mysql
/bin/cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chown mysql.mysql /application/mysql
chown mysql.mysql /data
echo 'export PATH=/application/mysql/bin:$PATH '>>/etc/profile
source /etc/profile
mv /etc/my.cnf /etc/my.cnf.bak
cat >/etc/my.cnf <<EOF
[mysqld]
port = 3306
socket = /application/mysql-5.5.32/tmp/mysql.sock
datadir =/data/mysql
user =mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=mysql-bin
server-id = 1
auto_increment_offset=1
auto_increment_increment=2
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
replicate-do-db =all
EOF
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/mysql --user=mysql
/etc/init.d/mysqld start
chkconfig mysqld on
mysqladmin -uroot password 'hwg123'
echo -e " 33[32m----------------------------------------------- 33[0m"
echo -e "