Lniux下Redis的源码安装应用及自启动配置

Redis版本 : 2.8.7

安装方式 :源码安装

官方文档建议使用源码方式安装,并使用  http://download.redis.io/redis-stable.tar.gz  一直指向最新的稳定版本。如果你只需要最新版本直接使用该地址即可。如果像我一样,需要指定版本,去Index of /releases/ 该仓库下找到对应的tar.gz下载链接即可。

PS:Redis has no dependencies other than a working GCC compiler and libc。
redis是C语言编写,因此需要有GCC依赖

 1、安装

yum install -y gcc
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install PREFIX=/usr/local/redis

使用:

以上redis已经安装成功了,并指定安装目录为 /usr/local/redis,实际在 /usr/local/redis/bin目录下访问 redis-server 程序已经能够启动了,但此时还只能前台启动,我们需要改变一些配置使得redis满足我们的应用使用。

PS: 

This is perfectly fine if you are starting Redis just to play a bit with it or for development, but for production environments you should use a configuration file.

You should use the redis.conf file included in the root directory of the Redis source code distribution as a template to write your configuration file.

        不带任何参数的启动服务,会直接使用默认配置参数,适用于开发环境,如果想要生产,就应该有一份自己的配置文件,而这份文件的模板可以使用源码中的 redis.conf       

2、修改 redis.conf

   默认模板从源码文件中的redis.conf复制一份出来即可。

cp /usr/local/redis/redis-stable/redis.conf /usr/local/redis/bin/

修改conf内容

#bind 127.0.0.1 -::1  注释该行(如果该行存在的话)

#bind 127.0.0.1 -::1

#protected-mode yes 将 yes 改为 no(如果该属性存在的话)
protected-mode no

#daemonize no 将 no 改为 yes (开启后台守护进程)
daemonize yes

#去除该行注释 ,并将foobared设置为一个自己的密码,此后该密码就是redis的验证密码
#requirepass foobared
requirepass 123456

        此时redis已经成为一个 后台进程、可远程连接、并且登陆密码为123456的权限很大的中间件了。请一定要保证生成环境的redis密码是复杂的。

(我出现了配置后还是不能远程访问的问题,此时判断一下服务器是否开通对应防火墙端口)

 默认情况下,redis没有任何监护(3.0之后应该不是了,3.2版后增加了 protected-mode,并bind回环地址访问),redis期望用户用很多安全措施去保证安全,比如指定端口监听,白名单路由绑定,密码设置,或者是使用spiped等SSL安全加密措施加密环境。

3、增加redis的的系统自启动配置

vi /etc/systemd/system/redis.service

复制以下文本粘贴进去

[Unit]

Description=redis-server

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf

PrivateTmp=true

[Install]

WantedBy=multi-user.target

保存后,重新加载系统

systemctl daemon-reload

systemctl start redis.service

systemctl enable redis.service

此时 redis 已经可以开机自启动了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值