CentOS7 安裝Redis5.0.5

1.找到最新穩定版(當前5.0.5)

redis官網鏈接: https://redis.io

進入Download可以界面可以看到有Unstable,Stable,Docker三個版本,由於本人是測試所以選擇的是Stable穩定版。

Redis版本遵循第二位偶數版爲穩定版,選擇的時候可以根據當前場景選擇。

下面爲redis官網介紹redis5.0的改動

Redis 5.0 is the first version of Redis to introduce the new stream data type with consumer groups, sorted sets blocking pop operations, LFU/LRU info in RDB, Cluster manager inside redis-cli, active defragmentation V2, HyperLogLogs improvements and many other improvements. Redis 5 was release as GA in October 2018.

大概意思:
引入了新的流數據類型,包括用戶組、阻塞pop操作的排序集、rdb中的lfu/lru信息、redis cli中的cluster manager、active defragmentation v2、hyperlogloglogs改進和許多其他改進

以此輸入下面命令:

$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar -zxvf redis-5.0.5.tar.gz #解壓
$ cd redis-5.0.5 #進入目錄
$ make #編譯
$ cd src
$ make install PREFIX=/usr/local/redis #安裝到/usr/local/redis目錄
$ cd …
$ cp redis.conf /usr/local/redis/bin #將配置文件移動到/usr/local/redis/bin目錄

2.配置默認啓動(redis 默認不後臺啓動,需要配置)

$ cd /usr/local/redis/bin
$ vim redis.conf #將 daemonize的值改爲yes bind 127.0.0.1去掉(如果要遠 程訪問) protected-mode改爲 no
$ ./redis-server ./redis.conf #啓動

3.開機自啓動

centos 7以上是用Systemd進行系統初始化的,Systemd 是 Linux 系統中最新的初始化系統(init),它主要的設計目標是克服 sysvinit 固有的缺點,提高系統的啓動速度。
Systemd服務文件以.service結尾,比如現在要建立redis爲開機啓動,如果用yum install命令安裝的,yum命令會自動創建redis.service文件,直接用命令systemcel enable redis.service設置開機啓動即可

vim /etc/systemd/system/redis.service

加入一下內容

[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.target


先關閉redis-server

systemctl stop redis.service

開啓redis-server

systemctl start redis.service #如果服務是開啓狀態,使用此命令會啓動失敗。
systemctl enable redis.service #注意後面不能跟空格

重啓

reboot #重啓

查看服務運行狀態

systemctl status redis.service

常用命令

systemctl start redis.service #啓動redis服務
systemctl enable redis.service #設置開機自啓動
systemctl disable redis.service #停止開機自啓動
systemctl status redis.service #查看服務當前狀態
systemctl restart redis.service  #重新啓動服務
systemctl list-units --type=service #查看所有已啓動的服務

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