Centos7 offline mode installation Redis6.2.13 detailed steps (rpm mode)

This article mainly introduces the installation of Redis6.2.13 in the CentOS7 server. The premise is that there is a gcc environment, so here I will also introduce the detailed installation process of gcc. I refer to many other related blogs, but some bloggers’ articles It may be transported, which caused me to report an error during the actual operation, so I will also introduce the troubleshooting solution here.

1. Preliminary inspection

Redis is developed by C language, and it needs gcc environment to compile under CentOS system, so check whether gcc is installed in the system

gcc -v

insert image description here
If there is no output above, it means that gcc is not installed.

2. Download and install gcc

Download the rpm package related to gcc:
http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
In the mirror of Alibaba Cloud, download the following rpm package.
insert image description here
After the download is complete, it can be uploaded to the specified directory through FinalShell
insert image description here
to install gcc-related rpm

rpm -ivh *.rpm --nodeps --force

–nodeps: When rpm installs packages, do not check dependencies
–force: Force installation

insert image description here
Check whether the installation is complete. If the following screenshot appears, it means that the gcc installation is successful.

gcc -v

insert image description here

3. Unzip the Redis compressed package and install the configuration

Redis download address: https://redis.io/download/#redis-downloads

3.1 Unzip the file

#进入到文件目录 路径是自己情况修改
cd /usr/local/redis
# 解压
tar -xvf redis-6.2.13.tar.gz -C /usr/local/redis

3.2 Compile and install files

# 进入到解压后的文件目录 路径是自己情况修改
cd /usr/local/redis/redis-6.2.13
# 编译
make
# 指定安装目录并进行安装
make install PREFIX=/usr/local/redis

If makean error occurs when using the command: zmalloc.h:50:31: Fatal error: jemalloc/jemalloc.h: There is no such file or directory, you
can use make MALLOC=libcthe command.
For details, see: Redis installation error: zmalloc.h:50:31: Fatal error: jemalloc/jemalloc.h: No such file or directory

insert image description here
After using the make command to compile, if the screenshot frame selection appears at the end of the command line output, the compilation is successful.
insert image description here
Specify the installation directory and perform the installation. If the following content appears, the installation is successful.
insert image description here

3.3 Modify the configuration file

# 复制配置文件到bin目录  目录需要自己视情况修改 复制语法:cp <源文件> <目标文件夹路径> 
cp /usr/local/redis/redis-6.2.13/redis.conf /usr/local/redis/bin
# 进入redis安装目录
cd /usr/local/redis/bin/
# 修改配置文件
vim redis.conf

If you want to set the specified IP to connect to redis, you only need to modify the bind configuration item in the redis.conf file. If the IP is not limited, change 127.0.0.1 to 0.0.0.0, or comment this line.
insert image description here
Modify the port number
insert image description here
and set it to start automatically when booting.
insert image description here
Disable the protection mode.
insert image description here

3.4 Start the service

# 启动服务
./redis-server redis.conf
# 查看进程
ps -ef |grep redis

insert image description here

3.5 Set up automatic startup

vim /usr/lib/systemd/system/redis.service

The content is as follows:

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
# ExecStart需要按照实际情况修改成自己的地址
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3.5 Start the service

# 开机自动启动
systemctl enable redis.service
# 启动redis服务
systemctl start redis.service
# 查看服务状态
systemctl status redis.service
# 停止服务
systemctl stop redis.service
# 取消开机自动启动(卸载服务)
systemctl disabled redis.service

insert image description here

3.6 Using the Redis-cli command line

./redis-cli -h 127.0.0.1 -p 6379

insert image description here

Guess you like

Origin blog.csdn.net/qq_44723773/article/details/131670845