Linux下搭建redis并解决无法连接redis的问题
2017-08-06 23:14
731 查看
原文地址:http://www.cnblogs.com/bestmystery/p/6371229.html
首先是搭建redis,这个比较简单。
1、检查安装依赖程序
2、获取安装文件
3、解压文件
自己新建一个目录将redis解压到里面
4、进入目录
5、编译安装
6、设置配置文件路径
7、修改配置文件
redis.conf是redis的配置文件,redis.conf在redis源码目录。
注意修改port作为redis进程的端口,port默认6379。如果需要搭建redis集群,千万别忘了修改端口号。
redis有两种启动方式,直接运行bin/redis-server将以前端模式启动,前端模式启动的缺点是ssh命令窗口关闭则redis-server程序结束,不推荐使用此方法。如下图:
后端模式启动
修改redis.conf配置文件, daemonize yes 以后端模式启动。推荐!
打开redis.conf,使用命令 :/ daemonize 快速查找到daemonize然后修改。
8、启动
9、查看启动
10、使用客户端
11.关闭客户端
12、开机启动配置
开机启动要配置在
13、设置密码
因为这是给局域网内的很多人使用,所以设置一个访问密码很有必要。
修改redis.conf文件配置
使用命令 :/ requirepass 快速查找到 # requirepass foobared 然后去掉注释,这个foobared改为自己的密码。然后wq保存。
14、重启redis
sudo service redis restart 这个时候尝试登录redis,发现可以登上,但是执行具体命令是提示操作不允许
redis-cli -h 127.0.0.1 -p 6379
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> keys *
(error) ERR operation not permitted
尝试用密码登录并执行具体的命令看到可以成功执行
redis-cli -h 127.0.0.1 -p 6379 -a password
redis 127.0.0.1:6379> keys *
1) "myset"
2) "mysortset"
redis 127.0.0.1:6379> select 1
OK
如果是自己在本机上使用现在已经可以了,因为我这是局域网内提供给大家使用的所以还需要最后的配置。
当时修改开发的配置文件后,启动项目报错。
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could
not get a resource from the pool
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:162) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:251) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:58) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:128) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
打开cmd 然后使用 telnet ip 端口 来ping 配置的redis(要保证redis已启动),发现无法ping通。
这是因为在redis.conf中有个配置 bind 127.0.0.1 这个是默认只有本机访问,把这个注释掉就好了,注释以后查看redis进程就变为下面这样:
[root@localhost redis]# ps -ef | grep redis
root 5655 1 0 11:40 ? 00:00:23 ./redis-server *:6379
root 21184 18040 0 17:33 pts/1 00:00:00 grep --color=auto redis
这个*号就表示允许其它用户访问了。然后在用打开本机的 cmd使用 telnet ip 端口 就能ping通了。
首先是搭建redis,这个比较简单。
1、检查安装依赖程序
yum install gcc-c++ yum install -y tcl yum install wget
2、获取安装文件
wget http://download.redis.io/releases/ 这里面有很多版本,自己选择需要的下载
3、解压文件
自己新建一个目录将redis解压到里面
tar -zxvf redis-3.2.01.tar.gz mv redis-3.2.01 /usr/local/redis
4、进入目录
cd /usr/local/redis
5、编译安装
make make install
6、设置配置文件路径
mkdir -p /etc/redis cp redis.conf/etc/redis
7、修改配置文件
redis.conf是redis的配置文件,redis.conf在redis源码目录。
注意修改port作为redis进程的端口,port默认6379。如果需要搭建redis集群,千万别忘了修改端口号。
redis有两种启动方式,直接运行bin/redis-server将以前端模式启动,前端模式启动的缺点是ssh命令窗口关闭则redis-server程序结束,不推荐使用此方法。如下图:
后端模式启动
修改redis.conf配置文件, daemonize yes 以后端模式启动。推荐!
打开redis.conf,使用命令 :/ daemonize 快速查找到daemonize然后修改。
vi /etc/redis/redis.conf 仅修改: daemonize yes (no-->yes)
8、启动
/usr/local/bin/redis-server /etc/redis/redis.conf
9、查看启动
ps -ef | grep redis
10、使用客户端
redis-cli >set name david OK >get name "david"
11.关闭客户端
redis-cli shutdown
12、开机启动配置
echo "/usr/local/bin/redis-server /etc/redis/redis.conf &" >> /etc/rc.local
开机启动要配置在
rc.local中,而
/etc/profile文件,要有用户登录了,才会被执行。
13、设置密码
因为这是给局域网内的很多人使用,所以设置一个访问密码很有必要。
修改redis.conf文件配置
使用命令 :/ requirepass 快速查找到 # requirepass foobared 然后去掉注释,这个foobared改为自己的密码。然后wq保存。
14、重启redis
sudo service redis restart 这个时候尝试登录redis,发现可以登上,但是执行具体命令是提示操作不允许
redis-cli -h 127.0.0.1 -p 6379
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> keys *
(error) ERR operation not permitted
尝试用密码登录并执行具体的命令看到可以成功执行
redis-cli -h 127.0.0.1 -p 6379 -a password
redis 127.0.0.1:6379> keys *
1) "myset"
2) "mysortset"
redis 127.0.0.1:6379> select 1
OK
如果是自己在本机上使用现在已经可以了,因为我这是局域网内提供给大家使用的所以还需要最后的配置。
当时修改开发的配置文件后,启动项目报错。
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could
not get a resource from the pool
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:162) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:251) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:58) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:128) ~[spring-data-redis-1.5.0.RELEASE.jar:1.5.0.RELEASE]
打开cmd 然后使用 telnet ip 端口 来ping 配置的redis(要保证redis已启动),发现无法ping通。
这是因为在redis.conf中有个配置 bind 127.0.0.1 这个是默认只有本机访问,把这个注释掉就好了,注释以后查看redis进程就变为下面这样:
[root@localhost redis]# ps -ef | grep redis
root 5655 1 0 11:40 ? 00:00:23 ./redis-server *:6379
root 21184 18040 0 17:33 pts/1 00:00:00 grep --color=auto redis
这个*号就表示允许其它用户访问了。然后在用打开本机的 cmd使用 telnet ip 端口 就能ping通了。
相关文章推荐
- linux下搭建redis并解决无法连接redis的问题
- Redis学习笔记(三)—— 使用redis客户端连接windows和linux下的redis并解决无法连接redis的问题
- linux下搭建redis并解决无法连接redis的问题
- Linux下ftp服务的搭建和windows下连接及问题解决
- linux系统下memcached启动正常但程序无法连接的问题解决
- Xshell无法连接本地linux虚拟机(多次尝试解决该问题)
- linux JDK 安装无法建立连接的问题解决 wget方法后面再说
- Broadcom网卡linux系统下无法连接到网络问题(某种情况- -||)的解决办法
- Jedis无法连接上Linux中Redis解决方法
- @Redis Desktop Manager无法连接虚拟机中启动的redis服务问题解决
- linux环境下搭建的redis无法访问解决
- Linux中4.0.1版本的redis和java连接出现的redis被保护的问题以及解决办法
- 解决在无线网络下本机无法连接linux(红帽)虚拟机问题
- Linux连接投影仪 (解决无法正常显示的问题)
- Broadcom网卡linux系统下无法连接到网络问题的解决办法
- linux 配置NDS服务器地址 解决安装中源无法连接问题
- ssh无法连接VM下Linux问题的解决
- RedisDesktopManager无法连接虚拟机中启动的redis服务问题解决
- Linux下PPTPD搭建***服务器连接后无法上外网及619错误的解决办法