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


    MGR 集群

    环境清理:

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

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

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

    mount /dev/sr0 /mnt
    yum install mysql-server -y
    systemctl start mysqld
    systemctl stop mysqld
    
    • 1
    • 2
    • 3
    • 4

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

    编写配置文件:

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    配置文件编辑完成

    #启动数据库服务

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

    #创建复制组的用户

    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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

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

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

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

    mysql> SHOW PLUGINS;
    
    • 1

    如果有以下内容则表示已装载
    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;
    
    • 1
    • 2
    • 3

    #查看复制组

    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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

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

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

    #复制第一台服务器的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 .
    
    • 1
    • 2
    • 3

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

    server_id=2
    group_replication_local_address= "mgr02:33061"
    
    • 1
    • 2

    #启动mysql服务器

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

    #连接服务器

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

    #切换数据库

    mysql> use mysql;
    
    • 1

    #创建复制组用户

    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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

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

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

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

    mysql> SHOW PLUGINS;
    
    • 1

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

    #启动复制组

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

    #查看复制组

    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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

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

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

    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 
    ^~~~~~~~~~~~~~~~~~~~~
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59

    启动服务

    [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 
    
    • 1
    • 2
    • 3
    • 4
    • 5

    务必关闭防火墙或者是使用防火墙策略允许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>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    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"
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    编辑配置

    可以通过修改 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"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    操作系统(一)概述&基本组成&运行机制
    springBoot整合rabbitMQ,通过注册bean的方式创建exchange,queue,容器中成功注入,但rabbitserver中不显示
    Istio微服务治理网格流量管理核心资源控制器详解
    MongoDB导入导出备份数据
    ubuntu20.04 nerf开山之作
    大数据学习(10)-Explain详解
    CPU vs GPU 的区别详解
    2023如何做谷歌收录?
    【java期末复习题】第1章 Java 程序设计语言概述
    问遍了身边的面试官朋友,我整理出这份 Java 集合高频面试题(2021年最新版)
  • 原文地址:https://blog.csdn.net/qq_53715074/article/details/126256680