centos7.6 安裝redis5.0.4 單機

centos7.6 安裝redis5.0.4

查看列表
http://download.redis.io/releases/

目前最新版穩定版爲5.0.6

[ ] redis-5.0.6.tar.gz

[root@VM_147_31_centos src]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@VM_147_31_centos src]# uname -a
Linux VM_147_31_centos 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@VM_147_31_centos src]#

創建目錄
mkdir /home/redis

進入目錄
cd /home/redis/

下載redis
wget http://download.redis.io/releases/redis-5.0.4.tar.gz
編譯

解壓redis:
tar -xvf redis-5.0.4.tar.gz

編譯redis(騰訊的試驗環境已經安裝了GCC所以可以直接編譯):
進入redis解壓目錄
cd redis-5.0.4/

編譯
make

安裝

用 make 安裝 redis
make install PREFIX=/usr/local/mysoft/redis

後面是你自己的安裝路徑。PREFIX參數指定redis的安裝目錄。一般軟件安裝到/usr目錄下
[root@VM_147_31_centos redis-5.0.4]# ll /usr/local/mysoft/redis/
total 4
drwxr-xr-x 2 root root 4096 Nov 13 17:53 bin
[root@VM_147_31_centos redis-5.0.4]# ll /usr/local/mysoft/redis/bin/
total 32700
-rwxr-xr-x 1 root root 4366640 Nov 13 17:53 redis-benchmark
-rwxr-xr-x 1 root root 8101312 Nov 13 17:53 redis-check-aof
-rwxr-xr-x 1 root root 8101312 Nov 13 17:53 redis-check-rdb
-rwxr-xr-x 1 root root 4806872 Nov 13 17:53 redis-cli
lrwxrwxrwx 1 root root 12 Nov 13 17:53 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 8101312 Nov 13 17:53 redis-server
[root@VM_147_31_centos redis-5.0.4]#

修改配置
文件由於安裝目錄僅僅是二進制文件,不包含配置文件,這裏我們要把編譯目錄的配置文件拷貝過來,我們先進入到安裝目錄, cd /usr/local/mysoft/redis 拷貝配置文件,順便命名爲 single.conf

cp /home/redis/redis-5.0.4/redis.conf single.conf
修改配置文件,把 redis 啓動改成後臺啓動

編輯 /home/redis/redis-5.0.4/single.conf

鍵入 ctrl+F 進行搜索,找到 daemonize no,把 no 改爲 yes ,鍵入 ctrl+S 保存即可。

[root@VM_147_31_centos redis-5.0.4]# cp /home/redis/redis-5.0.4/redis.conf single.conf
[root@VM_147_31_centos redis-5.0.4]# vi /home/redis/redis-5.0.4/single.conf
[root@VM_147_31_centos redis-5.0.4]#
[root@VM_147_31_centos redis-5.0.4]# grep daemonize /home/redis/redis-5.0.4/single.conf
#Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
#When the server runs non daemonized, no pid file is created if none is
#specified in the configuration. When the server is daemonized, the pid file
output for logging but daemonize, logs will be sent to /dev/null
[root@VM_147_31_centos redis-5.0.4]# pwd
/home/redis/redis-5.0.4
[root@VM_147_31_centos redis-5.0.4]#

啓動 redis-server
cd src

./redis-server ../single.conf

查看redis是否正常啓動
ps aux|grep redis

[root@VM_147_31_centos redis-5.0.4]# cd src
[root@VM_147_31_centos src]# ./redis-server ../single.conf
28677:C 13 Nov 2019 17:56:42.855 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28677:C 13 Nov 2019 17:56:42.855 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=28677, just started
28677:C 13 Nov 2019 17:56:42.855 # Configuration loaded
[root@VM_147_31_centos src]# ps -ef | grep redis
root 28678 1 0 17:56 ? 00:00:00 ./redis-server 127.0.0.1:6379
root 28700 22792 0 17:56 pts/0 00:00:00 grep --color=auto redis
[root@VM_147_31_centos src]#

測試試驗

使用 redis-cli 客戶端連接本機 redis
./redis-cli -h 127.0.0.1 -p 6379
設值
set test 123456
獲取值
get test

[root@VM_147_31_centos src]# ./redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set test 123456docker19.3
OK
127.0.0.1:6379> get test
"123456docker19.3"
127.0.0.1:6379> exit
[root@VM_147_31_centos src]#

[root@VM_147_31_centos bin]# pwd
/usr/local/mysoft/redis/bin
[root@VM_147_31_centos bin]# ll
total 32700
-rwxr-xr-x 1 root root 4366640 Nov 13 17:53 redis-benchmark
-rwxr-xr-x 1 root root 8101312 Nov 13 17:53 redis-check-aof
-rwxr-xr-x 1 root root 8101312 Nov 13 17:53 redis-check-rdb
-rwxr-xr-x 1 root root 4806872 Nov 13 17:53 redis-cli
lrwxrwxrwx 1 root root 12 Nov 13 17:53 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 8101312 Nov 13 17:53 redis-server
[root@VM_147_31_centos bin]# ./redis-cli -v
redis-cli 5.0.4
[root@VM_147_31_centos bin]#

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章