安装redis
下载fedora的epel仓库
yum install epel-release
安装redis数据库
yum install redis
启动redis
service redis start
显示redis运行状态
service redis status
至此已经安装完毕。
# 停止redis
service redis stop
# 查看redis进程
ps -ef | grep redis
#设置redis为开机自动启动
chkconfig redis on
#进入redis服务
redis-cli
# 列出所有key
keys *
#防火墙开放相应端口
# 开启6379/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT# 开启6380/sbin/iptables -I INPUT -p tcp --dport 6380 -j ACCEPT# 保存/etc/rc.d/init.d/iptables save# centos 7下执行service iptables save
#修改redis默认端口和密码
1.打开配置文件
vi /etc/redis.conf
2、修改默认端口,查找 port 6379 修改为相应端口即可
3、修改默认密码,查找 requirepass foobared 将 foobared 修改为你的密码
4、使用配置文件启动 redis
redis-server /etc/redis.conf &
5、使用端口登录
redis-cli -h 127.0.0.1 -p 6179
6、此时再输入命令则会报错
7、输入刚才输入的密码
auth 111
8、停止redis
命令方式关闭redis
[root@xxx ~]# redis-cli -h 127.0.0.1 -p 6379127.0.0.1:6379> shutdownnot connected> not connected> not connected> not connected> not connected> quit
显示状态,可以看到redis已经关闭
[root@xxx ~]# service redis statusRedirecting to /bin/systemctl status redis.service● redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: failed (Result: exit-code) since Tue 2019-02-12 17:37:49 CST; 22s ago Process: 59813 ExecStop=/usr/libexec/redis-shutdown (code=exited, status=1/FAILURE) Process: 59160 ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd (code=exited, status=0/SUCCESS) Main PID: 59160 (code=exited, status=0/SUCCESS)Feb 12 17:09:19 uJZPqK149888 systemd[1]: Starting Redis persistent key-value database...Feb 12 17:09:19 uJZPqK149888 systemd[1]: Started Redis persistent key-value database.Feb 12 17:37:49 uJZPqK149888 redis-shutdown[59813]: Could not connect to Redis at 127.0.0.1:6379: Connection refusedFeb 12 17:37:49 uJZPqK149888 systemd[1]: redis.service: control process exited, code=exited status=1Feb 12 17:37:49 uJZPqK149888 systemd[1]: Unit redis.service entered failed state.Feb 12 17:37:49 uJZPqK149888 systemd[1]: redis.service failed.
进程号杀掉redis,通过以下命令获取pid
ps -ef | grep redis
杀掉进程
kill -9 XXX
使用redis desktop manager远程连接redis
访问如下网址下载redis desktop manager
https://redisdesktop.com/download
安装后启动,新建一个连接
填写如下信息后点击“Test Connection”测试是否连接成功
如果长时间连接不上,可能有两种可能性:
a)bind了127.0.01:只允许在本机连接redis
b)protected-mode设置了yes(使用redis desktop manager工具需要配置,其余不用)
解决办法:
# 打开redis配置文件vi /etc/redis.conf# 找到 bind 127.0.0.1 将其注释# 找到 protected-mode yes 将其改为protected-mode no
重启redis
service redis stopservice redis start
再次连接即可