CentOS7安装redis源码包
-
安装
# 将redis压缩包上传到服务器/home/software,并解压
tar -zxvf redis-6.0.6.tar.gz
# 安装gcc
yum install gcc-c++ -y
# 查看版本
gcc -v
# 进入解压目录
cd redis-6.0.6
# 编译
make
# 安装(默认安装到/usr/local/bin,不建议默认安装)
# make install
# 指定安装路径安装(建议制定路径)
make install PREFIX=/usr/local/redis
# 当前在/home/software/redis-6.0.6目录
# 复制配置文件到安装目录
cp redis.conf /usr/local/redis/bin/
# 进入安装目录
cd /usr/local/redis/bin/
# 编辑
vim redis.conf
# 将6379端口放行
# 将daemonize no改为daemonize yes,允许后台启动
# 将protected-mode yes设置为protected-mode no,可远程连接
# 使用步骤
# 每次启动都必须进入安装目录
cd /usr/local/redis/bin
# 启动服务
[root@localhost bin]# ./redis-server redis.conf
26205:C 04 Dec 2023 00:27:33.617 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
26205:C 04 Dec 2023 00:27:33.617 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=26205, just started
26205:C 04 Dec 2023 00:27:33.617 # Configuration loaded
# 查看进程
[root@localhost bin]# ps aux|grep redis
root 26206 0.1 0.2 162420 2532 ? Ssl 00:27 0:00 ./redis-server 127.0.0.1:6379
root 26214 0.0 0.0 112828 984 pts/0 R+ 00:28 0:00 grep --color=auto redis
# 启动客户端,先启动服务
./redis-cli
# 退出
quit
# 关闭服务
./redis-cli shutdown
# 启动cli客户端报错:Could not connect to Redis at 127.0.0.1:6379: Connection refused
# 错误原因:redis.conf中bind 127.0.0.1 ::1 被修改或注释了,改为原样即可
- 卸载
cd /home/software
rm -rf redis-6.0.6
cd /usr/local
rm -rf redis
- 远程连接
# 开放端口
[root@localhost bin]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@localhost bin]# firewall-cmd --reload
success
# 修改/usr/local/redis/bin/redis.conf,protected-mode设置成no,允许远程连接
# 设置密码
requirepass redis123
# 将 bind 127.0.0.1 修改成 bind * -::*
# 或者直接将bind这一行注释掉
# 先关闭服务
./redis-cli shutdown
# 再启动服务
./redis-server redis.conf
# windows上打开cmd测试
telnet 192.168.128.80 6379
-
RedisClient连接,Server,Add
-
设置密码后连接
[root@localhost bin]# ./redis-cli -h 192.168.128.80 -p 6379 -a redis123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.128.80:6379> keys *
1) "aaa"
# 方式2
[root@localhost bin]# ./redis-cli
127.0.0.1:6379> auth redis123
# 否则报错:
[root@localhost bin]# ./redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
# 关闭服务
[root@localhost bin]# ./redis-cli -h 192.168.128.80 -p 6379 -a redis123 shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
[root@localhost bin]# ps aux|grep redis
root 26409 0.0 0.0 112828 984 pts/0 R+ 02:20 0:00 grep --color=auto redis
# 否则报错
[root@localhost bin]# ./redis-cli shutdown
(error) NOAUTH Authentication required.
查看详情
-
虚拟机上的redis设置密码后,redisclient输入密码连接成功
-
Tools,Console,输入命令,点击Run current,报错:NOAUTH Authentication required.
-
虚拟机上的redis未设置密码,redisclient不输入密码连接成功
-
Tools,Console,输入命令,点击Run current,报错如下