Install and configure Redis in Centos8 to achieve remote access

1. To achieve the goal

1.1. Install Redis-6.2.3 in Centos8

1.2. Configure Redis for remote access

Second, the process of installing Redis on the Contos8 local server

2.1, preparation content

①Redis official website download address:

②Download address of Redis visual management tool:

③Redis Reference Manual:

2.2, install Redis-6.2.3 steps in Centos8

① Use the root account to check whether the C++ compiler is installed

yum -y install gcc-c++

②Obtain the Redis-6.2.3 installation package and unzip and install

#①下载Redis-6.2.3安装包wget #②解压Redis-6.2.3安装包tar xzf redis-6.2.3.tar.gz #③进入解压好的Redis6.2.3目录cd redis-6.2.3 #④编译且安装Redis-6.2.3make && make install

③Copy the configuration file Redis.conf to the Src directory

cp redis.conf src

④Start the Redis server

#启动Redis-6.2.3服务端./redis-server redis.conf

⑤Open a new window and run the Redis-6.2.3 client

#①进入Redis-6.2.3客户端的路径src下cd src #②启动客户端./redis.cli 

⑥Insert the key-value pair into the server to test whether it is successful

#①设置键值对到服务器中set 键 值 ②根据键获取值get 键  #示例#①给服务器设置键为foo,值为bar的内容set foo bar #②查看键foo对应的值get foo 

3. The Redis server configured with the Cenos8 server can be accessed remotely

3.1, modify the Redis configuration file

①Open the Redis.conf configuration file in the Redis server folder

#打开Redis的配置文件vim redis.conf

②Enable Redis remote access [change protected-mode to no]

Press the keyboard [i] key to insert editing, press the keyboard [esc] to exit the insert editing mode, enter [:wq] to save and exit, and enter [:q] to exit.

③Set the Redis server to start in the background

④Set password [requirepass password]

3.2, restart the Redis service

① Query the currently running Redis service first, Kill

#①查看redis服务进程ps -ef|grep 进程名称 #kill进程kill 进程编号   #示例:查询到Redis服务器进程,且Kill掉[[email protected] home]# ps -ef|grep redisroot       11756    2090  0 01:40 ?        00:00:11 ./redis-server *:6379root       18343   18224  0 03:33 pts/0    00:00:00 grep --color=auto redis[[email protected] home]# kill 11756

②Start Redis service

#启动Redis-6.2.3服务端./redis-server redis.conf

③Check that the Redis service started successfully as follows

#查看端口号为6379的程序进程lsof -i:6379  #示例:查看服务器端口号为6379的服务器进程[[email protected] home]# lsof -i:6379COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEredis-ser 11756 root    6u  IPv4 130050      0t0  TCP *:redis (LISTEN)redis-ser 11756 root    7u  IPv6 130051      0t0  TCP *:redis (LISTEN)

3.3, open the 6379 port number corresponding to Redis in Centos

#①查看当前Redis的端口6379是否打开:yes为打开firewall-cmd --query-port=6379/tcp #②开启防火墙的6379端口 firewall-cmd --zone=public --add-port=6379/tcp --permanent #③重启防火墙 firewall-cmd --reload  #④查看防火墙的端口哪些是打开的firewall-cmd --list-port   命令含义:--zone #作用域--add-port=80/tcp #添加端口,格式为:端口/通讯协议--permanent #永久生效,没有此参数重启后失效  #关闭firewall:#停止firewallsystemctl stop firewalld.service #禁止firewall开机启动systemctl disable firewalld.service 

Fourth, use the Redis visual management tool to remotely connect to the Redis server

4.1, download and install the Redis visual management tool

4.2. Check the IP address of the Redis server


4.3. Start the Redis visual management tool to connect to the remote Redis service