1、下载安装包:
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
2、解压安装包,放于redis的安装目录下
tar -zxvf redis-4.0.9.tar.gz -C /usr/local/redis
3、进入安装目录下的redis-4.0.9
cd /usr/local/redis/redis-4.0.9
4、编译前需要的环境安装,如果有了就不用再安装了
yum -y install gcc gcc-c++ kernel-devel
5、编译
make PREFIX=/usr/local/redis install (PREFIX指定安装路径)
mkdir /usr/local/redis/etc
6、创建redis.conf配置文件
cp /usr/local/redis/redis-4.0.9/redis.conf /usr/local/redis/etc/
7、将redis-cli、redis-server、redis-benchmark复制到/usr/bin下
cd /usr/local/redis/bin/
cp redis-benchmark redis-cli redis-server /usr/bin/
8、修改/usr/local/redis/etc/下redis启动的配置文件
# redis以守护进程的方式运行,不占用终端
daemonize yes
# 客户端闲置多长时间后断开连接,默认为0关闭此功能
timeout 300
# 设置redis日志级别,默认级别:notice
loglevel verbose
# 设置日志文件的输出方式,如果以守护进程的方式运行redis 默认:""
# 并且日志输出设置为stdout,那么日志信息就输出到/dev/null里面去了
logfile stdout
# 设置密码授权,连接访问信息时需要auth认证
requirepass 666666
# 监听ip
bind 127.0.0.1
9、配置环境变量,使service能发现redis
vim /etc/profile
export PATH="$PATH:/usr/local/redis/bin" (新增一行)
wq!
# 让环境变量立即生效
source /etc/profile
10、配置启动脚本,并给脚本增加运行权限
vim /etc/init.d/redis
#!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/etc/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 does not exist, 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|force-reload}" >&2
exit 1
esac
chmod 755 /etc/init.d/redis
11、开机自启动设置
# 添加服务
chkconfig redis on
# 查看服务列表
chkconfig --list
# 配置启动级别,自启动服务的先后启动顺序
chkconfig --level 2345 redis on (这一步可有可无)
12、启动关闭测试
service redis start 或者 systemctl start redis #或者 /etc/init.d/redis start
service redis stop 或者 systemctl stop redis #或者 /etc/init.d/redis stop
13、端口查看ip连接情况
netstat -an|grep 6379
14、redis本地连接远程redis
开放安全组相应入方向端口
防火墙打开下执行firewall-cmd --permanent --zone=public --add-port=6379/tcp打开redis连接端口
重启防火墙service firewalld reload
redis.conf中的bind-ip删掉,不然若指定ip则只能让指定ip连接到
亲测成功!
希望能对诸位有帮助!