ubutnu18.04安装Redis
安装redis服务端
# apt-get install redis-server
检查Redis服务器系统进程
# ps -agx|grep redis
13614 ? Ssl 0:00 /usr/bin/redis-server 127.0.0.1:6379
13746 pts/6 S+ 0:00 grep --color=auto redis
查看redis默认端口
# netstat -nlt|grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
tcp6 0 0 ::1:6379 :::* LISTEN
通过启动命令检查Redis服务器状态
# /etc/init.d/redis-server status
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-07-13 12:55:35 CST; 14min ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 13614 (redis-server)
Tasks: 4 (limit: 4915)
CGroup: /system.slice/redis-server.service
└─13614 /usr/bin/redis-server 127.0.0.1:6379
7月 13 12:55:34 master systemd[1]: Starting Advanced key-value store...
7月 13 12:55:35 master systemd[1]: redis-server.service: Can't open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory
7月 13 12:55:35 master systemd[1]: Started Advanced key-value store.
命令行客户端访问Redis
# redis-cli
127.0.0.1:6379> help
redis-cli 4.0.9
To get help about Redis commands type:
"help @<group>" to get a list of commands in <group>
"help <command>" for help on <command>
"help <tab>" to get a list of possible help topics
"quit" to exit
To set redis-cli preferences:
":set hints" enable online hints
":set nohints" disable online hints
Set your preferences in ~/.redisclirc
修改Redis的配置
默认情况下,访问Redis服务器是不需要密码的,为了增加安全性我们需要设置Redis服务器的访问密码。这里我设置密码为root506
# vim /etc/redis/redis.conf
#取消注释requirepass
requirepass root506
让Redis服务器被远程访问
# vim /etc/redis/redis.conf
#注释bind
#bind 127.0.0.1
之后重启redis
# /etc/init.d/redis-server restart
不使用密码登录redis
可以登录,但无法执行命令
# redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
使用密码登录后,一切正常
# redis-cli -a root506
127.0.0.1:6379> keys *
1) "key1"
检查端口发现由127.0.0.1变为0.0.0.0,表示可以远程登录
# netstat -nlt|grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
tcp6 0 0 :::6379 :::* LISTEN
另一台机器登录
# redis-cli -a root506 -h 192.168.1.11
192.168.1.11:6379> keys *
1) "key1"
192.168.1.11:6379>