mynote/redis/配置.md
2018-09-30 14:47:03 +08:00

93 lines
1.9 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
```
## docker
``` bash
docker pull redis
mkdir /db/redis/
docker run -p 127.0.0.1:6379:6379 --name myredis -v /db/redis/:/data -d redis redis-server --appendonly yes --requirepass "abc123456"
```