1 下载
官网地址: https://redis.io/download
历史版本下载: http://download.redis.io/releases/
Windows 版本: https://github.com/tporadowski/redis/releases
CSDN-Windows版本地址: https://download.csdn.net/download/qq_15769939/15039183
CSDN-Linux版本地址: https://download.csdn.net/download/qq_15769939/15039008
2 安装redis
2.1 上传文件到服务器
[root@localhost ~]# cd /opt/module/software
[root@localhost software]# ll
-rw-r--r--. 1 root root 1975750 2月 4 10:20 redis-5.0.5.tar.gz
[root@localhost software]# tar -zxvf redis-5.0.5.tar.gz
[root@localhost software]# ll
drwxrwxr-x. 6 root root 4096 5月 16 2019 redis-5.0.5
-rw-r--r--. 1 root root 1975750 2月 4 10:20 redis-5.0.5.tar.gz
2.2 安装GCC编译环境
[root@localhost software]# yum install gcc-c++
2.3 编译安装
[root@localhost software]# cd /opt/module/software/redis-5.0.5
[root@localhost redis-5.0.5]# make && make install
3 配置Redis
3.1 拷贝脚本文件
[root@localhost redis-5.0.5]# cd /opt/module/software/redis-5.0.5/utils
[root@localhost utils]# cp redis_init_script /etc/init.d
[root@localhost utils]# mkdir /usr/local/redis -p
[root@localhost utils]# cd /usr/local/redis/
[root@localhost redis]# mkdir working
3.2 自定义配置文件
[root@localhost utils]# cd /opt/module/software/redis-5.0.5
[root@localhost redis-5.0.5]# cp redis.conf /usr/local/redis
[root@localhost redis-5.0.5]# vi /usr/local/redis/redis.conf
3.2.1 设置redis启动在后台运行
将 daemonize no
修改为 daemonize yes
################################# GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
3.2.2 修改redis工作目录
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /usr/local/redis/working
3.2.3 设置远程访问(不限制IP)
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0
3.2.4 设置密码
默认没有密码
,需要配置指定
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass auskat
3.3 修改脚本文件
[root@localhost redis-5.0.5]# vi /etc/init.d/redis_init_script
CONF="/usr/local/redis/${REDISPORT}.conf"
[root@localhost redis-5.0.5]# mv /usr/local/redis/redis.conf /usr/local/redis/6379.conf
3.4 授权并启动
[root@localhost redis-5.0.5]# cd /etc/init.d/
[root@localhost init.d]# chmod 777 redis_init_script
[root@localhost init.d]# ./redis_init_script start
Starting Redis server...
12217:C 04 Feb 2021 10:42:30.639 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12217:C 04 Feb 2021 10:42:30.639 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12217, just started
12217:C 04 Feb 2021 10:42:30.639 # Configuration loaded
[root@localhost init.d]# ps -ef | grep redis
root 12218 1 0 10:42 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 12223 7622 0 10:42 pts/3 00:00:00 grep --color=auto redis
3.5 设置开机自启动
[root@localhost redis-5.0.5]# vi /etc/init.d/redis_init_script
#chkconifg: 22345 10 90
#description: Start and stop redis
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a auskat -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
$CLIEXEC -a auskat -p $REDISPORT shutdown
增加停止的密码验证
chkconfig redis_init_script on
4 常用命令
redis-cli -a password shutdown :关闭redis
./redis_init_script stop :关闭redis
redis-cli :进入到redis客户端
auth pwd :输入密码
set key value :设置缓存
get key :获得缓存
del key :删除缓存
redis-cli -a password ping :查看是否存活
5 相关信息
- 博文不易,辛苦各位猿友点个关注和赞,感谢