ZC: 主要是 做一些配置,使得 java程序能够访问到 redis服务器,主要内容为:
ZC:  ①、redis服务端服务 重启的命令
ZC:  ②、取消绑定 本地IP的配置,使得 所有本网段局域网机器都能访问 redis服务器 (非本网段局域网/公网 机器 如何访问,还得查资料+测试)
ZC:  ③、增加 redis服务端 验证密码
ZC:  ④、一段简单的 java访问 redis服务器 的代码

1、服务 重启

在 "/home/redis-3.2.3/README.md"中,搜到一句话:


You'll be able to stop and start Redis using the script named
`/etc/init.d/redis_<portnumber>`, for instance `/etc/init.d/redis_6379`.

看了一下里面的shell脚本,一般操作行为为:"/etc/init.d/redis_6379"后面跟" start/stop/restart"

2、

http://jiangwenfeng762.iteye.com/blog/1280700 中说到“jedis是Redis官网推荐的java客户端实现。”

 2.1、

  java使用 jedis 来连接 redis,但是出错:“Connection refused: connect”

搜到 http://www.oschina.net/question/579073_113004?sort=time 说


bind的问题. 把Redis的配置文件redis.conf里
#bind localhost
注释掉它.
注释掉本机,局域网内的所有计算机都能访问.

band localhost :只能本机访问,局域网内计算机不能访问
bind 局域网IP :只能局域网内IP的机器访问, 本地localhost都无法访问.

 2.2、注释掉“#bind 127.0.0.1”,然后重启之后。再次 java程序连接,出现新问题:

  “DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.”

  ZC: 网上查到,取消了 bind本机 之后,需要有密码才能登录,于是设置密码:

[root@localhost src]# redis-cli
127.0.0.1:6379> config set requirepass 123456
OK
127.0.0.1:6379> exit
[root@localhost src]#

    ZC: 设置密码后,无需 重启服务

  ZC: 上面这样,在 redis客户端设置验证密码,在redis服务器重启之后,requirepass机制 就没有了。要想 重启之后 requirepass机制 依旧存在,就需要修改配置文件(这里,安装的时候配置的是"/etc/redis/6379.conf"),在配置文件中有 requirepass相关的部分(gedit搜索"requirepass"),做好设置即可。(个人感觉 需要重启redis服务程序,未测试...)

  2.3、Jedis 连接 Redis 的测试代码:

import redis.clients.jedis.*;

public class TredisZ
{
public static void main(String[] args)
{
//连接本地的 Redis 服务
Jedis jedis = new Jedis("192.168.1.235", 6379);
String str = jedis.auth("123456");
System.out.println("Jedis.auth : "+str);
System.out.println("Connection to server sucessfully");
//查看服务是否运行
System.out.println("Server is running: "+jedis.ping());
//jedis.close();
}
}

    控制台输出:

Jedis.auth : OK
Connection to server sucessfully
Server is running: PONG

3、另一个 测试代码:

  3.1、

import redis.clients.jedis.*;
//import org.apache.commons.pool.impl.GenericObjectPool.Config; public class TredisZ
{
public static void main(String[] args)
{
String strRedisAddress = "192.168.1.235"; int iRedisPort = 6379;
int iRedisTimeout = 2000; JedisPoolConfig poolCfg = new JedisPoolConfig();
JedisPool pool = new JedisPool(
poolCfg,
strRedisAddress,
iRedisPort,
iRedisTimeout, "123456"); Jedis jedis = pool.getResource();
//jedis.set("test123", "lulu");
System.out.println("Server is running: "+jedis.ping()); pool.returnResource(jedis);
}
}

  3.2、

JedisPoolConfig 依赖于 commons-pool

commons-pool 的

 官网为:

  http://commons.apache.org/proper/commons-pool/

 下载页面为:

  http://commons.apache.org/proper/commons-pool/download_pool.cgi

 我下了2个 :commons-pool-1.6-bin.tar.gz 和 commons-pool2-2.4.2-bin.tar.gz

4、

5、

20160817_Redis配置操作的更多相关文章

  1. [mysql]brew 安装 配置 操作 mysql(中文问题)

    mac 下卸载mysqldmg mac下mysql的DMG格式安装内有安装文件,却没有卸载文件--很郁闷的事. 网上搜了一下,发现给的方法原来得手动去删. 很多文章记述要删的文件不完整,后来在stac ...

  2. LSI SAS 2208 配置操作

    配置LSISAS2208 介绍LSISAS2208扣卡的配置方法. 2.1 登录CU界面 介绍登录LSISAS2208的CU配置界面的方法,以及CU界面的主要功能. 2.2 创建RAID 介绍创建RA ...

  3. LSI SAS 3108 配置操作

    配置LSISAS3108 介绍LSISAS3108的配置操作. 5.1 登录CU界面 介绍登录LSISAS3108的CU配置界面的方法,以及CU界面的主要功能. 5.2 创建RAID 介绍在LSISA ...

  4. LSI SAS 3008配置操作

    配置 LSI SAS 3008 介绍LSISAS3008的配置操作. 4.1 登录CU界面 介绍登录LSISAS3008的CU配置界面的方法. 4.2 创建RAID 介绍在LSISAS3008扣卡上创 ...

  5. LSI SAS 2308配置操作

    介绍LSISAS2308的配置操作 3.1 登录CU界面 介绍登录LSISAS2308的CU配置界面的方法. 3.2 创建RAID 介绍在LSISAS2308扣卡上创建RAID的操作方法. 3.3 配 ...

  6. LSI SAS 3008 Web配置操作

    配置 LSI SAS 3008 介绍LSISAS3008的配置操作. 4.1 登录CU界面 介绍登录LSISAS3008的CU配置界面的方法. 4.2 创建RAID 介绍在LSISAS3008扣卡上创 ...

  7. Python 之configparser读取配置操作类

    一.为什么要封装 我们为什么要封装,我相信你们在项目开发过程中深有体会,那么这个读取配置工具类,又是为了什么? 为了项目参数配置的灵活性,不要改动到源码 为了信息的安全(一定层面的),体现代码重用性 ...

  8. Ubuntu 防火墙常用配置操作(ufw)【适用于 Debian 及其衍生版---Linux Mint、Deepin 等】-转

    Ubuntu 防火墙常用配置操作(ufw)[适用于 Debian 及其衍生版---Linux Mint.Deepin 等] 点击访问

  9. apscheduler(定时任务) 基于redis持久化配置操作

    apscheduler(定时任务) 基于redis持久化配置操作 安装模块 pip install apscheduler 导入模块配置 ## 配置redis模块 from apscheduler.j ...

随机推荐

  1. 《Linux内核设计与实现》CHAPTER5阅读梳理

    <Linux内核设计与实现>CHAPTER5阅读梳理 [学习时间:2.5hours] [学习内容:系统调用的概念.功能及实现:系统调用的创建和使用方法] CHAPTER5 系统调用 1.系 ...

  2. 使用Android Studio进行单元测试

    Android Studio默认支持Android单元测试,不需要像网上说的配置mainifest.xml或build.gradle. 创建单元测试文件夹 可以把单元测试文件夹放到你自己创建的文件夹中 ...

  3. [转]第四章 使用OpenCV探测来至运动的结构——Chapter 4:Exploring Structure from Motion Using OpenCV

    仅供参考,还未运行程序,理解部分有误,请参考英文原版. 绿色部分非文章内容,是个人理解. 转载请注明:http://blog.csdn.net/raby_gyl/article/details/174 ...

  4. 【转】PHP实现连贯操作

    [第一种方案 __call] 我们在使用一些框架(如ThinkPHP)编码的时候,常用到这样的代码. M('User')->where(array('id'=>1))->field( ...

  5. #if 0在代码中的作用

    #if 0在代码中有2个作用. 1.作为行内注释 /**/是多行注释,如果想在/**/里面嵌套一个多行注释,怎么办呢? /* int a=10; /* - (void)test{ NSLog(@&qu ...

  6. bootstrap入门-3.响应式原理

    Bootstrap网格系统(Grid System) 响应式网格系统随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 ...

  7. 从零开始学Linux[三]:shell脚本学习

    测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试

  8. URL中文乱码处理总结(转)

    转自:http://www.cnblogs.com/xirongliu/archive/2012/09/06/2674196.html 问题:传递中文参数的时候,接收页面出现乱码问题?当跨域操作,两套 ...

  9. 移动前端中viewport(视口) 转

    移动前端中常说的 viewport (视口)就是浏览器显示页面内容的屏幕区域.其中涉及几个重要概念是 dpi ( device-independent pixel 设备逻辑像素 )和 CSS 像素之间 ...

  10. mongodb备份与恢复

    一.备份:mongodump -d mailaccess -c Mail -q ‘{user:”zhaoxy1@szdep.com”}’ -o /data/dump备份mailaccess datab ...