日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

centos7.2 mysql集群_Centos7.2下安装mysql-group-replication数据库集群

發布時間:2024/9/30 数据库 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos7.2 mysql集群_Centos7.2下安装mysql-group-replication数据库集群 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

系統版本:Centos7.2 x64

數據庫版本:mysql5.7.17

1.首先安裝環境:

yum -y install gcc gcc-c++ libaio-devel boost-devel autoconf automake zlib-devel libxml2-devel ncurses-devel libgcrypt-devel libtool-devel openssl-devel bison-devel unzip numactl-devel

2.關閉selinux和防火墻

setenforce 0

systemctl stop firewalld

systemctl disabled firewalld

3.下載mysql安裝包

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar

解壓:

tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar

tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

將解壓后的文件夾移動到/user/local并且修改為mysql5.7

mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql5.7

配置環境變量

mysql-5.7.17-linux-glibc2.5-x86_64.tar

source /etc/profile

5.創建data目錄和conf文件

進入mysql5.7

mkdir data/3306 data/3307 data/3308

mkdir conf

分別創建3306.cnf 3307.cnf 3308.cnf

6.實例化并且啟動mysql

實例化:

/usr/local/mysql5.7/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql5.7 --datadir=/usr/local/mysql5.7/data/3306

/usr/local/mysql5.7/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql5.7 --datadir=/usr/local/mysql5.7/data/3307

/usr/local/mysql5.7/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql5.7 --datadir=/usr/local/mysql5.7/data/3308

會報一些警告信息:

2018-06-14T03:17:32.915314Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-06-14T03:17:33.980961Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-06-14T03:17:34.192176Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-06-14T03:17:34.256360Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7b29387c-6f81-11e8-abac-00163e06e59d.

2018-06-14T03:17:34.259013Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-06-14T03:17:34.259401Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

分別啟動三個實例:

/usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3306.cnf &

/usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3307.cnf &

/usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3308.cnf &

查看mysql三個實例是否啟動成功

[root@iZm5e7kkxs23uutsa9dbl5Z mysql5.7]# ps -ef | grep mysqld

root 22236 9200 1 11:18 pts/0 00:00:00 /usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3306.cnf

root 22265 9200 2 11:18 pts/0 00:00:00 /usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3307.cnf

root 22294 9200 3 11:18 pts/0 00:00:00 /usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3308.cnf

root 22326 9200 0 11:18 pts/0 00:00:00 grep --color=auto mysqld

說明啟動成功

4.數據庫相關配置

進入3306節點,作為主節點

執行以下操作:

mysql -S /usr/local/mysql5.7/data/3306/mysqld.sock

mysql> set sql_log_bin=0;

Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave,replication client on *.* to 'repluser'@'%' identified by 'replpass';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_user='repluser',master_password='replpass' for channel 'group_replication_recovery';

Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> install plugin group_replication soname 'group_replication.so';

Query OK, 0 rows affected (0.01 sec)

mysql> set global group_replication_bootstrap_group=ON;

Query OK, 0 rows affected (0.00 sec)

mysql> START group_replication;

Query OK, 0 rows affected (1.07 sec)

mysql> set global group_replication_bootstrap_group=OFF;

Query OK, 0 rows affected (0.00 sec)

mysql> exit;

進入3307節點

mysql -S /usr/local/mysql5.7/data/3307/mysqld.sock

mysql> set sql_log_bin=0;

Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave,replication client on *.* to 'repluser'@'%' identified by 'replpass';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> set sql_log_bin=1;

Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_user='repluser',master_password='replpass' for channel 'group_replication_recovery';

Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> install plugin group_replication soname 'group_replication.so';

Query OK, 0 rows affected (0.00 sec)

mysql> START group_replication;

Query OK, 0 rows affected (5.59 sec)

mysql> exit;

進入3308節點:

mysql -S /usr/local/mysql5.7/data/3308/mysqld.sock

mysql> set sql_log_bin=0;

Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave,replication client on *.* to 'repluser'@'%' identified by 'replpass';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> set sql_log_bin=1;

Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_user='repluser',master_password='replpass' for channel 'group_replication_recovery';

Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> install plugin group_replication soname 'group_replication.so';

Query OK, 0 rows affected (0.01 sec)

mysql> start group_replication;

Query OK, 0 rows affected (2.25 sec)

進入三個任意一個節點驗證:

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------------------+-------------+--------------+

| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |

+---------------------------+--------------------------------------+-------------------------+-------------+--------------+

| group_replication_applier | 7b29387c-6f81-11e8-abac-00163e06e59d | iZm5e7kkxs23uutsa9dbl5Z | 3306 | ONLINE |

| group_replication_applier | 8badfa8f-6f81-11e8-aec3-00163e06e59d | iZm5e7kkxs23uutsa9dbl5Z | 3307 | ONLINE |

| group_replication_applier | 90f24e32-6f81-11e8-aef5-00163e06e59d | iZm5e7kkxs23uutsa9dbl5Z | 3308 | ONLINE |

+---------------------------+--------------------------------------+-------------------------+-------------+--------------+

3 rows in set (0.00 sec)

5.數據同步測試

進入到3306節點

mysql> create table tb_stu(id int not null primary key auto_increment,name varchar(50));

Query OK, 0 rows affected (0.02 sec)

mysql> select * from tb_stu;

+----+------+

| id | name |

+----+------+

| 1 | tom |

+----+------+

1 row in set (0.00 sec)

進入3307節點:

mysql> select * from tb_stu;

+----+------+

| id | name |

+----+------+

| 1 | tom |

+----+------+

1 row in set (0.00 sec)

同樣進入3308節點驗證:

mysql> select * from tb_stu;

+----+------+

| id | name |

+----+------+

| 1 | tom |

+----+------+

1 row in set (0.00 sec)

說明三個節點能夠進行數據同步。

加入我們在3307或者3308節點插入數據:

mysql> insert tb_stu(id,name) values (1,'tom');

ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement

報錯原因是:3306是主節點,3307和3308是從節點,單主模式下只能在主節點寫入,從節點只能查詢數據。

下面我們在進行多主節點修改和增加節點。

轉載至鏈接:https://my.oschina.net/u/2477500/blog/1830407

總結

以上是生活随笔為你收集整理的centos7.2 mysql集群_Centos7.2下安装mysql-group-replication数据库集群的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。