[Super detailed tutorial on Linux installation and deployment of Redis]

[Super detailed tutorial on Linux installation and deployment of Redis]

1. First check whether it is installed:

## 检查是否安装了Redis
 ps -ef | grep redis

Insert image description here
If it exists, delete it first:

sudo yum remove redis

Insert image description here

2. Install TCL

1. First check whether tcl is installed:

rpm -qa | grep tcl

2. Enter the data directory, create the redis directory and enter the directory

cd /data
mkdir redis
cd redis

cd /data/redis/

3. Use wget command to download the compressed package

wget http://downloads.sourceforge.net/tcl/tcl8.6.12-src.tar.gz

Insert image description here

4. Unzip the source code package tcl8.6.12-src.tar.gz to the current directory (ie: /data/redis)

sudo tar xzvf tcl8.6.12-src.tar.gz

Insert image description here

5. Enter the specified unix directory

cd /data/redis/tcl8.6.12/unix/ 

Insert image description here

6. Run the configure script in the current directory

sudo ./configure

7. Compile source code

sudo make
make

8. Installation

sudo make install

3. Install Redis

1. Download the installation package

Chinese official website: Redis Chinese official website
Official website: Official
website If the download from the official website is slow, go directly to the resource package to download.

2. Enter the directory you just created and decompress the uploaded compressed package.

## 进入文件夹
cd /data/redis
## 解压文件
tar -zxvf redis-6.2.6.tar.gz

3. Enter the installation directory, compile and test

cd /data/redis/redis-6.2.6/ 

Insert image description here``

## 输入命令make执行编译命令
make
## make test测试一下
make test

Insert image description here
Insert image description here

4. Specify the PREFIX installation directory as /data/redis. If you do not add this keyword, Linux will store the executable file in the /data/redis/bin directory.

make install PREFIX=/data/redis 

Insert image description here

4. Configure Redis

1. Set soft connections to environment variables

ln -s /data/redis/redis-6.2.6/redis.conf /etc/redis.conf

2. Edit the configuration file content

vi /etc/redis.conf

3. Change the configuration file content

①: Press / on the keyboard to enter the search mode, search for the keyword daemonize no, press the i key to enter the edit mode, change no to yes, and set it to start redis in the background
Insert image description here
②: Search for the keyword protected-mode, change yes to no
Insert image description here
③: Search for the keyword bind 127.0.0.1, change from bind 127.0.0.1 to bind 0.0.0.0 (generally it may not exist)
Insert image description here
④: Press Esc to exit the editing mode, press: wq to save and exit the vim editor

5. Start Redis

1. Enter the bin directory of Redis

cd /data/redis/bin

Insert image description here

2. Start the Redis service

./redis-server /etc/redis.conf

Insert image description here

3. Check whether Redis starts successfully

lsof -i:6379

Insert image description here

4. Connect to the local Redis test

./redis-cli -h 127.0.0.1 -p 6379

Insert image description here

5. If normal, close the service.
./redis-cli shutdown

Insert image description here

6. Set up auto-start at power on

1. Enter the etc directory

cd /etc

2. Create a new redis directory

mkdir redis

3. Copy the redis configuration file and name it 6379.conf

cp /data/redis/redis-6.2.6/redis.conf /etc/redis/6379.conf

4. Copy the redis startup script and place it in the /etc/init.d directory.

cp /data/redis/redis-6.2.6/utils/redis_init_script /etc/init.d/redis

5. Edit the copied redis file

vi /etc/init.d/redis

Change it to your own installation directory!
Insert image description here

6. Enter the directory where the Linux self-starting script is stored

cd /etc/init.d

Insert image description here

7. Set executable permissions

chmod 777 /etc/init.d/redis

8. Set to start automatically at boot

chkconfig redis on

9. View service list`

chkconfig --list

Insert image description here

10. Start the Redis service

## 启动服务
service redis start

11. Check whether the startup is successful

netstat -lntp | grep 6379

Insert image description here

12. Close the service

service redis stop

Insert image description here

7. Open the firewall port

## 查看当前防火墙放行端口情况。
firewall-cmd --zone=public --list-ports

## 查看端口状态,比如redis 6379    no-表示关闭,yes-表示开启
firewall-cmd --zone=public --query-port=6379/tcp

## 放行端口
sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent

## 防火墙重载
firewall-cmd --reload


## 再次查看端口状态
firewall-cmd --zone=public --query-port=6379/tcp


## 其他
## 检查防火墙状态
sudo systemctl status firewalld
## 开启防火墙
## 1、之前关闭,现在临时开启
sudo systemctl start firewalld
## 2、开机自启
sudo systemctl enable firewalld

## 关闭防火墙
## 1、临时关闭
sudo systemctl stop firewalld
## 永久关闭
sudo systemctl disable firewalld

Insert image description here

8. Others

1.常用命令  
  redis-server /usr/local/redis/etc/redis.conf //启动redis
  pkill redis  //停止redis
  卸载redis:
    rm -rf /usr/local/redis //删除安装目录
    rm -rf /usr/bin/redis-* //删除所有redis相关命令脚本
    rm -rf /root/download/redis-4.0.4 //删除redis解压文件夹
 
2.启动redis:
两种方式:
redis-server &
加上`&`号使redis以后台程序方式运行
或者是
redis-server
 
3.检测后台进程是否存在
ps -ef |grep redis
4.检测6379端口是否在监听
netstat -lntp | grep 6379
有时候会报异常
 
原因: Redis已经启动
解决: 关掉Redis,重启即可
redis-cli shutdown
redis-server
然后你就能看到Redis愉快的运行了.
 
使用redis-cli客户端检测连接是否正常
redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key "hello world"
OK
127.0.0.1:6379> get key
"hello world"
停止redis:
使用客户端
redis-cli shutdown
因为Redis可以妥善处理SIGTERM信号,所以直接kill -9也是可以的
kill -9 PID
#启动redis服务端
$ src/redis-server

#启动redis客户端
$ src/redis-cli

When installing redis, the prompt CC adlist.o /bin/sh: cc: command not found is prompted when executing the make command.
This is because the system does not have the gcc environment installed, so the above prompt will only appear when compiling, and then proceed after gcc is installed. When compiling, the above error message will disappear
yum -y install gcc automake autoconf libtool make
yum install gcc-c++

Guess you like

Origin blog.csdn.net/m0_49762804/article/details/132437347