标签:ane comm wal add-port nbsp yum linu cli mode
1.安装gcc
Redis是c语言开发的,安装redis需要c语言的编译环境,如果没有gcc需要在线安装。
安装gcc:yum install gcc-c++
2.获取redis
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
3..解压
tar xzvf redis-4.0.8.tar.gz
4.安装redis
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
5.移动配置文件到安装目录下
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
6.配置redis为后台启动
vi /usr/local/redis/etc/redis.conf
把daemonize no 改成daemonize yes
7.配置外网访问
注释掉bind 127.0.0.1
把protected-mode yes改为no
保存并退出 :wq
7.将redis加入到开机启动
vi /etc/rc.local
添加:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
8.开启redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
9.查看redis是否启动
ps aux|grep redis
10.测试存取
cd /usr/local/redis/bin
./redis-cli
set test test1
get test
11.配置防火墙
查看防火墙状态 firewall-cmd --state
在running状态下,添加需要开放的端口 firewall-cmd --permanent --zone=public --add-port=6379/tcp //去掉--permanent则表示临时开放
加载配置 firewall-cmd --reload
查看开启状态 firewall-cmd --permanent --zone=public --list-ports //6379/tcp
12.使用jedis连接测试
maven中jedis依赖:
1 <dependency> 2 <groupId>redis.clients</groupId> 3 <artifactId>jedis</artifactId> 4 <version>2.7.1</version> 5 </dependency> 6 <dependency> 7 <groupId>org.apache.commons</groupId> 8 <artifactId>commons-lang3</artifactId> 9 <version>3.3.2</version> 10 </dependency>
测试:
1 @Test 2 public void testRedis() { 3 Jedis jedis = new Jedis("redis服务器ip",6379); 4 jedis.set("name", "user1"); 5 String name = jedis.get("name"); 6 System.out.println(name); 7 jedis.close(); 8 }
也可使用Redis Desktop Manage进行测试
查看redis服务器ip:ifconfig -a
标签:ane comm wal add-port nbsp yum linu cli mode
原文地址:https://www.cnblogs.com/I-van/p/11581820.html