Content
0. Order
1. How to install?
2. Configuration parameters and their significance
3. Set as Linux service
0. Order
This article mainly records the installation configuration of Redis under CentOS. If not specifically stated in this article. Represents the redis-3.2.10 code directory.
1. How to Install
2. configuration parameters and their significance
Modifying a configuration file vi/usr/local/redis/etc/redis.conf
123456789101112131415161718192021222324252627282930 |
#是否只允许本机客户端连接,这样可以避免将redis服务暴露于危险的网络环境中
bind 127.0.0.1
#是否以守护进程方式运行
daemonize
yes
#pid文件位置
pidfile
/usr/local/redis/var/run/redis_6379
.pid
#监听端口
port 6379
#请求超时时间
timeout 0
#是否为长连接,非 0时为长连接
tcp-keepalive 300
#log信息级别
loglevel notice
#log位置
logfile
/usr/local/redis/log/redis
.log
#开启数据的数量
databases 16
#保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件
save * *
#是否使用压缩
rdbcompression
yes
#数据快照文件名(只是文件名,不包括目录)
dbfilename dump.rdb
#数据快照保存目录
dir /usr/local/redis/data/
#是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。
appendonly no
#如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步)
appendfsync everysec
|
3. Set as Linux service
Copy the Redis service script file to the/ETC/RC.D/INIT.D directory;
1 |
$ cp . /utils/redis_init_script /etc/rc .d /init .d /redis |
Modify the Redis service script, Vi/etc/rc.d/init.d/redis; modified/etc/rc.d/redis as follows:
12345678910111213141516171819202122232425262728293031323334353637383940414243 |
#!/bin/sh
#
# chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=
/usr/local/redis/bin/redis-server
CLIEXEC=
/usr/local/redis/bin/redis-cli
PIDFILE=
/usr/local/redis/var/run/redis_
${REDISPORT}.pid
CONF=
"/usr/local/redis/etc/redis.conf"
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/
${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac |
Add the/etc/rc.d/init.d/redis script to the service with the following command:
Set boot up
PHP Installation Configuration