[Redis | Redis Installation] Under CentOS, install Redis

Note : [This article is recorded in personal study, may contain content excerpted from the Internet, intrusion and deletion! If you make any mistakes, please correct me, communicate and make progress together, thank you!

Native environment:

VMware Fusion Pro 12.1.2
​CentOS 6.5
Redis 3.2.8

One, install Redis

1. Download and upload the Redis installation package

1) Download the Redis installation package redis-3.2.8.tar.gz (link: https://pan.baidu.com/s/1oDQv3nr46qcb70_z9HdeeQ password: i98r)
2) Upload the Redis installation package to the /tmp directory in the CentOS server
3) Unzip the Redis installation package

cd /tmp
tar -zxvf redis-3.2.8.tar.gz

4) Move the unzipped package to /usr/local/ and rename it to redis

mv redis-3.2.8 /usr/local/redis

2. Compile and install Redis

carried out

cd /usr/local/redis
make -j 4 #使用4核同时编译,加快编译速度

Compilation is complete, execute

make install #将编译好的可执行文件添加至系统目录里

3. Change the Redis configuration file

carried out

cd /usr/local/redis
vi redis.conf
  • Change bind bind outside the machine can also be accessed
  • Change daemonize nois daemonize yesset to start with a daemon thread way
  • Open #requirepass foobaredcomments, change requirepass 123456, set the password to connect the Redis

4. Start Redis

carried out

redis-server /usr/local/redis/redis.conf

5. Access Redis

carried out

A password is required to connect to Redis

(Because password access is configured in the Redis configuration file, password login is required to access Redis.)

Second, start Redis as a service

1. Execution

cp /usr/local/redis/redis.conf /usr/local/redis/6379.conf #后面会有用到该 Redis配置文件
cd /usr/local/redis/utils

2. According to the prompts, type the corresponding content one by one, you can refer to the following

Redis started as a service

3. Execute the following commands to view the configuration status of the Redis service

chkconfig --list | grep redis

4. Execute the following commands to view the current status of Redis

service redis_6379 status
Insert picture description here

5. Execute the following instructions to modify the Redis service script and add the yellow authorization information as shown below.

vi /etc/init.d/redis_6379
  1. Add a variable above the script PASSWORD=123456
  2. Found $REDIS_CLI -p $REDISPORT shutdown, change to$REDIS_CLI-a $PASSWORD-p $REDISPORT shutdown
  3. Save and exit
Due to the above, we set up a connection Redis need to use a password requirepass 123456, if there is no change Redis service script execution will be service redis_6379 stopstopped when the Redis service will be error: NOAUTH Authentication required.

6. Execute the following command to stop the Redis service

service redis_6379 stop

7. Execute the following command to open the Redis service

service redis_6379 start
Restart Redis

Three, rename the Redis service

As you can see from the above, the Redis service name is redis_6379, let’s change the service name to redis

Of course, we can also imitate the mysql service name: mysqld will change the Redis service name to redisd

carried out

mv /etc/init.d/redis_6379 /etc/init.d/redis
chkconfig --add redis
chkconfig --list | grep redis
service redis restart

Four, reference

Linux series-Set up Redis as a service