环境准备
Linux环境:CentOS 7.3.
Redis服务端版本:3.2.6
Redis客户端下载链接:https://redisdesktop.com/download
Redis下载、安装教程链接:http://www.runoob.com/redis/redis-install.html 【含Win、Linux、Mac、Ubuntu】
远程连接
1. 安装时可能遇到的问题
问题1:make[3]: gcc: Command not found
解决: Centos系统执行yum install gcc;
Ubuntu系统执行apt-get install gcc;
问题2:zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error “Newer version of jemalloc required”
make[1]: * [adlist.o] Error 1
解决:输入make MALLOC=libc,然后重新编译
2. 安装完成之后进入redis安装目录执行
[root@Karle src]# ./redis-server
2745:C 10 Sep 10:16:13.130 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
2745:M 10 Sep 10:16:13.131 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2745
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
2745:M 10 Sep 10:16:13.145 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2745:M 10 Sep 10:16:13.145 # Server started, Redis version 3.2.6
2745:M 10 Sep 10:16:13.147 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2745:M 10 Sep 10:16:13.147 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
2745:M 10 Sep 10:16:13.147 * DB loaded from disk: 0.000 seconds
2745:M 10 Sep 10:16:13.147 * The server is now ready to accept connections on port 6379
3. Redis服务已经可以成功启动了,界面一直停留在Redis服务窗口中,按Ctrl+C虽然可以屏蔽服务窗口,但同时也会结束Redis服务
4. Redis服务默认是前台运行,需要修改为后台运行;返回上一层目录,修改redis.conf配置文件。找到daemonize(守护进程)配置,默认no。
修改前 daemonize no
修改后 daemonize yes
5. 启动服务的同时读取最新的配置文件
[root@Karle src]# ./redis-server ../redis.conf
6. 使用RedisDesktopManager客户端,输入服务器IP地址,端口,点击测试:
成功?over!———————-失败,继续往下看
7. Redis默认只支持本地链接,修改默认配置
[root@Karle src]# ps -ef | grep redis
root 5239 1 0 10:37 ? 00:00:00 ./redis-server 127.0.0.1:6379
root 5244 2321 0 10:37 pts/0 00:00:00 grep redis
问题解决:编辑redis.conf配置文件;注释掉61行本地链接限制以及80行配置修改为no
56 # bind 127.0.0.1
70 protected-mode no
读取最新配置文件并重启,查看Redis进程情况,还是127.0.0.1:6379
[root@Karle src]# ./redis-server ../redis.conf
[root@Karle src]# ps -ef | grep redis
root 5352 1 0 10:59 ? 00:00:00 ./redis-server 127.0.0.1:6379
root 5367 2321 0 11:00 pts/0 00:00:00 grep redis
杀掉Redis进程,再读取最新配置文件并重启
[root@Karle src]# redis-cli shutdown
[root@Karle src]# ./redis-server ../redis.conf
再查看进程情况:
[root@Karle src]# ps -ef | grep redis
root 5391 1 0 11:05 ? 00:00:00 ./redis-server *:6379
root 5395 2321 0 11:05 pts/0 00:00:00 grep redis
<br/>
成功?over!———————-失败,继续往下看
8. 防火墙设置
[root@Karle src]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8080
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:3306
8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:15672
9 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
编辑Linux防火墙
[root@Karle src]# vi /etc/sysconfig/iptables
加入防火墙规则:-A INPUT -m state –state NEW -m tcp -p tcp –dport 6379 -j ACCEPT
重启Linux防火墙
[root@Karle src]# service iptables restart
点击Test Connection按钮测试连接,连接成功!!!
![成功图](https://i.imgur.com/jv9CHnS.png)