1. 程式人生 > 資料庫 >CentOS7 安裝Redis-6.0.9

CentOS7 安裝Redis-6.0.9

1. su root進入root模式

2. 安裝gcc套裝:

yum install cpp
yum install binutils
yum install glibc
yum install glibc-kernheaders
yum install glibc-common
yum install glibc-devel
yum install gcc
yum install make

升級gcc

yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

設定永久升級:

echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

 3. 下載壓縮包

用wget指令: wget http://download.redis.io/releases/redis-6.0.9.tar.gz 

當然如果你想下載最新版,去官網看一下最新版的版本號,更改下就可以

4.解壓安裝包

tar -zxvf redis-6.0.9.tar.gz

 

 5.cd切換到redis解壓目錄下,執行編譯

cd redis-6.0.9/
make
 

 6. 安裝並指定安裝目錄

make install PREFIX=/usr/local/redis

7. 前臺啟動

cd /usr/local/redis/bin/
./redis-server

 

8. 後臺啟動

從 redis 的原始碼目錄中複製 redis.conf 到 redis 的安裝目錄

這個原始碼目錄就是你解壓的目錄,然後需要進入root模式

su root
cp redis.conf /usr/local/redis/bin/
cd /usr/local/redis/bin/

 9. 修改配置檔案

 vi redis.conf

鍵盤輸入:進入命令模式

命令模式下輸入 /字串,就可以快速查詢字串,將把 daemonize no 改為 daemonize yes

按insert鍵就可以進行改寫,Esc退出編輯模式

然後輸入wq儲存退出

10. 後臺啟動

./redis-server redis.conf

可以通過ps命令檢視是否有該程序

ps -ef|grep redis

 

11. 設定開機啟動

新增開機啟動服務

 vi /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

注意:ExecStart配置成自己的路徑 。

設定開機啟動

systemctl daemon-reload

systemctl start redis.service

systemctl enable redis.service

建立 redis 命令軟連結

ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

服務操作命令

systemctl start redis.service   #啟動redis服務

systemctl stop redis.service   #停止redis服務

systemctl restart redis.service   #重新啟動服務

systemctl status redis.service   #檢視服務當前狀態

systemctl enable redis.service   #設定開機自啟動

systemctl disable redis.service   #停止開機自啟動

使用 (也可以在redis目錄下用 ./redis-server redis.conf 啟動):

 

參考(是個小禿頭):