1. 程式人生 > >Centos 7安裝部署Redis

Centos 7安裝部署Redis

作為軟體開發人員在開發系統的時候為了提高系統的響應效率採用快取技術是必須的,現在redis是使用較多的快取技術,這裡介紹一下如何在centos7環境下配置redis服務。

Redis 安裝部署

作業系統環境不用說了(需要配置好gcc環境) 1.下載redis安裝檔案

2.解壓縮

tar -zxvf redis-4.0.11.tar.gz

3.編譯安裝 在安裝前切記執行這句,不然會報錯 make MALLOC=libc 隨後進入src目錄執行,剩下的就等著就是了

make instal

安裝結束了啟動一下redis服務

[[email protected]

redis-4.0.11]# ./src/redis-server

你會看到以下結果

15018:C 16 Sep 20:49:05.729 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15018:C 16 Sep 20:49:05.730 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=15018, just started
15018:C 16 Sep 20:49:05.730 # Warning: no config file specified, using the default config. In
order to specify a config file use ./src/redis-server /path/to/redis.conf 15018:M 16 Sep 20:49:05.731 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-``
`. `_. ''-._ Redis 4.0.11 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 15018 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 15018:M 16 Sep 20:49:05.733 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 15018:M 16 Sep 20:49:05.733 # Server initialized 15018:M 16 Sep 20:49:05.733 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 15018:M 16 Sep 20:49:05.733 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 15018:M 16 Sep 20:49:05.733 * DB loaded from disk: 0.000 seconds 15018:M 16 Sep 20:49:05.733 * Ready to accept connections

說明redis已經成功完成安裝

Redis配置

安裝完後不可能每次要使用的時候都手動啟動redis,因此我們需要做一些配置讓redis能夠作為後臺服務在開機的時候自動啟動。 1.修改redis的配置檔案

[[email protected] redis-4.0.11]# vi redis.conf

找到

daemonize no

並將其修改為

daemonize yes

2.將src目錄下面的檔案同步複製到/usr/local/bin目錄下

[[email protected] init.d]# cp /opt/redis/redis-4.0.11/src/* -r /usr/local/bin/

3.在/etc下建立redis目錄

[[email protected] redis-4.0.11]# mkdir /etc/redis

4.複製redis.conf檔案到/etc/redis目錄下並重命名為6397.conf

[[email protected] redis-4.0.11]# cp /opt/redis/redis-4.0.11/redis.conf /etc/redis/6379.conf

5.複製redis啟動指令碼到/etc/init.d下並重命名為redisd

[[email protected] redis-4.0.11]# cp utils/redis_init_script /etc/init.d/redisd

6.設定redis開機自啟

[[email protected] init.d]# chkconfig redisd on

7.啟動測試

[root@nic-redis init.d]# service redisd start
Starting Redis server...
16065:C 16 Sep 21:12:01.590 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16065:C 16 Sep 21:12:01.590 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=16065, just started
16065:C 16 Sep 21:12:01.590 # Configuration loaded

這時候說明redis已經作為後臺服務啟動了 這時候看下程序

[root@nic-redis init.d]# ps -aux | grep redis
avahi       707  0.0  0.0  62240  2180 ?        Ss   907   0:05 avahi-daemon: running [nic-redis.local]
root      16066  0.0  0.0  38240  1952 ?        Ssl  21:12   0:00 /usr/local/bin/redis-server 127.0.0.1:6379
root      16259  0.0  0.0 112720   936 pts/0    S+   21:18   0:00 grep --color=auto redis

重啟一下再測試

[root@nic-redis ~]# ps -aux | grep redis
avahi       693  0.0  0.0  62236  2180 ?        Ss   21:19   0:00 avahi-daemon: running [nic-redis.local]
root       1129  0.0  0.0 141828  1992 ?        Ssl  21:19   0:00 /usr/local/bin/redis-server 127.0.0.1:6379
root       2005  0.0  0.0 112720   932 pts/0    S+   21:21   0:00 grep --color=auto redis

可以看到redis已經能夠開機作為後臺服務自動啟動了,這樣我們就完成了redis的安裝配置工作!