install redis on centos7, use systemctl to boot

1. Download
Originally, I wanted to download the compressed package directly in centos through wget http://download.redis.io/releases/redis-4.0.2.tar.gz, but the download was unsuccessful.
So I downloaded the compressed package on the official website, and then transferred the file to /home/hsoluo/Downloads via ftp
. 2. Installation

  1. Go to the /home/hsoluo/Downloads directory, and then unzip the installation package
cd /home/hsoluo/Downloads
tar -xzvf redis-4.0.2.tar.gz
  1. Enter the decompressed file and compile it directly
cd /home/hsoluo/Downloads/redis-4.0.2
make
  1. Create a file to store redis and copy redis-server redis-cli to the newly created folder
mkdir -p /usr/local/redis
cp /home/hsoluo/Downloads/redis-4.0.2/src/redis-server /usr/local/redis/
cp /home/hsoluo/Downloads/redis-4.0.2/src/redis-cli /usr/local/redis/
  1. Start redis by command
cd /usr/local/redis
./redis-server
  1. To start redis in the background,
    first copy the redis.conf file to the redis folder, and then modify the configuration of some parameters
 cp /home/hsoluo/Downloads/redis-4.0.2/redis.conf /usr/local/redis/
 vim redis.conf

Modify the configuration information of redis.conf
1) Add "#" before bind 127.0.0.1 and comment it out
2) The default is protected mode, change protected-mode yes to protected-mode no
3) The default is no daemon mode, Change daemonize no to daemonize yes
4) Remove the "#" before requirepass foobared, and change the password to the password you want to set (for your own use, set it to simple 123456)

Then start redis.conf

./redis-server redis.conf
  1. Setting up boot-up I
    stepped on the pit when I set up the boot-up. I originally wanted to use the command chkconfig --add redis to set the boot-up, but I couldn't start it up or down, so I switched to systemctl to start it.
vim /etc/systemd/system/redis.service

Copy the following content in the file:
[Unit]
Description=redis-server
After=network.target

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

[Install]
WantedBy=multi-user.target
**ps.**ExecStart should be set to its own path

Then set boot to start

systemctl daemon-reload

systemctl start redis.service

systemctl enable redis.service
  1. View the process status of redis
[root@localhost ~]# ps -ef|grep redis
root      14467      1  0 16:34 ?        00:00:05 ./redis-server *:6379
root      19357  11723  0 17:37 pts/2    00:00:00 grep --color=auto redis

If the above appears, it means that redis has been successfully installed in centos.
8. Use redis graphical tools to connect to redis in centos in windows.
First, open the redis port in centos, and then restart the firewall to connect. The instructions are as follows

systemctl start firewalld (开启防火墙)
firewall-cmd --permanent --add-port=6379/tcp(开放redis端口)
systemctl restart firewalld(重启防火墙)

Insert picture description here
Test the connection, if it is success, it will succeed.

Guess you like

Origin blog.csdn.net/weixin_39040527/article/details/106671028