centos安裝redis,開機自啟動

2021-10-08 03:35:52 字數 3207 閱讀 5982

我是伺服器小白!

1、安裝redis我選用的yum install redis

安裝成功之後測試啟動鏈結

[root@robot-release-1 ~]# redis-server

如下圖表示啟動成功

連線命令

[root@robot-release-1 ~]# redis-cli

如圖也可以

2、後台執行

更改配置檔案的

笨鳥都是先查一下配置檔案的位置

找到daemonize 預設是no 改為yes 儲存退出

驗證是否成功(注意:想要後台執行啟動時要帶配置檔案啟動,如下圖)

3、開機自啟動

網上找了很多,無非就兩種方式

第一種原始碼安裝自帶啟動指令碼

第二種自己寫指令碼

我只能選第二種,這個博主寫的挺詳細的

第一步:

[root@robot-release-1 ~]# vim /etc/init.d/redis

內容:

#!/bin/sh

#configurations injected by install_server below....

exec=/usr/bin/redis-server

cliexec=/usr/bin/redis-cli

pidfile=/run/redis_6379.pid

conf="/etc/redis.conf"

redisport="6379"

case "$1" in

start)

if [ -f $pidfile ]

then

echo "$pidfile exists, process is already running or crashed"

else

echo "starting redis server..."

$exec $conf

fi;;

stop)

if [ ! -f $pidfile ]

then

echo "$pidfile does not exist, process is not running"

else

pid=$(cat $pidfile)

echo "stopping ..."

$cliexec -p $redisport shutdown

while [ -x /proc/$ ]

doecho "waiting for redis to shutdown ..."

sleep 1

done

echo "redis stopped"

fi;;

status)

pid=$(cat $pidfile)

if [ ! -x /proc/$ ]

then

echo 'redis is not running'

else

echo "redis is running ($pid)"

fi;;

restart)

$0 stop

$0 start

;;*)

echo "please use start, stop, restart or status as first argument"

;;esac

其中比較重要的檔案配置位址要替換成自己本機的,我是這樣做的。

其中配置檔案名稱他的部落格寫的是6379.con  結果我個笨笨沒找到,後來爬樓看到自己之前該過配置檔案的路徑就替換上了。

儲存退出。

接著執行:

[root@robot-release-1 ~]# systemctl start redis

job for redis.service failed because the control process exited with error code. see "systemctl status redis.service" and "journalctl -xe" for details.

報錯了。。。。

我按照錯誤上面執行了那兩個命令,結果如下:

第乙個都沒看懂

還好第二個看出來說我

7月 15 17:40:06 robot-release-1 redis-server[19539]: >>> 'logfile /var/log/redis/redis.log'

7月 15 17:40:06 robot-release-1 redis-server[19539]: can't open the log file: permission denied

看懂了沒許可權

找到了這個帖子

其中說的這個檢視redis.service命令我也執行了,上面說使用者和分組都是redis

嗷~[root@robot-release-1 ~]# chown redis:redis /var/log/redis/redis.log

[root@robot-release-1 ~]# systemctl start redis

好了。

centos7 安裝redis並開機啟動

首先確認是否具有root許可權,因為vim 設定redis開機啟動需要root許可權 su wget io releases redis 3.2 8.tar gz解壓縮 tar xzf redis 3.2 8.tar gz進入解壓後的檔案目錄 cd redis 3.2.8redis安裝相對簡單 直接...

centos7安裝redis 後台開機啟動

一 安裝gcc依賴 yum install y gcc cd usr local wget tar zxvf redis 5.0.3.tar.gz三 安裝redis cd redis 5.0.3 make make test make installmake test 報錯 you need tcl...

centos7安裝redis設定開機啟動

centos7安裝redis設定開機啟動 sjhuangx 2018 03 20 22 43 56 14304 收藏 9 展開參考 wget tar xvzf redis 4.0.8.tar.gz 2.使用gcc進行編譯 make make test 編譯後的可執行檔案在redis 4.0.8 sr...