阿里雲伺服器使用yum安裝redis,配置開機自啟
阿新 • • 發佈:2018-12-30
前言
自己買了個阿里雲伺服器,在安裝redis之後,想要將redis註冊為系統服務,並設定開機自啟,走了些彎路,但最終弄好,記錄下,也希望能幫到廣大碼農。
1.安裝gcc
如果沒有需要先進行安裝,使用一下命令,但一般阿里雲伺服器都會有
yum install cpp
2.安裝redis
去redis官網,https://redis.io/download,這步可以跟著官網的步驟走,隨意找個路徑。個人一般把安裝的包放在/usr/local/下
$ wget http://download.redis.io/releases/redis-4.0.11.tar.gz $ tar xzf redis-4.0.11.tar.gz $ cp redis-4.0.11 /usr/local/redis $ cd /usr/local/redis $ make
3.啟動redis
進入/redis/下,使用命令./src/redis-server就能啟動redis,然後使用命令./src/redis-cli登入redis
./src/redis-server --啟動redis
./src/redis-cli --登入redis
4.使用mkdir /etc/redis建立路徑,將/redis下的redis.conf複製到/etc/redis
[[email protected] utils]# mkdir /etc/redis [[email protected] redis]# cp redis.conf /etc/redis/6379.conf
使用vi /etc/redis/6379.conf找到daemonize no將其改為yes
5.將redis註冊為系統服務
進入/utils路徑,將redis_init_script複製到/etc/init.d/redisd
[[email protected] redis]# cd utils/
[[email protected] utils]# ll
total 76
-rw-rw-r-- 1 root root 593 Aug 4 06:44 build-static-symbols.tcl
-rw-rw-r-- 1 root root 1303 Aug 4 06:44 cluster_fail_time.tcl
-rw-rw-r-- 1 root root 1070 Aug 4 06:44 corrupt_rdb.c
drwxrwxr-x 2 root root 4096 Aug 4 06:44 create-cluster
-rwxrwxr-x 1 root root 2137 Aug 4 06:44 generate-command-help.rb
drwxrwxr-x 3 root root 4096 Aug 4 06:44 graphs
drwxrwxr-x 2 root root 4096 Aug 4 06:44 hashtable
drwxrwxr-x 2 root root 4096 Aug 4 06:44 hyperloglog
-rwxrwxr-x 1 root root 9567 Aug 4 06:44 install_server.sh
drwxrwxr-x 2 root root 4096 Aug 4 06:44 lru
-rw-rw-r-- 1 root root 1277 Aug 4 06:44 redis-copy.rb
-rwxrwxr-x 1 root root 1447 Sep 27 22:21 redis_init_script
-rwxrwxr-x 1 root root 1047 Aug 4 06:44 redis_init_script.tpl
-rw-rw-r-- 1 root root 1762 Aug 4 06:44 redis-sha1.rb
drwxrwxr-x 2 root root 4096 Aug 4 06:44 releasetools
-rwxrwxr-x 1 root root 3787 Aug 4 06:44 speed-regression.tcl
-rwxrwxr-x 1 root root 693 Aug 4 06:44 whatisdoing.sh
[ [email protected] utils]# ^C
[[email protected] utils]# cp redis_init_script /etc/init.d/redisd
修改/etc/init.d/redisd中的內容,將# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database新增在#!/bin/sh之下
[[email protected] utils]# vi /etc/init.d/redisd
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
6.新增開機啟動
chkconfig redisd on
7.啟動redis
service redisd start