Centos Linux 系统部署java程序(四、Redis的安装和部署)
安装
安装非常简单,执行以下命令即可
[root@hcss-ecs-5eee labsys]# yum install -y redis
配置
常用的配置是3个地方,当然不常用的配置还有很多,后续将会把使用的心得体会总结成长篇文章让大家知道得更详细,目前我们只讲这3个基本的。
配置文件默认是 /etc/redis.conf
- 端口配置 端口号默认为6379。如需要修改,则在配置文件中找到port所在的位置,将port后的默认端口6379修改为你想要的端口号即可。
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
- 密码配置 默认是不使用密码的,如果需要认证密码,则在配置文件中找到requirepass的配置,手动增加一项,对应的值填上想要设置的密码,配置就改好了。
################################## 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 abc@123
- IP绑定配置 redis为了控制访问安全,设置了ip绑定,默认绑定的IP是127.0.0.1 ,也可以改为本机上其他网卡的地址,绑定之后,就只能通过该网卡的IP来访问。 也可以不设置该项,那么所有的能连上网的主机都能访问。
配置如下:
################################## 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