redis官網上給出了安裝步驟,這里做一下總結。
1、Download, extract and compile Redis with:
wget http://download.redis.io/releases/redis-5.0.2.tar.gz tar -zxvf redis-5.0.2.tar.gz cd redis-5.0.2 yum install -y gcc # 直接使用make命令會出現以下錯誤 fatal error: jemalloc/jemalloc.h: No such file or directory make MALLOC=libc # 直接make test會出現以下錯誤 You need tcl 8.5 or newer in order to run the Redis test # 解決方法 yum install -y tcl
make test
2、配置並啟動redis。
# 備份redis配置文件
cp redis.conf redis.conf.bak
a>配置reids為后台駐留程序。打開redis.conf,找到daemonize,可以看到reids默認情況下不是后台駐留程序。
# By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. # daemonize no
# 修改成:
daemonize yes
b-1>配置redis log文件路徑。
# Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null # logfile ""
# 修改為如下,意思為把log文件放在redis安裝目下logs/redis.log(要自己創建好目錄結構)
logfile "logs/redis.log"
b-2>配置db file location
# The working directory. # dir ./ dir /usr/local/redis-5.0.2/
c>配置redis遠程連接
#注釋掉所有bind 127.0.0.1 #bind 127.0.0.1 ::1 #bind 127.0.0.1 bind 0.0.0.0 #創建密碼 requirepass password
d>創建redis用戶
groupadd gredis useradd -r -g gredis -s /bin/false redis
e>修改redis目錄擁有者為redis:redis
chown -R redis:gredis ./
f>啟動redis
# redis3.x # 啟動redis。禁止使用root啟動!!!注意可能造成的文件的讀寫權限。 # 修改redis.conf文件后需指定配置文件路徑啟動 sudo -u redis src/redis-server ./redis.conf # redis客戶端連接命令 src/redis-cli -h 127.0.0.1 -p 6379 -a password
#
g>關閉redis
src/redis-cli shutdown # 強制關閉redis,找到redis進程號,kill掉。 netstat -anp | grep redis tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1132/src/redis-serv kill -9 1132
可能遇到的問題:
1、在執行src/redis-cli shutdown時報錯:“(error) ERR Errors trying to SHUTDOWN. Check logs.”。日志(上面配置了日志路徑)如下:
# User requested shutdown... * Saving the final RDB snapshot before exiting. # Failed opening the RDB file dump.rdb (in server root dir /usr/local/redis-3.2.9) for saving: Permission denied # Error trying to save the DB, can't exit.
解決方法:
You should check your redis.conf file to see the permissions in dir and dbfilename.
If the file named in the dbfilename which is located in the path specified in the
dir path exists and the permission is also right. then the problem should be fixed. Hope this will help someone. P.S. To find the redis.conf file location, you can use the #ps ax | grep redis to check.
Usually it will be passed to the redis-server as input file. For the dir permissions:it should be 755, for the dbfilename, it should be 644 Sometimes you also need to use top command to check whether the user:group of
the redis-server and the owner of dir are consistent.
i.e. The redis-server is running by redis:redis, but the dir is under root:root.
In this case, you need to chown redis:redis -R dir.
QQ技術交流群:282575808
--------------------------------------
聲明: 原創文章,未經允許,禁止轉載!
--------------------------------------