1.环境
1)Mysql-master:
IP:xxx.xxx.xxx.xxx
操作系统:centOS 6.5
Mysql版本:5.7.11
Boost版本:boost_1_59
主机名:msyql-master.com
2)Mysql-slave:
IP:xxx.xxx.xxx.xxx
操作系统:centOS 6.5
Mysql版本:5.7.11
Boost版本:boost_1_59
主机名:mysql-slave.com
2.安装准备(两台都做)
1)配置好IP与主机名
保证master与slave能ping通,并且将下面两行添加到/etc/hosts下
xxx.xxx.xxx.xxx mysql-master.com
xxx.xxx.xxx.xxx mysql-slave.com
2)卸载系统自带的mysql
(1)列出所有被安装的RPM
rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
(2) 忽略依赖关系卸载列出的包
rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
3)利用rz命令上传程序包
yum -y install lrzsz
上传mysql-5.7.11.tar.gz和库文件boost_1_59_0.tar.gz到/usr/local/src目录
4)安装需要的编译软件及库文件(两台都做)
自行配置yum环境
yum -y install libtermcap-devel imake autoconf automake libtool m4 libstdc++-devel gcc-c++ zlib-devel ncurses-devel bison make cmake
3.创建用户及用户组(两台都做)
groupadd mysql
useradd -M -g mysql -s /sbin/false mysql
4.规划目录(两台都做)
mkdir -pv /mnt/mysql
mkdir -pv /mnt/mysql/data
5.解压安装(两台都做)
cd /usr/local/src/
tar -xvf boost_1_59_0.tar.gz -C /mnt/
tar xvf mysql-5.7.13.tar.gz
cd mysql-5.7.13
cmake -DCMAKE_INSTALL_PREFIX=/mnt/mysql \
-DMYSQL_DATADIR=/mnt/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_BOOST=/mnt/boost_1_59_0 \
-DEXTRA_CHARSETS=all
make&&make install
编译时的错误(内存不足):
See for instructions.
make[2]: ***[sql/CMakeFiles/sql.dir/item_geofunc_setops.cc.o] 错误 4
make[1]: ***[sql/CMakeFiles/sql.dir/all] 错误 2
make: ***[all] 错误 2
6.添加目录并赋予权限(两台都做)
mkdir -pv /mnt/mysql/{logs,temp}
chown -R mysql.mysql /mnt/mysql
7.初始化数据库(两台都做)
/mnt/mysql/bin/mysql_install_db --initialize-insecure --user=mysql --basedir=/mnt/mysql --datadir=/mnt/mysql/data
ps:--initialize-insecure不生成用户名和密码
8.更改配置文件(两台都做)
cp /mnt/mysql/support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
[client]
port=3306#自行修改端口
socket=/tmp/mysql.sock
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
log-bin-trust-function-creators=1
skip-external-locking
skip-name-resolve
user=mysql
port=3306
basedir=/mnt/mysql
datadir=/mnt/mysql/data
tmpdir=/mnt/mysql/temp
# server_id =.....一般为IP最后一段
server_id=xxx
log_bin=mysql-bin
binlog_format=mixed
socket=/tmp/mysql.sock
log-error=/mnt/mysql/logs/mysql_error.log
pid-file=/mnt/mysql/mysql.pid
open_files_limit=10240
back_log=600
max_connections=500
max_connect_errors=6000
wait_timeout=605800
max_allowed_packet=32M
sort_buffer_size=4M
join_buffer_size=4M
thread_cache_size=300
query_cache_type=1
query_cache_size=256M
query_cache_limit=2M
query_cache_min_res_unit=16k
tmp_table_size=256M
max_heap_table_size=256M
key_buffer_size=256M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
lower_case_table_names=1
default-storage-engine=INNODB
innodb_buffer_pool_size=2G
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_flush_method=O_DIRECT
long_query_time=2
slow-query-log=on
slow-query-log-file=/mnt/mysql/logs/mysql-slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet=32M
[mysqld_safe]
log-error=/mnt/mysql/logs/mysqld.log
pid-file=/mnt/mysql/mysqld.pid
9.将mysql服务注册为linux系统服务:(两台都做)
cp -f /mnt/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
service mysqld stop
service mysqld restart
10.安装目录权限设置(两台都做)
ln -s /mnt/mysql/bin/* /usr/local/bin/
ln -s /mnt/mysql/lib/* /usr/lib/
ln -s /mnt/mysql/include/mysql/* /usr/include/
11.Mysql登录(两台都做)
mysql
自行设置MySQL的root密码
mysql>update mysql.user set authentication_string=password('password') whereuser='root' and Host = 'localhost';
mysql>grant all on *.* to root@'localhost' identified by 'password';
mysql>grant all on *.* to root@'127.0.0.1' identified by 'password';
mysql> exit
service mysqld restart
12.配置master(master)
在my.cnf添加如下
server_id=xxx
log_bin=mysql-bin
binlog_format=mixed
mysql -uroot -p
mysql>grant replication client,replication slave on *.* to 'repl'@'mysql-slave的ip' identified by 'password';
mysql>flush privileges;
mysql> show grants for 'repl'@'mysql-slave的ip';
mysql>flush logs;
mysql> exit
repl用户密码自行设置
13.配置slave(slave)
在my.cnf添加如下
server_id=xxx
relay_log=mysql-relay
mysql -uroot -p
mysql>change master to master_host='mysql-master的ip',master_port=3306,master_user='repl',master_password='repl用户的密码',master_log_file='mysql-bin.000002',master_log_pos=154;
mysql>start slave;
mysql>show slave status\G
网友评论