Centos7安装Redis并设置远程访问
  Gmus5gIMInPU 2023年11月13日 16 0


下载安装文件

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


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  nQkVcpdWfLDr   2023年11月13日   16   0   0 DesktopSystem重启
  3M67F8YJLxn2   2023年11月13日   71   0   0 重启
Gmus5gIMInPU