redis安装
下载地址:http://redis.io/download
官方安装教程:
$ wget http://download.redis.io/releases/redis-3.2.1.tar.gz
$ tar xzf redis-3.2.1.tar.gz
$ cd redis-3.2.1
$ make
执行完make之后,redis的可执行文件即生成完毕,在redis-3.2.1/src/redis-server。
再执行make install,可以将redis-server,redis-cli等命令放入/user/local/bin/。
然后将redis-3.2.1/redis.conf放入/etc/后,即可删除解压生成的redis-3.2.1文件夹。
redis启动命令:redis-server /etc/redis.conf
redis关闭命令:redis-cli -a passwd shutdown
redis配置文件:/etc/redis.conf
redis配置参考
bind
# 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.
# ZH:redis如果没有配置bind参数,那么他将监听服务端所有的网络接口。bind参数配置为指定IP地址可以实现监听服务端的一个或多个网络接口。
#
# 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 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
# ZH:redis服务端所有接口直接暴露在互联网上是危险的做法。所以我们默认配置为本机访问。
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ZH:如果你确定你的接口要监听服务端所有的网络接口,直接注释掉下一行。
bind 127.0.0.1
bind配置为监听本机网络接口地址。
例如:服务器有三个IP地址,127.0.0.1(本机IP),192.168.1.100(内网IP),10.10.10.10(公网IP)。
# 监听本机IP,本机能访问。
bind 127.0.0.1
# 监听内网IP,内网能访问。
bind 192.168.1.100
# 监听公网IP,公网能访问。
bind 10.10.10.10
# 监听多个IP,本机,内网,公网均能访问。
bind 127.0.0.1 192.168.1.100 10.10.10.10
# 监听本机所有网络接口
bind 0.0.0.0
# 配置文件提到如果监听本机所有网络接口,将bind注释掉,但是注释掉redis无法启动。所以如果要设置为监听本机所有的网络接口,设置为bind 0.0.0.0。
daemonize
# 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.
# ZH:redis默认运行方式非守护进程,当使用守护进程方式运行时,redis会产生一个pid文件/var/run/redis.pid。
daemonize no
requirepass
# 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.
# ZH:需要客户端验证密码,这在一个你不信任的环境里面很有用。
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 这个配置最好注释掉,因为大部分人不需要认证,因为他们在他们自己的服务器上架设的redis。
#
# 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.
# ZH:由于redis速度很快,客户端可以1秒尝试150k大小的密码,这意味着你最好拥有一个强壮的密码,否则很容易被人攻破。
requirepass foobared