[Linux] install and configure redis3.2.3 on CentOS 7, centosredis3.2.3
I. Install redis source code
As of January 11, the latest stable version of redis is 3.2.3. This article is based on this version.
Download the redis source code and perform the following operations:
Wget http://download.redis.io/releases/redis-3.2.3.tar.gz
Tar-zxvf redis-3.2.3.tar.gz
Music redis-3.2.3 redis
After decompression, install the tool as follows:
Cd redis
Make & make install
Through this, we can easily see that redis is installed to/usr/local,/usr/local/bin,/usr/local/share,/usr/local/include, /usr/local/lib,/usr/local/share/man directory.
Then switch to the utils directory and execute the redis Initialization Script install_server.sh, as shown below:
Cd utils/
./Install_server.sh
Port: 6379
Config file:/etc/redis/6379. conf
Log file:/var/log/redis_62.16.log
Data dir:/var/lib/apsaradb for redis/6379
Executable:/usr/local/bin/redis-server
Cli Executable:/usr/local/bin/redis-cli
Copied/tmp/6379. conf =>/etc/init. d/redis_6379
Through, we can see that the redis configuration file after redis Initialization is/etc/redis/6379. conf: the log file is/var/log/redis_62.16.log, and the data file is dump. rdb is stored in the/var/lib/redis/6379 directory, and the startup script is/etc/init. d/redis_6379.
Now we want to use systemd, so in/etc/systems/system
Create a unit file namedredis_6379.service
.
vi/etc/systemd/system/redis_6379.service
Enter the following content. For details, see systemd. service.
[Unit]
Description=Redis on port 6379
[Service]
Type=forking
ExecStart=/etc/init.d/redis_6379 start
ExecStop=/etc/init.d/redis_6379 stop
[Install]
WantedBy=multi-user.target
Check the redis version and run the redis-cli-version command as follows:
Redis-cli-version
We can see that the redis version is 3.2.3.
Now we only need to start redis to use redis. The installation of redis in this source code method is complete.
Ii. yum Installation
After introducing the source code to install redis, We will install redis using yum. This article uses centos6.8 as an example. Run the following command:
Rpm-Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Rpm-Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Yum-y-enablerepo = remi, remi-test install redis
After redis is installed, let's check the related files created during redis installation, as follows:
Rpm-qa | grep redis
Rpm-ql redis
We can see that the configuration file of redis is/etc/redis. conf, data file dump. rdb is stored in the/var/lib/redis/directory. The log file is/var/log/redis. log, others are default.
Check the redis version and run the redis-cli-version command as follows:
Redis-cli-version
We can see that the yum installation method is indeed the latest redis version.
Now we only need to start redis and we can use redis. The yum installation method is complete.
Iii. apt-get Installation
After the introduction of installing redis in yum mode, we will introduce how to install redis in Ubuntu through apt-get.
Based on the new version and old version of redis, we have made another distinction.
3.1 apt-get
Install the latest version
To install the latest version of redis, first import the apt-get warehouse verification key, as shown below:
Wget-q-O-http://www.dotdeb.org/dotdeb.gpg | sudo apt-key add-
Or
Wget http://www.dotdeb.org/dotdeb.gpg
Sudo apt-key add dotdeb. gpg
After the verification file is installed, configure the apt-get repository as follows:
Vim/etc/apt/sources. list. d/redis. list
Deb http://packages.dotdeb.org wheezy all
Deb-src http://packages.dotdeb.org maid all
Note: This apt-get warehouse uses the debian apt-get warehouse. After multiple tests, we found that only the apt-get Warehouse can be installed to the latest redis version.
After configuring the apt-get repository, run the following command to install the Repository:
Sudo apt-get clean all
Sudo apt-get update
Sudo apt-get-y install redis-server
Through this, we can clearly see that the redis version is 3.2.3, the latest version. You can also run the redis-cli-version command. As follows:
Redis-cli-version
We can see that redis installed in this way is the latest version.
4. Configure redis
After redis is installed, We will configure redis again. In fact, for redis installation, we recommend that you install it directly through the source code. After the installation, the redis configuration file is complete.
To ensure security, you only need to enable the requirepass parameter of the redis password verification function.
The final redis configuration file is as follows:
Grep-Ev '^ # | ^ $'/etc/redis/6379. conf
Bind 127.0.0.1
Protected-mode yes
Port 6379
Tcp-Back log 511
Timeout 0
Tcp-keepalive 300
Daemonize yes
Supervised no
Pidfile/var/run/redis_62.16.pid
Loglevel notice
Logfile/var/log/redis_62.16.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Stop-writes-on-bgsave-error yes
Rdbcompression yes
Rdbchecksum yes
Dbfilename dump. rdb
Dir/var/lib/apsaradb for redis/6379
Slave-serve-stale-data yes
Slave-read-only yes
Repl-diskless-sync no
Repl-diskless-sync-delay 5
Repl-disable-tcp-nodelay no
Slave-priority 100
Requirepass ilanniredis
Appendonly no
Appendfilename "appendonly. aof"
Appendfsync everysec
No-appendfsync-on-rewrite no
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64 mb
Aof-load-truncated yes
Lua-time-limit 5000
Slowlog-log-slower-than 10000
Slowlog-max-len 128
Latency-monitor-threshold 0
Policy-keyspace-events ""
Hash-max-ziplist-entries 512
Hash-max-ziplist-value 64
List-max-ziplist-size-2
List-compress-depth 0
Set-max-intset-entries 512
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64
Hll-sparse-max-bytes 3000
Activerehashing yes
Client-output-buffer-limit normal 0 0 0
Client-output-buffer-limit slave 256 mb 64 mb 60
Client-output-buffer-limit pubsub 32 mb 8 mb 60
Hz 10
Aof-rewrite-incremental-fsync yes
We will introduce these parameters in the configuration file in a later article. The redis configuration is complete.
V. Start and use redis
After configuring the redis configuration file, start redis and perform simple operations. As follows:
Redis-cli-h 127.0.0.1-p 6379-a ilanniredis
Keys *
Set ilanni testredis
Get ilanni
Let's explain the meaning of the above commands:
Redis-cli-h 127.0.0.1-p 6379-a ilanniredis
This command is used to connect to the redis server, with the IP address 127.0.0.1, port 6379, and password ilanniredis.
Keys * is to view all key-value pairs of redis.
Set ilanni testredis to add a key value ilanni with the content testredis.
Get ilanni view the content of the ilanni key value.