84 lines
1.7 KiB
Markdown
Executable File
84 lines
1.7 KiB
Markdown
Executable File
# redis 安装配置
|
||
|
||
> https://redis.io/download
|
||
|
||
## 安装
|
||
|
||
``` bash
|
||
cd /srv
|
||
wget http://download.redis.io/releases/redis-4.0.1.tar.gz
|
||
tar xzf redis-4.0.1.tar.gz
|
||
cd redis-4.0.1
|
||
make
|
||
make test
|
||
```
|
||
|
||
## 配置
|
||
|
||
``` bash
|
||
sudo ln -s /srv/redis-4.0.1/src/redis-server /usr/local/bin/
|
||
sudo ln -s /srv/redis-4.0.1/src/redis-cli /usr/local/bin/
|
||
mkdir /etc/redis
|
||
cp /srv/redis-4.0.1/redis.conf /etc/redis
|
||
#修改redis.conf(/etc/redis下)
|
||
#打开后台运行选项
|
||
daemonize yes
|
||
#设置日志文件路径
|
||
logfile"/var/log/redis/redis.log"
|
||
```
|
||
|
||
> nano /etc/init.d/redis
|
||
|
||
``` bash
|
||
#!/bin/sh
|
||
# chkconfig: 2345 10 90
|
||
# description: Start and Stop redis
|
||
|
||
PATH=/usr/local/bin
|
||
REDISPORT=6379
|
||
EXEC=/usr/local/bin/redis-server
|
||
REDIS_CLI=/usr/local/bin/redis-cli
|
||
PIDFILE=/var/run/redis_6379.pid
|
||
CONF="/etc/redis/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
|
||
if [ "$?"="0" ]
|
||
then
|
||
echo "Redis is running..."
|
||
fi
|
||
;;
|
||
stop)
|
||
if [ ! -f $PIDFILE ]
|
||
then
|
||
echo "$PIDFILE exists, process is not running."
|
||
else
|
||
PID=$(cat $PIDFILE)
|
||
echo "Stopping..."
|
||
$REDIS_CLI -p $REDISPORT SHUTDOWN
|
||
while [ -x $PIDFILE ]
|
||
do
|
||
echo "Waiting for Redis to shutdown..."
|
||
sleep 1
|
||
done
|
||
echo "Redis stopped"
|
||
fi
|
||
;;
|
||
restart|force-reload)
|
||
${0} stop
|
||
${0} start
|
||
;;
|
||
*)
|
||
echo "Usage: /etc/init.d/redis {start|stop|restart|fore-reload}"
|
||
exit 1
|
||
esac
|
||
|
||
```
|