Linux——MySQL 的 MGR 集群和Redis的编译安装

MGR 集群

环境清理:

===================================
三台机器都做:

修改主机名
修改/etc/hosts
关闭和禁用防火墙
关闭和禁用SELinux
生成密钥对
传输密钥对
验证免密登陆

安装数据库:每个机器都做

mount /dev/sr0 /mnt
yum install mysql-server -y
systemctl start mysqld
systemctl stop mysqld

第一个服务器:(主服务器)

编写配置文件:

cd /etc/my.cnf.d/
vim mysql-server.cnf 

追加内容:

disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"

#server_id确保每个机器不一样  
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON

log_bin=binlog
log_slave_updates=ON
binlog_format=ROW
master_info_repository=TABLE
relay_log_info_repository=TABLE
transaction_write_set_extraction=XXHASH64

plugin_load_add='group_replication.so'

#uuid确保每个机器都一样,可以用uuidgen生成
group_replication_group_name="8e1969ec-3ae3-4bd1-b80f-6de58b837ff5"
group_replication_start_on_boot=off

#当前主机的主机名和复制组端口,建议用主机名
group_replication_local_address= "mgr01:33061"
group_replication_group_seeds= "mgr01:33061,mgr02:33061,mgr03:33061"
group_replication_bootstrap_group=off

配置文件编辑完成

#启动数据库服务

[root@mgr01 ~]# systemctl start mysqld
[root@mgr01 ~]# mysql -uroot -p
mysql> use mysql;

#创建复制组的用户

mysql> SET SQL_LOG_BIN=0;
mysql> CREATE USER rpl_user@'%' IDENTIFIED BY 'Test@1234';
mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
mysql> GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
mysql> FLUSH PRIVILEGES;
mysql> SET SQL_LOG_BIN=1;

#复制用户凭据到复制组通道

mysql> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='Test@1234' FOR CHANNEL 'group_replication_recovery';

#查看复制组插件是否装载

mysql> SHOW PLUGINS;

如果有以下内容则表示已装载
group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL

#启动复制组

mysql> SET GLOBAL group_replication_bootstrap_group=ON;
mysql> START GROUP_REPLICATION USER='rpl_user', PASSWORD='Test@1234';
mysql> SET GLOBAL group_replication_bootstrap_group=OFF;

#查看复制组

mysql> SELECT * FROM performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | a49b5c8f-fd44-11eb-a9e2-000c29707010 | mgr01       |        3306 | ONLINE       | PRIMARY     | 8.0.21         |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
1 row in set (0.00 sec)

上面是第一台服务器的配置

以下是添加第二台的相关配置

#复制第一台服务器的mysql配置

[root@mgr02 ~]# cd /etc/my.cnf.d/
[root@mgr02 my.cnf.d]# rm -rf mysql-server.cnf 
[root@mgr02 my.cnf.d]# scp mgr01:/etc/my.cnf.d/mysql-server.cnf .

只需要编辑以下两个相关配置:

server_id=2
group_replication_local_address= "mgr02:33061"

#启动mysql服务器

[root@mgr02 my.cnf.d]# systemctl start mysqld

#连接服务器

[root@mgr02 my.cnf.d]# mysql -uroot -p

#切换数据库

mysql> use mysql;

#创建复制组用户

SET SQL_LOG_BIN=0;
CREATE USER rpl_user@'%' IDENTIFIED BY 'Test@1234';
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
FLUSH PRIVILEGES;
SET SQL_LOG_BIN=1;

#复制用户凭据到复制组通道

mysql> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='Test@1234' FOR CHANNEL 'group_replication_recovery';

#查看复制组插件是否装载

mysql> SHOW PLUGINS;

如果有以下内容则表示已装载
group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL

#启动复制组

mysql> START GROUP_REPLICATION USER='rpl_user', PASSWORD='Test@1234';

#查看复制组

mysql> SELECT * FROM performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | a49b5c8f-fd44-11eb-a9e2-000c29707010 | mgr01       |        3306 | ONLINE       | PRIMARY     | 8.0.21         |
| group_replication_applier | a9eed5dc-fd44-11eb-aec2-000c29de2f00 | mgr02       |        3306 | ONLINE       | SECONDARY   | 8.0.21         |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
2 rows in set (0.00 sec)

以上是第二台服务器的配置,第三台和第二台服务器的配置是一样的

如果需要停止复制组,则使用:

mysql> stop GROUP_REPLICATION

Redis的编译安装

安装Redis

#解压
[root@kittod opt]# pwd
/opt
[root@kittod opt]# tar xvf redis-6.0.6.tar.gz
#编译
[root@kittod opt]# make
#如果提示没有make命令,先安装make以及gcc环境
[root@kittod redis-6.0.6]# make
-bash: make: command not found
[root@kittod redis-6.0.6]# dnf install make gcc tcl -y
#如果make提示致命错误,请指定分配器为libc
In file included from adlist.c:34:
zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:315: adlist.o] Error 1
make[1]: Leaving directory '/redis-6.0.6/src'
make: *** [Makefile:6: all] Error 2
[root@kittod redis-6.0.6]# make MALLOC=libc
#测试
[root@kittod opt]# make test
#安装
[root@kittod opt]# make install
#启动服务
[root@kittod opt]# cd src/
[root@kittod opt]# ./redis-server
#警告1
#打开文件限制
1672:M 18 Aug 2020 22:04:35.532 * Increased maximum number of open files to
10032 (it was originally set to 1024).
#解决方法
[root@kittod src]# vim /etc/security/limits.conf
root soft nofile 10032
root hard nofile 10032
#警告2
#TCP监听队列
1672:M 18 Aug 2020 22:04:35.533 # WARNING: The TCP backlog setting of 511
cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower
value of 128.
#解决办法
[root@kittod src]# vim /etc/sysctl.conf
net.core.somaxconn= 1024
#警告3
#内存过载
1672:M 18 Aug 2020 22:04:35.533 # WARNING overcommit_memory is set to 0!
Background save may fail under low memory condition.
#解决办法
[root@kittod src]# vim /etc/sysctl.conf
vm.overcommit_memory = 1
#警告4
#大页支持禁用
1672:M 18 Aug 2020 22:04:35.533 # WARNING you have Transparent Huge Pages
(THP) support enabled in your kernel. This will create latency and memory
usage issues with Redis.
#解决办法
[root@kittod src]# vim /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@kittod src]# chmod u+x /etc/rc.d/rc.local

启动服务

[root@kittod ~]# cd /opt/redis-6.0.6/src/
[root@kittod src]# ./redis-server
或者是
[root@kittod ~]# cd /opt/redis-6.0.6/src/
[root@kittod ~ ]# ./redis-server  /root/redis-6.0.6/redis.conf 

务必关闭防火墙或者是使用防火墙策略允许Redis通过

测试使用

[root@kittod src]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> incr mycounter
(integer) 1
127.0.0.1:6379> incr mycounter
(integer) 2
127.0.0.1:6379>

Redis 配置

Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf 可以通过 CONFIG 命令查看或设置配置项。

127.0.0.1:6379> config get *
1) "rdbchecksum"
2) "yes"
1
2
3
编辑配置
你可以通过修改 redis.conf 文件或使用 CONFIG set 命令来修改配置。
Key的数据结构
Redis key值是二进制安全的,这意味着可以用任何二进制序列作为key值,从形如”foo”的简单字符串到
一个JPEG文件的内容都可以。空字符串也是有效key值。
key的操作
exists key
指定的key是否存在。时间复杂度:O(1)。返回整数1则表示结果存在,返回0,则表示不存在。
set key
设置key-value
3) "daemonize"
4) "no"
。。。
259) "notify-keyspace-events"
260) ""
261) "bind"
262) ""
263) "requirepass"
264) ""
127.0.0.1:6379> config get loglevel
1) "loglevel"
2) "notice"

编辑配置

可以通过修改 redis.conf 文件或使用 CONFIG set 命令来修改配置。

127.0.0.1:6379> config get loglevel
1) "loglevel"
2) "notice"
127.0.0.1:6379> config set loglevel "warning"
OK
127.0.0.1:6379> config get loglevel
1) "loglevel"
2) "warning"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值