Centos7安装Redis并设置远程访问

下载安装文件
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
安装编译器
yum install gcc-c++
Redis安装文件复制到/usr/local/src目录下,进入/usr/local/src目录下,解压redis安装文件
cd /usr/local/src
tar -xzvf redis-4.0.2.tar.gz
进入解压后的文件目录,之后直接编译即可
cd /usr/local/src/redis-4.0.2

make
创建存储redis文件目录,复制redis-server redis-cli到新建立的文件夹
mkdir -p /usr/local/redis
cp /usr/local/src/redis-4.0.2/src/redis-server /usr/local/redis/
cp /usr/local/src/redis-4.0.2/src/redis-cli /usr/local/redis/
设置Redis开机自动启动
进入/usr/local/src/redis-4.0.2的util目录, 执行./install_server.sh
[root@localhost 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] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
# 这个写你新建的那个目录的redis-server
Please select the redis executable path [] /usr/local/redis/redis-server
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/redis/redis-server
Cli Executable : /usr/local/redis/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!
Starting Redis server...
Installation successful!
查看Redis进程
ps -ef|grep redis
Redis开启远程访问
# 查找Redis配置(注意不是安装目录下的redis.conf)
# 打开第五步设计的Redis配置,默认为:/etc/redis/6379.conf
# 修改配置文件如下几项,其它保持不变
daemonize yes
#bind 127.0.0.1 (注释,不限制IP)
protected-mode no
将 requirepass foobared前的“#”去掉,密码改为你想要设置的密码(我设置为123456)

# 重启服务
[root@172 redis-3.2.11]# service redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...

# 开放6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 重启防火墙,否则开放端口不起作用
firewall-cmd --reload
创建redis命令软连接
ln -s /usr/local/redis/redis-cli /usr/bin/redis
# 这样就可以输入进入redis进行控制台了
[root@localhost ~]# redis
127.0.0.1:6379> auth "123456"
OK
127.0.0.1:6379> 

关闭redis服务
service redis_6379 stop
Stopping ...
OK
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...

## 报错
解决方法:修改redis服务脚本,加入如下所示的信息即可:
vim /etc/init.d/redis_6379
# 修改 添加 -a "password"
$CLIEXEC -a "123456" -p $REDISPORT shutdown
# 关闭redis服务
[root@localhost init.d]# service redis_6379 stop
Stopping ...
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Redis stopped
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值