Redis啟動
1. 前台啟動(不推薦)
前台啟動,指令行視窗不能關閉,否則伺服器停止
(1) 進入到redis的/usr/local/bin目錄下, 執行 redis-service
(2) Ctrl+c退出
2. 背景啟動(推薦)
(1) 備份redis.conf 拷貝一份redis.conf到其他目錄
cp /opt/redis-3.2.5/redis.conf /myredis
(2) 背景啟動設定daemonize no改成yes
修改redis.conf(128行)檔案将裡面的daemonize no 改成 yes,讓服務在背景啟動
(3) Redis啟動
redis-server /myredis/redis.conf
(4) 用用戶端通路:redis-cli
(5) 測試驗證: ping
(6) Redis關閉
① 單執行個體關閉:redis-cli shutdown
② 也可以進入終端後再關閉
多執行個體關閉,指定端口關閉:redis-cli -p 6379 shutdown
3. 設定開機啟動
(1) 在redis的安裝目錄下找到install_server.sh檔案
/opt/redis-6.2.1/utils/install_server.sh
(2) 執行檔案
./install_server.sh
(3) 如果報錯
Welcome to the redis service installer
This script will help you easily set up a running redis server
This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
修改install_server.sh檔案
注釋下面的代碼即可
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi
然後重新運作 ./install_server.sh即可。
最終在/etc/init.d目錄下生成了一個redis_6379的檔案,這就是我們的服務啟動的腳本檔案
(4) 進入/etc/init.d目錄。通過mv指令進行修改:mv /etc/init.d/redis_6379 /etc/init.d/redisd
(5) 開機自啟動。隻需執行一條指令格式為:
(chkconfig --add 服務名稱)chkconfig --add redisd
(6) 啟動redis服務
systemctl start redisd 格式:(systemctl start 服務名稱)
(7) 重新整理配置或重新開機
systemctl daemon-reload