下载最新版本
以3.2.8为例,附上地址:redis-3.2.8.tar.gz
解压,编译,安装redis
- 解压:
tar -zxvf redis-3.2.8.tar.gz
- 进入目录:
cd redis-3.2.8
- 编译:
make && make install
- 创建相关目录:
mkdir -p /opt/redis-3.2.8/bin
mkdir -p /opt/redis-3.2.8/log
mkdir -p /opt/redis-3.2.8/pid
mkdir -p /opt/redis-3.2.8/db
- 将编译后的可执行文件复制到自己的安装目录:
ln -s /usr/local/bin/redis-* /opt/redis-3.2.8/bin
- 复制配置文件到安装目录:
cp redis.conf /opt/redis-3.2.8/
配置redis
- 编辑redis.conf:
cd /opt/redis-3.2.8
,vi redis.conf
- redis默认只允许本机连接,所以注释掉这行配置就可以远程访问:
\# bind 127.0.0.1
- redis3.0版本增加了保护模式,需要我们设置密码,如果不想设置密码,就关闭保护模式:
protected-mode no
- 设置redis以守护线程方式启动:
daemonize yes
- 配置pid,log,db文件的保存地址:
- redis默认只允许本机连接,所以注释掉这行配置就可以远程访问:
pidfile /opt/redis-3.2.8/pid/redis.pid
logfile /opt/redis-3.2.8/log/redis.log
dir /opt/redis-3.2.8/db
其他配置就默认即可,有需要再自行修改
- 编写redis启动脚本:
vi /etc/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
PATH=/opt/redis-3.2.8/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/opt/redis-3.2.8/bin/redis-server
CLIEXEC=/opt/redis-3.2.8/bin/redis-cli
PIDFILE=/opt/redis-3.2.8/pid/redis.pid
CONF="/opt/redis-3.2.8/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
- 设置服务权限:
chmod a+x /etc/init.d/redis
相关使用
- 启动:
service redis start
- 关闭:
service redis stop
- 查看:
ps -ef | grep redis
,netstat -anptu | grep 6379
作者:Joepis
链接:https://www.jianshu.com/p/1650f45109b3
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。