安装Redis

https://redis.io/

1.源码包安装
# tar -zxf redis-4.0.6.tar.gz -C /usr/local/
# cd /usr/local/ && mv redis-4.0.6 redis
# cd redis
# vim redis.conf, 修改如下:
bind 0.0.0.0 # 可以从任何IP访问
daemonize yes # 允许作为后台服务运行
# redis-server ./redis.conf
# ps -ef | grep redis
# redis-cli
127.0.0.1:6379> set key1 123456
OK
127.0.0.1:6379> get key1
"123456"
127.0.0.1:6379> exit


2.增加访问密码

# vim redis.conf 
requirepass bigdata
# redis-cli
127.0.0.1:6379> shutdown save # 关闭redis
not connected> exit
# ps -ef |grep redis
root       6410   2440  0 17:53 pts/0    00:00:00 grep --color=auto redis
# redis-server ./redis.conf # 启动redis
# redis-cli
127.0.0.1:6379> get key1
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth bigdata
OK
127.0.0.1:6379> get key1

"123456"


3.将redis设置成系统服务
# pwd
/usr/local/redis
# cd 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] /usr/local/redis/redis.conf
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/redis.log
Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/data
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /usr/local/redis/redis.conf
Log file       : /usr/local/redis/redis.log
Data dir       : /usr/local/redis/data
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/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...
Successfully added to chkconfig!
Successfully added to runlevels 345!
/var/run/redis_6379.pid exists, process is already running or crashed
Installation successful!
# chkconfig --list|grep redis
redis_6379     0:off 1:off 2:on 3:on 4:on 5:on 6:off
# systemctl status redis_6379
● redis_6379.service - LSB: start and stop redis_6379
   Loaded: loaded (/etc/rc.d/init.d/redis_6379)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
# systemctl stop redis_6379
# systemctl start redis_6379
# ps -ef|grep redis
root       6412      1  0 17:53 ?        00:00:00 redis-server 0.0.0.0:6379
root       6530   2440  0 18:03 pts/0    00:00:00 grep --color=auto redis
# vim /etc/init.d/redis_6379
# redis-cli # 测试使用
127.0.0.1:6379> auth bigdata
OK
127.0.0.1:6379> set key3 abc
OK
127.0.0.1:6379> get key3
"abc"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值