Centos7 + mysql5.6主从配置搭建

来源:互联网 发布:酒店网络部署方案 编辑:程序博客网 时间:2024/05/19 13:42

Centos7将默认数据库mysql替换成了Mariadb,得把它给卡卡掉。

本安装的架构信息:

10.70.27.12:3306 master
10.70.27.10:3306 slave


第一章:安装MySQL5.6

1、下载安装包  mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz, 可前往官网自行下载:http://dev.mysql.com/downloads/mysql/

# cd /data/tools; wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz

2、卸载系统自带的Mariadb

打开Terminal终端:

[plain] view plain copy
  1. # rpm -qa|grep mariadb  // 查询出来已安装的mariadb  
  2. # rpm -e --nodeps 文件名  // 卸载mariadb,文件名为上述命令查询出来的文件  

3、删除etc目录下的my.cnf

[plain] view plain copy
  1. # rm /etc/my.cnf  

4、执行以下命令来创建mysql用户组

[plain] view plain copy
  1. # groupadd mysql  

5、执行以下命令来创建一个用户名为mysql的用户并加入mysql用户组

[plain] view plain copy
  1. # useradd -g mysql mysql  

6、解压安装包

[plain] view plain copy
  1. # tar -zxvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz;

7、将解压好的文件夹重命名为mysql-5.6.38

[plain] view plain copy
  1. # mkdir -p /data/mysql-5.6.38; mv mysql-5.6.38-linux-glibc2.12-x86_64/* /data/mysql-5.6.38/; cd /data/mysql-5.6.38

8、在 /etc 下新建配置文件my.cnf 

[plain] view plain copy
  1. # cp support-files/my-default.cnf /etc/my.cnf

然后,配置/etc/my.cnf文件

master mysql的 my.cnf内容如下:


[plain] view plain copy
  1. # vim /etc/my.cnf  

[plain] view plain copy
  1. [mysqld]
    #master DB
    sync_binlog=1
    log_bin=/data/mysql/mysql-bin-log
    server-id=12
    binlog-ignore-db=information_schema
    binlog-ignore-db=cluster
    binlog-ignore-db=mysql
    binlog-do-db=test
    expire-logs-days  = 7
    #master DB ends
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    datadir=/data/mysql/data
    basedir=/data/mysql-5.6.38
    socket=/var/lib/mysql/mysql.sock
    open_files_limit  = 10240
    back_log = 600 # 256K per link
    max_connections = 3000 #
    max_connect_errors = 6000
    thread_concurrency = 32 #cpu * 2
    sort_buffer_size = 4M
    join_buffer_size = 256M
    read_rnd_buffer_size = 4M
    thread_cache_size = 300
    query_cache_size = 256M
    query_cache_limit = 40M
    tmp_table_size = 256M
    binlog_cache_size = 4M
    max_binlog_cache_size = 8M
    max_binlog_size = 512M
    expire_logs_days = 7
    key_buffer_size = 2048M
    innodb_buffer_pool_size = 4096M
    bulk_insert_buffer_size = 64M
    innodb_file_io_threads = 8
    innodb_thread_concurrency =  16
    innodb_log_buffer_size = 16M

slave mysql的 my.cnf内容如下:

[plain] view plain copy
  1. # vim /etc/my.cnf  

[plain] view plain copy

  1. [mysqld]
    # for slave DB
    server-id=10
    relay_log=/data/mysql/mysql-relay-log
    log_bin=/data/mysql/mysql-bin-log
    read_only
    skip_slave_start
    binlog-ignore-db=information_schema
    binlog-ignore-db=cluster
    binlog-ignore-db=mysql
    replicate-do-db=test
    replicate-ignore-db=mysql
    log-slave-updates
    slave-skip-errors=all
    slave-net-timeout=60
    # slave DB ends
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    datadir=/data/mysql/data
    basedir=/data/mysql-5.6.38
    socket=/var/lib/mysql/mysql.sock
    open_files_limit  = 10240
    back_log = 600 # 256K per link
    max_connections = 3000 #
    max_connect_errors = 6000
    thread_concurrency = 32 #cpu * 2
    sort_buffer_size = 4M
    join_buffer_size = 256M
    read_rnd_buffer_size = 4M
    thread_cache_size = 300
    query_cache_size = 256M
    query_cache_limit = 40M
    tmp_table_size = 256M
    binlog_cache_size = 4M
    max_binlog_cache_size = 8M
    max_binlog_size = 512M
    expire_logs_days = 7
    key_buffer_size = 2048M
    innodb_buffer_pool_size = 4096M
    bulk_insert_buffer_size = 64M
    innodb_file_io_threads = 8
    innodb_thread_concurrency =  16
    innodb_log_buffer_size = 16M
    innodb_log_file_size = 256M
    innodb_log_files_in_group = 3
    innodb_flush_log_at_trx_commit = 2
    innodb_data_file_path = ibdata1:1024M:autoextend
    innodb_lock_wait_timeout = 120
    thread_stack = 2048K
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links = 0
    sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    character-set-server=utf8
    [mysqld_safe]
    log-error = /data/mysql/log/mysqld.log
    pid-file = /var/run/mysqld/mysqld.pid

10.进入安装mysql软件目录

[plain] view plain copy
  1. # cd /data/mysql-5.6.38  
  2. # chown -R mysql:mysql ./ 
  3. chown -R mysql:mysql /data/mysql
  4. # ./scripts/mysql_install_db --user=mysql --basedir=/data/mysql-5.6.38/ --datadir=/data/mysql/data/    

注:若执行以上最后一个命令出现以下问题:

[plain] view plain copy
  1. FATAL ERROR: please install the following Perl modules before executing   
  2. ./scripts/mysql_install_db:Data::Dumper  

解决方法 :安装autoconf库

[plain] view plain copy
  1. 命令: yum -y install autoconf   //此包安装时会安装Data:Dumper模块  
  2. 安装完成重新执行上述最后一个命令  

到此数据库安装完毕!

 

第二章、配置单个MySQL

1、授予my.cnf最大权限

[plain] view plain copy
  1. # chown 777 /etc/my.cnf  

设置开机自启动服务控制脚本:

2、复制启动脚本到资源目录

[plain] view plain copy
  1. # cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld  

3、增加mysqld服务控制脚本执行权限

[plain] view plain copy
  1. # chmod +x /etc/rc.d/init.d/mysqld  

4、将mysqld服务加入到系统服务

[plain] view plain copy
  1. # chkconfig --add mysqld  

5、检查mysqld服务是否已经生效

[plain] view plain copy
  1. # chkconfig --list mysqld  

命令输出类似下面的结果:

[plain] view plain copy
  1. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off  

表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制mysql的启动和停止

[plain] view plain copy
  1. 命令为:service mysqld start和service mysqld stop  

6、启动mysqld

[plain] view plain copy
  1. # service mysqld start  

7、将mysql的bin目录加入PATH环境变量,编辑 ~/.bash_profile文件

[plain] view plain copy
  1. # vim ~/.bash_profile  

在文件最后添加如下信息:

[plain] view plain copy
  1. export PATH=$PATH:/data/mysql-5.6.38/bin

然后按ESC键

继续 shift键加冒号打出来=>  :

接下来输入wq回车即可

执行下面的命令是修改的内容立即生效:

[plain] view plain copy
  1. # source ~/.bash_profile  

8、以root账户登录mysql,默认是没有密码的

[plain] view plain copy
  1. # mysql -uroot -p  

要输入密码的时候直接回车即可。

9、设置root账户密码为root(也可以修改成你要的密码)

[plain] view plain copy
  1. mysql>use mysql;  
  2. mysql>update user set password=password('root') where user='root' and host='localhost';  
  3. mysql>flush privileges;  

10、设置远程主机登录,注意下面的your username 和 your password改成你需要设置的用户和密码

[plain] view plain copy
  1. mysql>GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password' WITH  
  2. GRANT OPTION;  

到此,在Centos 7上安装mysql5.6就完成了。在主和从两条服务器都按这个步骤启动mysql.

 第三章: 主从mysql的搭建

上面只是完成了两条mysql的安装,但是把它们组成master/slave结构,并能自动复制,还需要做如下的配置。



阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 木质门 木质部 木质吊顶 木质花箱 木质肥皂盒 木质耳饰 木质船模型 木质北欧装修效果图 钢木质防火门 木质地板怎么铺 木质画框批发 木质踢脚线多少钱一米 木通 木遁 木遁造福综英美 海贼世界的木遁使用者 那木子 木那雪花棉 木那 木那雪花棉翡翠图片 婚后木采 木采作品 离婚以后by木采 婚后by木采 婚后 木采 采木园实木家具 嫁给贺先生 木采 离婚以后 木采 木里 荒木里菜 木里县 木里苏 木里木外 木里火灾 木里在哪里 木里路况 木里宾馆 木里火灾牺牲英雄 四川木里县森林火灾 睡在古木里蛇妻美人 木里求丝称雄记