Install the latest Redis on CentOS

Introduction to Redis

Redis is a high-performance key-value database. The emergence of redis has largely compensated for the inadequacy of key/value storage such as memcached, and can play a good supplementary role to relational databases in some cases. It provides clients such as Java, C/C++, C#, PHP, JavaScript, Perl, Object-C, Python, Ruby, Erlang, etc., which is very convenient to use.

download

Download the latest version from the official website

https://redis.io/download

installation

Upload the downloaded compressed file to the server. For example, in the /usr/loca folder, create a new redis folder.
Use tar -zxvf'file name' to decompress.

Because redis is written in C language. So before compiling, you must confirm whether the gcc compiler is installed locally. You can check it with the (gcc -v) command.

Enter the unzipped folder. See the file, similar to the figure below:
Insert picture description here
execute the make command.
After brushing the code, if there is no warning message similar to the following, it means that the compilation is complete.
Insert picture description here

If there is a message of the type above, it is because the gcc version is too low. The
upgrade method is as follows:

# 查看当前版本
gcc -v
# 升级到9.1版本
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
# 临时启用
scl enable devtoolset-9 bash  (目前先用这个就行)
# 如果要长期使用gcc 9.1的话
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

After the compilation is complete, install to the specified directory

make install PREFIX=/usr/local/redis

start up

Foreground start

Execute under the bin file after installation

[root@localhost bin]# ./redis-server

Start in the background

Need to configure redis.conf Copy redis.conf
from the source directory of redis to the installation directory of redis

cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis6/bin/
cp 源目录 空格 安装目录

[root@localhost bin]# vim redis.conf
modify redis.conf file, change daemonize no to daemonize yes

Background start command

[root@localhost bin]# ./redis-server redis.conf

Use the ps command to check whether the startup is successful
Insert picture description here

Use optimization

Set boot up

Add boot service

[root @ localhost bin] # vi /etc/systemd/system/redis.service

Copy and paste the following:

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

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Note: ExecStart is configured to its own path

Set boot up

[root@localhost bin]# systemctl daemon-reload

[root@localhost bin]# systemctl start redis.service

[root@localhost bin]# systemctl enable redis.service

Set shortcut

[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

Common service operation commands

systemctl start redis.service #Start redis service

systemctl stop redis.service #Stop the redis service

systemctl restart redis.service #Restart the service

systemctl status redis.service #View the current status of the service

systemctl enable redis.service #Set the boot to start automatically

systemctl disable redis.service #Stop self-starting after booting

Guess you like

Origin blog.csdn.net/shuai_ge_feng/article/details/108547482