使用jedis连接云端远程linux服务器详细配置步骤

1、创建maven项目导包

	 <!--导入jedis的包-->
	    <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
	    <dependencies>
	        <dependency>
	            <groupId>redis.clients</groupId>
	            <artifactId>jedis</artifactId>
	            <version>3.6.0</version>
	        </dependency>
	        <dependency>
	            <groupId>com.alibaba</groupId>
	            <artifactId>fastjson</artifactId>
	            <version>1.2.75</version>
	        </dependency>
	    </dependencies>

2、远程服务器配置

1、首先修改redis.config 建议先备份

		protected-mode  no	改为no,原来为yes
		bind 127.0.0.1 	注释掉
		requirepass 123456	如果需要就设置密码  123456
							连接时需要
							auth 123456 
							jedis.auth("123456")
		然后wq保存

2、开启防火墙

			firewall-cmd --list-ports	查看所有端口
			firewall-cmd --zone=public --add-port=6379/tcp --permanent	开启端口
			systemctl restart firewalld.service	重启防火墙

3、在服务器上添加安全组

4、如果需要 停止掉之前的服务

		lsof -i:6379	查看某个端口所占进程
		kill -9 PID 	杀死进程

5、redis-server /myserver/redis.conf 开启服务

3、建立连接

		 Jedis jedis = new Jedis("123.123.123.123",6379);	连接服务器
		 jedis.auth("123456");	输入密码
		 System.out.println(jedis.ping());	测试连接

版权声明:本文为qq_43610489原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。