Linux 安装 Redis
本例子在 redis-5.0.5.tar.gz
中测试成功
安装
# 下载
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
# 解压
tar -zxvf redis-5.0.5.tar.gz
# 进入解压目录
cd redis-5.0.5/
# 指定目录并安装,服务被安装在 /home/shaw/server/redis5 中
make PREFIX=/home/shaw/server/redis5 install
# 测试是否安装成功
make test
# 删除解压缩文件
cd ../
rm -rf redis-5.0.5/
启动运行
# 使用指定的 Redis 配置文件进行运行
/home/shaw/server/redis5/bin/redis-server /home/shaw/server/redis5/redis.conf
常用配置(redis.conf)
允许外网访问
注释掉 bind 127.0.0.1
即可
################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ 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 127.0.0.1
开启守护进程(后台运行)
设置 daemonize yes
即可
# 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 no
设置密码
取消 requirepass foobared
注释,并将 foobared
修改为自己期望的密码即可;
################################## 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
使用 redis 自带工具配置 Redis
shaw@shaw-pc:~/server/redis-install/utils$ cd /home/shaw/server/redis-install/
shaw@shaw-pc:~/server/redis-install$ cd utils/
shaw@shaw-pc:~/server/redis-install/utils$ sudo su
root@shaw-pc:/home/shaw/server/redis-install/utils#
root@shaw-pc:/home/shaw/server/redis-install/utils# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /home/shaw/server/redis5/635^C
root@shaw-pc:/home/shaw/server/redis-install/utils# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /home/shaw/server/redis5/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /home/shaw/server/redis5/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /home/shaw/server/redis5/6379
Please select the redis executable path [] /home/shaw/server/redis5/bin/redis-server
Selected config:
Port : 6379
Config file : /home/shaw/server/redis5/6379.conf
Log file : /home/shaw/server/redis5/redis_6379.log
Data dir : /home/shaw/server/redis5/6379
Executable : /home/shaw/server/redis5/bin/redis-server
Cli Executable : /home/shaw/server/redis5/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Success!
Starting Redis server...
Installation successful!
redis-cli
连接服务
redis-cli -h localhost -p 6379 -a myredispassword