Installing redis needs to rely on the gcc environment. Execute the following command to install:
yum install -y gcc
If the machine does not have a network, you can refer to this article:
CentOS offline installation gcc environment (with installation package pictures and texts)
redis official website: https://redis.io/download
Download Then upload it to CentOS, for example, upload it to /usr/local/
command is as follows:
cd /usr/local/
tar -zxvf redis-6.2.1.tar.gz
cd redis-6.2.1 make##4 , Install to the specified directory Install redis to the specified directory, you can modify the path yourself, take
/usr/local/redis as an example:
make install prefix=/usr/local/redis
4. Start redisThere are two ways to start redis, one is to start the foreground interface, which will be closed as long as the interface is closed, and the other is to start the background. 4.1. Start the front-end interfaceEnter the bin directory of the redis installation directory:
cd /usr/local/redis/binAt this time, just execute the following command to start:
./redis-serverThe startup screenshot is as follows: The problem at this time is that we don’t know where the startup configuration file is...In fact, we can directly pass Use the find command to check:
find / -name 'redis.conf'The results are as follows: The front-end startup method is not commonly used. As long as the interface is closed, redis will stop. 4.2. Start the background serviceWe copy a redis.conf file from the previously decompressed installation package to the redis installation directory.
cp /usr/local/redis-6.2.1/redis.conf /usr/local/redis/bin/Then modify the thread mode parameters of the redis.conf configuration file:
vi /usr/local/redis/bin/redis.confPS: vi shortcut key, click
/, and then enter [keyword] Query parameters.
daemonizeThe corresponding value is yes
1、修改之前 daemonize no 2、修改之后 daemonize yesExplanation of the value of this parameter:
./redis-server redis.confNow redis is started in the background. 5. Set external network accessThe default configuration file does not support external network access. Next, modify the parameters for external network access. Or modify the configuration file:
vi /usr/local/redis/bin/redis.confFind the following three parameters:
is modified as follows:
vi /etc/systemd/system/redis.serviceAdd the following command:
[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.targetThe ExecStart parameter corresponds to the installation of redis-server in the Redis directory, and the configuration file is the same as above. Set up startup:
systemctl daemon-reload systemctl start redis.service systemctl enable redis.service7. Common service commandsStart redis service
systemctl start redis.service
systemctl stop redis.service
systemctl restart redis.service
systemctl status redis.service
systemctl enable redis.service
systemctl disable redis.service
The above is the detailed content of How to install redis in CentOS7 and configure it to be accessible from the external network. For more information, please follow other related articles on the PHP Chinese website!