CentOS? 7.6 install Redis 6.0.1 and enable auto start

Keywords: Database Redis CentOS yum shell


Alibaba cloud's ECS server just bought is going to set up a website of its own. First install the Redis service.

Download Redis

Download address: https://redis.io/download

Current version of Redis 6.0.1

Upgrade gcc

#Check whether the gcc version is above 5.3. CentOS 7.6 installs 4.8.5 by default
[root@liukai-ecs-01 system]# gcc -v
 #Upgrade gcc to 5.3 and above, as follows:
Upgrade to gcc 9.3:
[root@liukai-ecs-01 system]# yum -y install centos-release-scl
[root@liukai-ecs-01 system]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@liukai-ecs-01 system]# scl enable devtoolset-9 bash
 It should be noted that the scl command is only enabled temporarily. Exiting the shell or restarting will restore the original gcc version of the system.
If you want to use gcc 9.3 for a long time:

[root@liukai-ecs-01 system]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
 So you exit the shell and reopen it, which is the new version of gcc
 The following other versions are the same. Just change the version number of devtoolset.

Install Redis

Enter the /usr/local directory

[root@liukai-ecs-01 local]# ls
[root@liukai-ecs-01 local]# tar xf redis-6.0.1.tar.gz -C redis/
[root@liukai-ecs-01 local]# cd redis/
[root@liukai-ecs-01 redis]# make && make install

Other commands

# In case of compilation error, clean out the files generated by compilation
make distclean
# Compile and install to the specified directory
make PREFIX=/usr/local/redis install 
# uninstall
make uninstall

Set automatic startup

Enter the cd /usr/local/redis directory and modify the redis.conf file

[root@liukai-ecs-01 local]# cd /usr/local/redis
[root@liukai-ecs-01 redis]# vim redis.conf
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# Change no to yes to start the service in the future mode
daemonize yes

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
# Changing no to systemd means starting in CentOS systemd system service mode
supervised systemd

Enter the / etc/systemd/system directory and create the redis-server.service file

[root@liukai-ecs-01 redis]# cd /etc/systemd/system
[root@liukai-ecs-01 system]# vim redis-server.service
# example systemd service unit file for redis-server
# In order to use this as a template for providing a redis service in your
# environment, _at the very least_ make sure to adapt the redis configuration
# file you intend to use as needed (make sure to set "supervised systemd"), and
# to set sane TimeoutStartSec and TimeoutStopSec property values in the unit's
# "[Service]" section to fit your needs.
# Some properties, such as User= and Group=, are highly desirable for virtually
# all deployments of redis, but cannot be provided in a manner that fits all
# expectable environments. Some of these properties have been commented out in
# this example service unit file, but you are highly encouraged to set them to
# fit your needs.
# Please refer to systemd.unit(5), systemd.service(5), and systemd.exec(5) for
# more information.

Description=Redis data structure server
#Before=your_application.service another_example_application.service

#ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize yes
## Alternatively, have redis-server load a configuration file:
#ExecStart=/usr/local/bin/redis-server /path/to/your/redis.conf
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
# Note that notify will fail. Instead, it will be started in forking mode. Let the main process copy a sub process for execution


Reload system service file

[root@liukai-ecs-01 system]# systemctl daemon-reload

Start redis server in system service mode

[root@liukai-ecs-01 system]# systemctl start redis-server.service

View service status

[root@liukai-ecs-01 system]# systemctl status redis-server.service
● redis-server.service - Redis data structure server
   Loaded: loaded (/etc/systemd/system/redis-server.service; enabled; vendor preset: disabled)
   Active: active (running) since III. 2020-05-13 21:43:35 CST; 38min ago
     Docs: https://redis.io/documentation
 Main PID: 16153 (redis-server)
   CGroup: /system.slice/redis-server.service
           └─16153 /usr/local/bin/redis-server

5 13-21:43:35 liukai-ecs-01 systemd[1]: Starting Redis data structure server...
5 13-21:43:35 liukai-ecs-01 redis-server[16152]: 16152:C 13 May 2020 21:43:35.196 # oO0OoO0OoO0...0Oo
5 13-21:43:35 liukai-ecs-01 redis-server[16152]: 16152:C 13 May 2020 21:43:35.196 # Redis versi...ted
5 13-21:43:35 liukai-ecs-01 redis-server[16152]: 16152:C 13 May 2020 21:43:35.196 # Configurati...ded
5 13-21:43:35 liukai-ecs-01 redis-server[16152]: 16152:C 13 May 2020 21:43:35.196 # WARNING sup...it.
5 13-21:43:35 liukai-ecs-01 redis-server[16152]: 16152:C 13 May 2020 21:43:35.196 # systemd sup...und
5 13-21:43:35 liukai-ecs-01 systemd[1]: Started Redis data structure server.
Hint: Some lines were ellipsized, use -l to show in full.

Check whether redis is started

[root@liukai-ecs-01 ~]# ps -ef | grep redis
root       519     1  0 22:24 ?        00:00:00 /usr/local/bin/redis-server
root      1046  1028  0 22:25 pts/0    00:00:00 grep --color=auto redis

Set the startup of redis service

[root@liukai-ecs-01 system]# systemctl enable redis-server.service

reference material

Posted by blueguitar on Thu, 14 May 2020 07:56:20 -0700