Redis的安裝與開機自啟動

1.檢查安裝依賴程序

//安裝需要的運行環(huán)境,防止安裝出錯

yum -y install gcc automake autoconf libtool make

yum install gcc-c++

yum install -y tcl

2.獲取安裝文件

mkdir /www

cd /www

#獲取安裝文件

wget http://download.redis.io/releases/redis-5.0.7.tar.gz

#解壓?

tar -xvf redis-5.0.7.tar.gz

3.進(jìn)入目錄、編譯、安裝

cd /www/redis-5.0.7/

make test

make

cd??/www/redis-5.0.7/src

make PREFIX=/www/redis install

cp /www/redis-5.0.7/redis.conf /www/redis

mkdir /www/redis/log

4.修改配置文件

#開啟后臺啟動

lmonize yes (no -> yes)

# 你可以綁定單一接口,注掉,可以允許任何機器訪問

# bind 127.0.0.1

#設(shè)置redis連接密碼,配置了連接密碼,客戶端在連接redis時需要通過auth 123465 命令提供密碼,

#requirepass 123456

#設(shè)置模式非保護(hù)模式,

protected-mode no

#數(shù)據(jù)存放路徑,rdb存放的路徑

dir /usr/local/redis/log

#指定持久化方式,

appendonly yes

5.創(chuàng)建服務(wù)啟動配置文件

vi /lib/systemd/system/redis.service

[Unit]

Description=Redis

After=network.target

[Service]

Type=forking

PIDFile=/var/run/redis_6379.pid

ExecStart=/www/redis/bin/redis-server /www/redis/redis.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

[Install]

WantedBy=multi-user.target

創(chuàng)建軟連接

ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service

剛剛配置的服務(wù)需要讓systemctl能識別,就必須刷新配置

systemctl daemon-reload

redis服務(wù)加入開機啟動

systemctl enable redis

6.常用命令集合

禁止開機啟動

systemctl disable redis

啟動

systemctl start redis

重啟

systemctl restart redis

停止

systemctl stop redis

查看狀態(tài)

systemctl status redis

啟動Redis

/www/redis/bin/redis-server /www/redis/redis.conf

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容