1. 下载上传解压
1.1下载
1.2 上传
$ rz redis-5.0.14.tar.gz
1.3 解压编译安装
$ tar -zvxf redis-5.0.14.tar.gz
$ cd redis-5.0.14
$ make
$ make PREFIX=/usr/local/redis/redis-5.0.14 install
2. 启动
$ cd redis-5.0.14
$ ./bin/redis-server& ./redis.conf
3. 配置
- 编辑redis.conf配置文件
3.1 配置环境变量
$ vim /etc/profile
export PATH=$PATH:/usr/local/redis/redis-5.0.14/src
$ source /etc/profile
在任意地方 输入 redis-server 或 redis-cli 即可使用redis
3.2 开启守护线程
daemonize 改为 yes ;
3.3 允许远程访问
protected-mode 改为 no
bind 127.0.0.1 改为 bind *
4. 端口开放
$ firewall-cmd --add-port=6379/tcp --permanent
$ firewall-cmd --reload
5. 作为服务启动
定位到redis的tar包所在位置,将redis中的utils中的redis_init_script复制到/etc/rc.d/init.d中,重命名为redis
cp /{redis解压包所在目录}/utils/redis_init_script /etc/rc.d/init.d/redis
vi /etc/rc.d/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/home/flying/program/redis-5.0.14/bin/redis-server #实际环境而定
CLIEXEC=/home/flying/program/redis-5.0.14/bin/redis-cli #实际环境而定
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/home/flying/download/redis-5.0.14/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 755 /etc/init.d/redis
$ chkconfig redis on # 开启服务自启动
$ service redis start #启动redis
$ service redis stop #关闭redis
$ reboot
$ ps -fe | grep redis #检查是否启动