文档课题:rhel 7.3搭建redis-6.2.5采用级联复制搭建一主两从.
架构介绍:
1、单实例安装
1.1、redis依赖包
说明:redis是基于C语言编写的,因此首先需要安装redis的gcc等依赖包.
[root@redis-leo-master ~]# mkdir /etc/yum.repos.d/bak
[root@redis-leo-master ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
[root@redis-leo-master ~]# mount /dev/sr0 /mnt
[root@redis-leo-master ~]# cat >/etc/yum.repos.d/rhel7.repo
[rhel7]
name=rhel7
baseurl=file:///mnt
enable=1
gpgcheck=0
EOF
[root@redis-leo-master ~]# yum makecache
[root@redis-leo-master ~]# yum -y install gcc tcl
……
Installed:
gcc.x86_64 0:4.8.5-44.el7 tcl.x86_64 1:8.5.13-8.el7
Dependency Installed:
cpp.x86_64 0:4.8.5-44.el7 glibc-devel.x86_64 0:2.17-317.el7 glibc-headers.x86_64 0:2.17-317.el7 kernel-headers.x86_64 0:3.10.0-1160.el7
Complete!
1.2、安装包处理
--上传安装包.
将安装包redis-6.2.5.tar.gz上传到/home/redis目录.
[root@redis-leo-master ~]# useradd redis
[root@redis-leo-master ~]# echo "redis" | passwd redis --stdin
[root@redis-leo-master ~]# mkdir -p /opt/redis
[root@redis-leo-master ~]# chown -R redis:redis /opt/redis
sftp> cd /home/redis
sftp> lcd F:installmediumredis
sftp> put redis-6.2.5.tar.gz
--解压安装包.
[root@redis-leo-master ~]# cd /home/redis
[root@redis-leo-master redis]# chown redis:redis redis-6.2.5.tar.gz
[root@redis-leo-master redis]# su - redis
[redis@redis-leo-master ~]$ tar -zxf redis-6.2.5.tar.gz
1.3、安装redis
--编译以及安装redis
[redis@redis-leo-master ~]$ cd redis-6.2.5
[redis@redis-leo-master redis-6.2.5]$ make
[redis@redis-leo-master redis-6.2.5]$ cd src
[redis@redis-leo-master src]$ make install PREFIX=/opt/redis
[redis@redis-leo-master src]$ cd ..
[redis@redis-leo-master redis-6.2.5]$ cp /home/redis/redis-6.2.5/redis.conf /opt/redis/bin/
[redis@redis-leo-master redis-6.2.5]$ ll /opt/redis/bin
total 18968
-rwxr-xr-x. 1 redis redis 4828480 Oct 12 22:06 redis-benchmark
lrwxrwxrwx. 1 redis redis 12 Oct 12 22:06 redis-check-aof -> redis-server
lrwxrwxrwx. 1 redis redis 12 Oct 12 22:06 redis-check-rdb -> redis-server
-rwxr-xr-x. 1 redis redis 5002160 Oct 12 22:06 redis-cli
-rw-rw-r--. 1 redis redis 93724 Oct 12 22:09 redis.conf
lrwxrwxrwx. 1 redis redis 12 Oct 12 22:06 redis-sentinel -> redis-server
-rwxr-xr-x. 1 redis redis 9492376 Oct 12 22:06 redis-server
说明:该目录默认配置到环境变量,因此可以在任意目录下运行如下命令:
Redis-cli:redis提供的命令客户端
Redis-server:redis的服务端启动脚本
Redis-sentinel:redis的哨兵启动脚本
1.4、测试验证
[redis@redis-leo-master redis-6.2.5]$ cd /opt/redis/bin
[redis@redis-leo-master bin]$ ./redis-server &
--查看redis进程.
[redis@redis-leo-master bin]$ ps -ef|grep redis
avahi 832 1 0 21:05 ? 00:00:00 avahi-daemon: running [redis-leo-master.local]
root 36411 36283 0 21:59 pts/0 00:00:00 su - redis
redis 36412 36411 0 21:59 pts/0 00:00:00 -bash
redis 41085 36412 0 22:11 pts/0 00:00:00 ./redis-server *:6379
redis 41090 36412 0 22:11 pts/0 00:00:00 ps -ef
redis 41091 36412 0 22:11 pts/0 00:00:00 grep --color=auto redis
[redis@redis-leo-master bin]$ ./redis-cli
127.0.0.1:6379> info server
# Server
redis_version:6.2.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:db59541138fdc0ed
redis_mode:standalone
os:Linux 3.10.0-514.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:41085
process_supervised:no
run_id:312f6d73fdb19ef5baf1077915cc449aace44c15
tcp_port:6379
server_time_usec:1697119967485766
uptime_in_seconds:69
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:2621151
executable:/opt/redis/bin/./redis-server
config_file:
io_threads_active:0
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_fai服务器托管网lover_state:no-failover
master_replid:403fb28ee7de9ac263ba798f97c92ce193a455ee
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> del foo
(integer) 1
127.0.0.1:6379> get foo
(nil)
1.5、PATH处理
[root@redis-leo-master ~]# vi /etc/profile
添加如下:
export PATH=$PATH:/opt/redis/bin
[root@redis-leo-master ~]# source /etc/profile
[root@redis-leo-master ~]# su - redis
[redis@redis-leo-master ~]$ vi .bash_profile
添加如下:
export PATH=$PATH:/opt/redis/bin
[redis@redis-leo-master ~]$ source .bash_profile
1.6、修改配置参数
--修改配置参数使redis服务进程在后台运行.
[redis@redis-leo-master bin]$ pwd
/opt/redis/bin
[redis@redis-leo-master bin]$ mkdir -p /opt/redis/data
[redis@redis-leo-master bin]$ cp redis.conf redis.conf.bak`date +%Y%m%d%H%M%S`
[redis@redis-leo-master bin]$ >redis.conf
[redis@redis-leo-master bin]$ vi redis.conf
添加如下:
bind * -::*
port 6379
protected-mode no
daemonize yes
pidfile "/opt/redis/bin/redis_6379.pid"
logfile "/opt/redis/bin/redis_6379.log"
dbfilename "dump_6379.rdb"
dir "/opt/redis/data"
说明:如上主要配置”daemonize yes”参数使redis进程在后台运行.
--重启redis实例
[redis@redis-leo-master bin]$ ps -ef|grep redis
avahi 832 1 0 21:05 ? 00:00:00 avahi-daemon: running [redis-leo-master.local]
redis 41085 1 0 22:11 pts/0 00:00:01 ./redis-server *:6379
root 41175 36283 0 22:16 pts/0 00:00:00 su - redis
redis 41176 41175 0 22:16 pts/0 00:00:00 -bash
redis 41315 41176 0 22:25 pts/0 00:00:00 ps -ef
redis 41316 41176 0 22:25 pts/0 00:00:00 grep --color=auto redis
[redis@redis-leo-master bin]$ kill -9 41085
[redis@redis-leo-master bin]$ redis-server ./redis.conf
[redis@redis-leo-master bin]$ ps -ef | grep redis
avahi 832 1 0 21:05 ? 00:00:00 avahi-daemon: running [redis-leo-master.local]
root 41175 36283 0 22:16 pts/0 00:00:00 su - redis
redis 41176 41175 0 22:16 pts/0 00:00:00 -bash
redis 41329 1 0 22:26 ? 00:00:00 redis-server *:6379
redis 41334 41176 0 22:26 pts/0 00:00:00 ps -ef
redis 41335 41176 0 22:26 pts/0 00:00:00 grep --color=auto redis
说明:至此redis-6.2.5单实例安装完毕.
2、搭建一主一从
2.1、从节点1实例搭建
说明:按如上步骤在redis-leo-slave1节点搭建redis 6.2.5实例.
2.2、修改从节点1配置文件
[root@redis-leo-slave1 bin]# vi redis.conf
修改如下:
bind * -::*
port 6379
protected-mode no
daemonize yes
pidfile "/opt/redis/bin/redis_6379.pid"
logfile "/opt/redis/bin/redis_6379.log"
dbfilename "dump_6379.rdb"
dir "/opt/redis/data"
replicaof 192.168.133.97 6379
说明:从节点主要添加replicaof参数配置.
2.3、关闭防火墙
--三台服务器均关闭防火墙.
[root@redis-leo-master ~]# systemctl stop firewalld
[root@redis-leo-master ~]# systemctl disable firewalld
[root@redis-leo-slave1 ~]# systemctl stop firewalld
[root@redis-leo-slave1 ~]# systemctl disable firewalld
2.4、重启redis实例
--重启从节点1 redis实例.
[redis@redis-leo-slave1 ~]$ redis-cli shutdown
[redis@redis-leo-slave1 ~]$ redis-server /opt/redis/bin/redis.conf
2.5、相关信息查询
--查master信息显示当前角色为master,且有1个slave连接.
[redis@redis-leo-master ~]$ redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.133.98,port=6379,state=online,offset=168,lag=0
master_failover_state:no-failover
master_replid:d750cfa3388bc1064a30803ca0076822af8d4f47
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:168
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:168
--查从节点1信息显示当前角色为slave,并表示master在线且显示master ip和port.
[redis@redis-leo-slave1 ~]$ redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.133.97
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:98
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:d750cfa3388bc1064a30803ca0076822af8d4f47
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:98
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:98
2.6、主从同步验证
Master:
127.0.0.1:6379> set name leo
OK
127.0.0.1:6379> get name
"leo"
Slave1
127.0.0.1:6379> get name
"leo"
3、添加从节点
说明:此处采用级联方式添加从节点,将从节点1作为从节点2的主节点.
3.1、从节点实例搭建
说明:按如上步骤在redis-leo-slave2节点搭建redis 6.2.5实例.
2.2、修改从节点2配置文件
[root@redis-leo-slave1 bin]# vi redis.conf
修改如下:
bind * -::*
port 6379
protected-mode no
daemonize yes
pidfile "/opt/redis/bin/redis_6379.pid"
logfile "/opt/redis/bin/redis_6379.log"
dbfilename "dump_6379.rdb"
dir "/opt/redis/data"
#replicaof 192.168.133.98 6379
说明:从节点2原本计划添加replicaof参数,将192.168.133.98作为主节点.但此处将其注释,采用指令的方式搭建.
3.3、关闭防火墙
--关闭从节点2防火墙.
[root@redis-leo-slave2 ~]# systemctl stop firewalld
[root@redis-leo-slave2 ~]# systemctl disable firewalld
3.4、重启redis实例
--重启从节点1 redis实例.
[redis@redis-leo-slave2 ~]$ redis-cli shutdown
[redis@redis-leo-slave2 ~]$ redis-server /opt/redis/bin/redis.conf
说明:此处未对redis.conf配置文件进行修改,因此不用重启redis实例.
3.5、搭建级联主从关系
--以下在从节点2执行,将从节点1作为从节点2的主库.
[redis@redis-leo-slave2 ~]$ redis-cli -h 192.168.133.99 -p 6379
192.168.133.99:6379> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:46a4d61e32fbcf77102590e958c73ed6fad9ab73
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
192.168.133.99:6379> replicaof 192.168.133.98 6379
OK
192.168.133.99:6379> info replication
# Replication
role:slave
master_host:192.168.133.98
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:2500
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:d750cfa3388bc1064a30803ca0076822af8d4f47
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2500
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2487
repl_backlog_histlen:14
3.6、相关信息查询
--查master信息显示当前角色为master,且有1个slave连接.
[redis@redis-leo-master ~]$ redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.133.98,port=6379,state=online,offset=2640,lag=0
master_failover_state:no-failover
master_replid:d750cfa3388bc1064a30803ca0076822af8d4f47
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2640
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:2640
--查从节点1信息显示当前角色为slave,并显示master ip和port.
[redis@redis-leo-slave1 ~]$ redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.133.97
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:2696
slave_prior服务器托管网ity:100
slave_read_only:1
replica_announced:1
connected_slaves:1
slave0:ip=192.168.133.99,port=6379,state=online,offset=2696,lag=0
master_failover_state:no-failover
master_replid:d750cfa3388bc1064a30803ca0076822af8d4f47
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2696
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:2696
参考网址:https://blog.csdn.net/norang/article/details/119965408
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
在计算机视觉领域,YOLO(You Only Look Once)是一种流行的目标检测算法,它能够快速准确地识别图像中的物体,并输出其边界框和类别信息。YOLOv5是YOLO系列的最新版本,相比之前版本在精度和速度上都有了显著提升。但在运行YOLOv5的tra…