分布式系统-基础篇-CentOS7 安装redis3.2并设置开机启动
1、解压redis
$:tar -zxvf Downloads/redis-3.2.4.tar.gz -C /usr/local/
2、重命名
$:mv /usr/local/redis-3.2.4/ /usr/local/redis3.2
3、编译
$ make /usr/local/redis-3.2.4/
4、启动redis3.2
$./src/redis-server
关闭进程:$ kill -9
5、打开客户端
$./src/redis-cli
退出客户端:$:quit
6、设置开机启动
1、拷贝: $ cp /usr/local/redis3.2/utils/redis_init_script /etc/init.d/redis
2、编辑:$ vi /etc/init.d/redis
3、复制:
# chkconfig: 2345 90 10
# description: Start and Stop redis
到/etc/init.d/redis 文件,并放到头部
4、修改对应:路径(主要是redis的安装路径)/usr/local/redis3.2/src/redis-server
EXEC=/usr/local/redis3.2/src/redis-server
CLIEXEC=/usr/local/redis3.2/src/redis-cli
5、创建/etc/redis文件夹, $ mkdir /etc/redis
6、到这个我们需要拷贝一下redis.conf文件到/etc/redis目录下
$ cp /usr/local/redis3.2/redis.conf /etc/redis/6379.conf
7. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
daemonize no
8、配置权限:$ chmod +x /etc/init.d/redis
9、设置开机启动:chkconfig redis on
10、手动启动:service redis start,手动关闭:service redis stop
11、开启6379端口:$: firewall-cmd --zone=public --add-port=6379/tcp --permanent
12、重启防火墙:$ systemctl restart firewalld.service
13、绑定 vi /etc/redis/6379.conf (不绑定ip将无法远程访问)
$:bind 192.168.83.136
附件 /etc/init.d/redis 配置文件:
# chkconfig: 2345 90 10
# descriptio: Star=/usr/local/redis3.2/src/redis-server
CLIEXEC=/usr/local/redis3.2/src/redis-cli
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis3.2/src/redis-server
CLIEXEC=/usr/local/redis3.2/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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