Linux下搭建redis并解决无法连接redis的问题
来源:互联网 发布:淘宝永久封店怎么解封 编辑:程序博客网 时间:2024/06/05 10:55
原文地址:http://www.cnblogs.com/bestmystery/p/6371229.html
首先是搭建redis,这个比较简单。
1、检查安装依赖程序
yum install gcc-c++yum install -y tclyum install wget
2、获取安装文件
wget http://download.redis.io/releases/
这里面有很多版本,自己选择需要的下载
3、解压文件
自己新建一个目录将redis解压到里面
tar -zxvf redis-3.2.01.tar.gzmv redis-3.2.01 /usr/local/redis
4、进入目录
cd /usr/local/redis
5、编译安装
makemake install
6、设置配置文件路径
mkdir -p /etc/rediscp 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 davidOK>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的问题
- Linux下搭建redis并解决无法连接redis的问题
- Redis入门(三)—— 使用redis客户端连接windows和linux下的redis并解决无法连接redis的问题
- 【redis】无法连接linux上的redis
- linux环境下搭建的redis无法访问解决
- Linux下搭建redis
- linux下搭建redis
- 解决Linux系统下安装redis make出错的问题
- Redis连接无法正常释放问题分析解决总结
- Linux系统下,redis集群的搭建
- Linux下Redis的环境搭建
- redis linux下的环境搭建
- 在Linux上(我的服务器是Ubuntu) 用redis-trib.rb搭建redis集群,并在客户端使用spring-data-redis连接(亲测)
- linux下搭建redis单机版+java连接测试
- ssh无法连接VM下Linux问题的解决
- Linux下搭建Redis环境
- linux下redis环境搭建
- redis在linux下搭建
- POJ 3009 Curling 2.0【带回溯DFS】
- Android动画机制与使用技巧(一)属性动画分析
- Manacher最长回文子串(模板)
- 大话数据结构 code 第四章 04斐波那契函数_Fibonacci
- POSIX 条件变量
- Linux下搭建redis并解决无法连接redis的问题
- 数据库的一些小结
- C语言指针--初级部分
- 河南省多校联萌-HAUT-1285-军团再临
- Unix下时间和日期
- Java实现二维码制作
- Java+Selenium3框架设计篇2-Selenium方法的二次封装和页面基类
- 安卓利用NDK打包so文件
- 使用op=(复合形式)替代op(独身形式)的优点