数据库
数据库主要分为两大类:关系型数据库与 NoSQL 数据库
关系型数据库,是建立在关系模型基础上的数据库,其借助于集合代数等数学概念和方法来处理数据库 中的数据主流的 MySQL、Oracle、MS SQL Server 和 DB2 都属于这类传统数据库。
NoSQL 数据库,全称为 Not Only SQL,意思就是适用关系型数据库的时候就使用关系型数据库,不适 用的时候也没有必要非使用关系型数据库不可,可以考虑使用更加合适的数据存储。主要分为临时性键 值存储(memcached、Redis)、永久性键值存储(ROMA、Redis)、面向文档的数据库 (MongoDB、CouchDB)、面向列的数据库(Cassandra、HBase),每种 NoSQL 都有其特有的使用 场景及优点
一、MySQL
bash
#安装依赖(rhel7版本) rhel9中还需要rpcgen.x86_64
yum install cmake gcc-c++ openssl-devel ncurses-devel.x86_64 libtirpc-devel-1.3.3-8.el7_4.x86_64.rpm
#下载源码安装包后解压
tar zxf mysql-boost-5.7.44.tar.gz
du -sh mysql-5.7.44/ #查看文件大小
cd /root/mysql-5.7.44
#源码编译,当cmake出错后如果想重新检测,删除 mysql-5.7.44 中 CMakeCache.txt即可
rm -fr CMakeCache.txt #make出错后使用
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定安装路径
-DMYSQL_DATADIR=/data/mysql \ #指定数据目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ #指定套接字文件
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #指定启用INNODB存储引擎,默认用myisam
-DWITH_EXTRA_CHARSETS=all \ #扩展字符集
-DDEFAULT_CHARSET=utf8mb4 \ #指定默认字符集
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \ #指定默认校验字符集
-DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/
#安装mysql
make -j2 #-j2 表示有几个核心就跑几个进程
make install
#生成启动脚本
yum install initscripts -y
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
#修改环境变量
vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
source ~/.bash_profile
#生成数据目录
useradd -s /sbin/nologin -M mysql
mkdir -p /data/mysql
chown mysql.mysql /data/mysql/
#修改配置文件
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql #指定数据目录
socket=/data/mysql/mysql.sock #指定套接字
symbolic-links=0 #数据只能存放到数据目录中,禁止链接到数据目录
#数据库初始化建立mysql基本数据
mysqld --initialize --user=mysql
/etc/init.d/mysqld start #启动mysql
chkconfig --list #查看系统默认启动级别
chkconfig mysqld on #开机启动
#数据库安全初始化
mysql_secure_installation #一般情况下前两个选no,后面选yes
#数据库环境出现问题时
rm -fr /data/mysql/*
mysqld --user mysql --initialize #重新初始化
#可以将配置好的文件传输到另一台主机上
Cd /usr/local/
rsync -al -r mysql root@172.25.254.10:/usr/local/
组从复制
bash
#写入大于读取,主多;读取大于写入,从多
#配置master
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin #仅master上开启
server-id=20
/etc/init.d/mysqld restart
mysql -uroot -e "select @@server_id"-p #查看mysql的编号
cd /data/mysql/
mysqlbinlog mysql-bin.000001 -vv ##查看二进制日志
#配置slave1
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=10
/etc/init.d/mysqld restart
#配置slave2
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=30
/etc/init.d/mysqld restart
sql
CREATE USER 'wyh'@'%' IDENTIFIED BY '123'; ##生成专门用来做复制的用户,此用户是用于slave端做认证用
GRANT REPLICATION SLAVE ON *.* TO repl@'%'; ##对这个用户进行授权
SHOW MASTER STATUS; ##查看master的状态
#slave上的配置
CHANGE MASTER TO MASTER_HOST='172.25.254.10',MASTER_USER='wyh',MASTER_PASSWORD='123',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=350;
start slave;
SHOW SLAVE STATUS\G;
从机
延时复制(slave端操作)
慢查询
并行复制
半同步模式
开启gtid强制同步
mysql高可用之组复制(MGR)
bash
rm-fr /data/mysql/*
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=10 #配置server唯一标识号
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY" #禁用指定存储引擎
gtid_mode=ON #启用全局事件标识
enforce_gtid_consistency=ON #强制gtid一致
master_info_repository=TABLE #复制事件数据到表中而不记录在数据目录中
relay_log_info_repository=TABLE
binlog_checksum=NONE #禁止对二进制日志校验
log_slave_updates=ON #打开数据库中继,当slave中sql线程读取日志后也会写入到自己的binlog中
log_bin=binlog #重新指定log名称
binlog_format=ROW #使用行日志格式
plugin_load_add='group_replication.so' #加载组复制插件
transaction_write_set_extraction=XXHASH64 #把每个事件编码为加密散列
group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" #通知插件正式加入,或创建的组名,名称为uuid格式
group_replication_start_on_boot=off #在server启动时不自动启动组复制
group_replication_local_address="172.25.254.10:33061" #指定插件接受其他成员的信息端口
group_replication_group_seeds="172.25.254.10:33061,172.25.254.20:33061,172.25.254.30:33061" #本地地址允许访问成员列表
group_replication_ip_whitelist="172.25.254.0/24,127.0.0.1/8" #主机白名单;不随系统自启而启动,只在初始成员主机中手动开启;需要在两种情况下做设定:1.初始化建组时 2.关闭并重新启动整个组时
group_replication_bootstrap_group=off
group_replication_single_primary_mode=OFF #使用多主模式
group_replication_enforce_update_everywhere_checks=ON #组同步中有任何改变检测更新
group_replication_allow_local_disjoint_gtids_join=1 #放弃自己信息以master事件为主
mysqld user=mysql --initialize
/etc/init.d/mysqld start
slave主机上修改my.cnf
每一台主机上都添加地址解析
sql
#进入数据库配置
mysql> SET SQL_LOG_BIN=0; #关闭日志
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER w@'%' IDENTIFIED BY '123'; #创建新用户
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT REPLICATION SLAVE ON *.* TO w@'%'; #赋予权限
Query OK, 0 rows affected (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='w', MASTER_PASSWORD='123' FOR CHANNEL
'group_replication_recovery'; #加入组
Query OK, 0 rows affected, 2 warnings (0.00 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 warning (2.19 sec)
mysql> SET GLOBAL group_replication_bootstrap_group=OFF;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM performance_schema.replication_group_members; #查看组信息
#组复制中建表必须有主键标识,防止数据重复
#某一台机器下线后只能手动开启
mysql路由
bash
rpm -ivh mysql-router-community-8.4.0-1.el7.x86_64.rpm
rpm -ql mysql-router-community #查看所有文件
vim /etc/mysqlrouter/mysqlrouter.conf
[routing:ro]
bind_address=0.0.0.0
bind_port=7001
destinations=172.25.254.20:3306,172.25.254.30:3306
routing_strategy=round-robin #轮询算法
#routing_strategy = first-available #先响应
systemctl start mysqlrouter.service
/etc/init.d/mysqld stop
MHA(需要在rhel7版本下进行实验)
bash
#将数据库为一主两从模式,清除之前的实验痕迹
[root@mysql1 ~]# /etc/init.d/mysqld stop
[root@mysql1 ~]# rm -fr /data/mysql/*
[root@mysql1 ~]# ps aux | grep mysql
mysqlro+ 28247 0.0 0.3 520980 12496 ? Ssl 19:48 0:00 /usr/bin/mysqlrouter
root 28570 0.0 0.0 113416 1600 pts/0 S 20:20 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql1.timinglee.org.pid
mysql 28963 0.5 5.5 1658680 213840 pts/0 Sl 20:20 0:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql1.timinglee.org.err --pid-file=/data/mysql/mysql1.timinglee.org.pid --socket=/data/mysql/mysql.sock
root 29084 0.0 0.0 112824 980 pts/0 S+ 20:29 0:00 grep --color=auto mysql
[root@mysql1 ~]# kill -9 28247
[root@mysql1 ~]# kill -9 28570
[root@mysql1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
server-id=10
log-bin=mysql-bin
gtid_mode=ON
log_slave_updates=ON
enforce-gtid-consistency=ON
symbolic-links=0
[root@mysql1 ~]# mysqld --user mysql --initialize
[root@mysql1 ~]# /etc/init.d/mysqld start
[root@mysql1 ~]# mysql_secure_installation
#master中配置
[root@mysql1 ~]# mysql -uroot -p
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY '123';
mysql> GRANT REPLICATION SLAVE ON *.* TO repl@'%';
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;
mysql> create user root@'%' identified by '123';
mysql> grant all on *.* to root@'%';
#slave中配置
mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.10',MASTER_USER='repl',MASTER_PASSWORD='123', MASTER_AUTO_POSITION=1;
mysql> start slave;
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
mysql> SET GLOBAL rpl_semi_sync_slave_enabled =1;
mysql> STOP SLAVE IO_THREAD;
mysql> START SLAVE IO_THREAD;
mysql> SHOW STATUS LIKE 'Rpl_semi_sync%';
bash
unzip MHA-7.zip
cd MHA-7/
yum install *.rpm -y #安装需要软件
#将节点所需软件传输
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172 .25.254.10:/root
mha4mysql-node-0.58-0.el7.centos.noarch.rpm 100% 35KB 4.0MB/s 00:00
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172 .25.254.20:/root
mha4mysql-node-0.58-0.el7.centos.noarch.rpm 100% 35KB 14.0MB/s 00:00
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172 .25.254.30:/root
mha4mysql-node-0.58-0.el7.centos.noarch.rpm 100% 35KB 4.9MB/s 00:00
#vim /etc/ssh/sshd_config
#systemctl restart sshd #传输速度慢时可以修改其中的DNS
#在节点处安装软件
yum install mha4mysql-node-0.58-0.el7.centos.noarch.rpm
tar zxf mha4mysql-manager-0.58.tar.gz -C /etc/masterha
cd mha4mysql-manager-0.58/samples/conf/
[root@mysql-mha conf]# ls
app1.cnf masterha_default.cnf
[root@mysql-mha conf]# cat masterha_default.cnf app1.cnf > /etc/masterha/app1.cnf
[root@mysql-mha conf]# cd /etc/masterha/
[root@mysql-mha masterha]# vim app1.cnf
#免密认证
[root@mysql-mha ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #直接回车
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): #直接回车
Enter same passphrase again: #直接回车
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0oVq2T4RO7u8XCfvsIeyQ3rtSDwqQ3BjuUpWcO00aZQ root@mysql-mha.timinglee.org
The key's randomart image is:
+---[RSA 2048]----+
| o.o |
| . . E . |
| o = .o . |
| . * .= + |
| = o= S |
| o o. +.+ |
| o o oB.+.. |
| . o .=+*o*. |
| o..B*ooo |
+----[SHA256]-----+
[root@mysql-mha ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.10
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.10 (172.25.254.10)' can't be established.
ECDSA key fingerprint is SHA256:I/mAOn2BwkS3J9C80hAyJ8Bc9RBFMgCnaIq7JNJr2Cs.
ECDSA key fingerprint is MD5:ce:93:6e:55:45:d5:1e:62:a3:a5:eb:4b:bd:f5:67:12.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.254.10's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.10'"
and check to make sure that only the key(s) you wanted were added.
[root@mysql-mha ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.20 (172.25.254.20)' can't be established.
ECDSA key fingerprint is SHA256:I/mAOn2BwkS3J9C80hAyJ8Bc9RBFMgCnaIq7JNJr2Cs.
ECDSA key fingerprint is MD5:ce:93:6e:55:45:d5:1e:62:a3:a5:eb:4b:bd:f5:67:12.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.254.20's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.20'"
and check to make sure that only the key(s) you wanted were added.
[root@mysql-mha ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.30
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.30 (172.25.254.30)' can't be established.
ECDSA key fingerprint is SHA256:I/mAOn2BwkS3J9C80hAyJ8Bc9RBFMgCnaIq7JNJr2Cs.
ECDSA key fingerprint is MD5:ce:93:6e:55:45:d5:1e:62:a3:a5:eb:4b:bd:f5:67:12.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.254.30's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.30'"
and check to make sure that only the key(s) you wanted were added.
#地址解析
[root@mysql-mha ~]# vim /etc/hosts
测试是否能顺利登录
masterha_check_ssh --conf=/etc/masterha/app1.cnf #检测网络及ssh免密
masterha_check_repl --conf=/etc/masterha/app1.cnf #检测数据主从复制情况
MHA的故障切换
bash
#手动切换
#在master数据节点还在正常工作情况下
[root@mysql-mha ~]# masterha_master_switch \
--conf=/etc/masterha/app1.cnf \ #指定配置文件
--master_state=alive \ #指定master节点状态
--new_master_host=172.25.254.20 \ #指定新master节点
--new_master_port=3306 \ #执行新master节点端口
--orig_master_is_new_slave \ #原始master会变成新的slave
--running_updates_limit=10000 #切换的超时时间
#模拟master故障
[root@mysql2 mysql]# /etc/init.d/mysqld stop
#在MHA-master中做故障切换
[root@mysql-mha masterha]# masterha_master_switch --master_state=dead --
conf=/etc/masterha/app1.cnf --dead_master_host=192.168.56.12 --
dead_master_port=3306 --new_master_host=192.168.56.11 --new_master_port=3306 --
ignore_last_failover \
--ignore_last_failover 表示忽略在/etc/masterha/目录中在切换过程中生成的锁文件
#master恢复
/etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@mysql2 ~]# mysql -p
mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.10', MASTER_USER='repl',
MASTER_PASSWORD='lee', MASTER_AUTO_POSITION=1;
mysql> show slave\G
#测试一主两从是否正常
[root@mysql-mha masterha]# masterha_check_repl --conf=/etc/masterha/app1.cnf
#自动切换
rm -fr app1.failover.complete #删掉切换锁文件
#监控程序通过指定配置文件监控master状态,当master出问题后自动切换并退出避免重复做故障切换
[root@mysql-mha masterha]# masterha_manager --conf=/etc/masterha/app1.cnf
[root@mysql-mha masterha]# cat /etc/masterha/manager.log
#恢复故障节点
[root@mysql2 mysql]# /etc/init.d/mysqld start
mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.10', MASTER_USER='repl',
MASTER_PASSWORD='123', MASTER_AUTO_POSITION=1
[root@mysql-mha masterha]# rm -rf app1.failover.complete manager.log
MHA添加vip
bash
[root@mysql-mha ~]# ls
master_ip_failover master_ip_online_change MHA-7 MHA-7.zip
[root@mysql-mha ~]# cp master_ip_failover master_ip_online_change /usr/local/bin/
[root@mysql-mha ~]# chmod +x /usr/local/bin/master_ip_*
#修改脚本中vip
[root@mysql-mha ~]# vim /usr/local/bin/master_ip_failover
my $vip = '172.25.254.100/24';
my $ssh_start_vip = "/sbin/ip addr add $vip dev eth0";
my $ssh_stop_vip = "/sbin/ip addr del $vip dev eth0";
[root@mysql-mha ~]# vim /usr/local/bin/master_ip_online_change
my $vip = '172.25.254.100/24';
my $ssh_start_vip = "/sbin/ip addr add $vip dev eth0";
my $ssh_stop_vip = "/sbin/ip addr del $vip dev eth0";
my $exit_code = 0;
[root@mysql-mha masterha]# masterha_manager --conf=/etc/masterha/app1.cnf & 启动监控程序
[root@mysql-node10 tmp]# ip a a 172.25.254.100/24 dev eth0 #在master节点添加VIP
#模拟故障
[root@mysql-node10 ~]# /etc/init.d/mysqld stop #关闭主节点服务
[root@mysql-mha masterha]# cat manager.log
#恢复故障主机
[root@mysql2 mysql]# /etc/init.d/mysqld start
mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.10', MASTER_USER='repl',
MASTER_PASSWORD='123', MASTER_AUTO_POSITION=1
[root@mysql-mha masterha]# rm -rf app1.failover.complete manager.log
#手动切换后查看vip变化
[root@mysql-mha masterha]# masterha_master_switch --conf=/etc/masterha/app1.cnf
--master_state=alive --new_master_host=172.25.254.10 --new_master_port=3306 --
orig_master_is_new_slave --running_updates_limit=10000
二、redis
Redis特性:
速度快: 10W QPS,基于内存,C语言实现;单线程;持久化;支持多种数据结构;支持多种编程语言;功能丰富: 支持Lua脚本,发布订阅,事务,pipeline等功能 简单: 代码短小精悍(单机核心代码只有23000行左右),单线程开发容易,不依赖外部库,使用简单;主从复制 支持高可用和分布式
单线程为何如此快?
纯内存;非阻塞;避免线程切换和竞态消耗
Redis应用场景
Session 共享:常见于web集群中的Tomcat或者PHP中多web服务器session共享
缓存:数据查询、电商网站商品信息、新闻内容
计数器:访问排行榜、商品浏览数等和次数相关的数值统计场景
微博/微信社交场合:共同好友,粉丝数,关注,点赞评论等
消息队列:ELK的日志缓存、部分业务的订阅发布系统
地理位置: 基于GEO(地理信息定位),实现摇一摇,附近的人,外卖等功能
bash
tar zxf redis-7.4.0.tar.gz #解压安装包
dnf install gcc make initscripts -y #安装依赖
cd redis-7.4.0/
make && make install #安装
cd utils/
vim install_server.sh #编辑启动模式
./install_server.sh
vim /etc/redis/6379.conf 编辑配置文件
/etc/init.d/redis_6379 start #启动服务
/etc/init.d/redis_6379 restart
redis-cli #进入数据库
instll_server.sh上的修改
配置文件上的修改
redis基本操作
主从复制
slave配置文件上的修改
哨兵
bash
#在master节点中
[root@redis-node1 ~]# cd redis-7.4.0/
[root@redis-node1 redis-7.4.0]# cp sentinel.conf /etc/redis/
[root@redis-node1 redis-7.4.0]# vim /etc/redis/sentinel.conf
protected-mode no #关闭保护模式
port 26379 #监听端口
daemonize no #前台运行
pidfile /var/run/redis-sentinel.pid #sentinel进程pid文件
loglevel notice #日志级别
sentinel monitor mymaster 172.25.254.10 6379 2 #创建sentinel监控监控master主机,2表示必须得到2票
sentinel down-after-milliseconds mymaster 10000 #master中断时长,10秒连不上视为master下线
sentinel parallel-syncs mymaster 1 #发生故障转移后,同时开始同步新
master数据的slave数量
sentinel failover-timeout mymaster 180000 #整个故障切换的超时时间为3分钟
#复制配置文件到其他节点
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.254.20:/etc/redis/sentinel.conf
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf
root@172.25.254.30:/etc/redis/sentinel.conf
#每一个节点都需要备份配置文件
cd /etc/redis
cp sentinel.conf sentinel.conf_bak
2 启动服务
[root@redis-node1 redis-7.4.0]# redis-sentinel /etc/redis/sentinel.conf
redis cluster集群
bash
#删除源码编译的redis
cd /root/redis-7.4.0/
make uninstall
/etc/init.d/redis_6379 start
/etc/init.d/redis_6379 stop
killall -9 redis-server
#安装redis并配置集群
yum install redis -y
vim /etc/redis/redis.conf
bind * -::*
masterauth "123456" #集群主从认证
requirepass "123456" #redis登陆密码 redis-cli 命令连接redis后要用"auth 密码"进行认证
cluster-enabled yes #开启cluster集群功能
cluster-config-file nodes-6379.conf #指定集群配置文件
cluster-node-timeout 15000 #节点加入集群的超时时间单位是ms
systemctl restart redis.service
netstat -antlupe | grep redis
[root@redis1 ~]# redis-cli
127.0.0.1:6379> auth 123456
redis-cli --cluster create -a 123456 172.25.254.10:6379 172.25.254.20:6379 172.25.254.30:6379 172.25.254.110:6379 172.25.254.120:6379 172.25.254.130:6379 --cluster-replicas 1
redis-cli -a 123456 --cluster check 172.25.254.10:6379
#参数说明
127.0.0.1:6379> redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN #创建集群
--cluster-replicas <arg> #指定master的副本数
check <host:port> or <host> <port> #检测集群信息
info <host:port> or <host> <port> #查看集群信息
fix <host:port> or <host> <port> #修复集群
reshard <host:port> or <host> <port> #在线热迁移集群指定主机的slots数据
rebalance <host:port> or <host> <port> #平衡各集群主机的slot数量
add-node new_host:new_port existing_host:existing_port #添加主机
del-node host:port node_id #删除主机
import host:port #导入外部redis服务器的数据到当前集群
创建集群
集群检测
集群扩容