当前位置: 首页 > Linux

Centos6.5安装Redis3.0备忘记录

时间:2023-04-07 01:46:57 Linux

Centos6.5安装Redis3.01。安装C编译环境首先需要安装编译Redis的C环境。在命令行中执行以下命令:[root@itzhouq32tools]yuminstallgcc-c++2。上传redis3.0到Linux3.解压redis,我解压到/usr/local[root@itzhouq32tools]#tar-xvfredis-3.0.0.tar.gz-C/usr/local4。编译进入解压目录,使用make编译[root@itzhouq32tools]#cd/usr/local/[root@itzhouq32local]#lsbingamesjdk1.8.0_201lib64redis-3.0.0sharesrcetcincludeliblibexecsbinsofttomcat[root@itzhouq32local]#cdredis-3.0.0/[root@itzhouq32redis-3.0.0]#ls00-RELEASENOTES复制Makefileredis.confruntest-sentineltestsBUGSdepsMANIFESTOruntestsentinel.confutilsCONTRIBUTINGINSTALLREADMEruntest-clustersrc[root@itzhouq32redis-3.0.0]#make5.在原目录下安装,当前目录为/usr/local/redis[root@itzhouq32redis-3.0.0]#makePREFIX=/usr/local/redisinstall6.修改配置文件进入redis-3.0.0目录,找到redis.conf配置文件,复制到redis/bin目录下[root@itzhouq32local]#lsbingamesjdk1.8.0_201lib64redissbinsofttomcatetcincludeliblibexecredis-3.0.0sharesrc[root@itzhouq32local]#cdredis-3.0.0/[root@itzhouq32redis-3.0.0]#ls00-RELEASENOTESCOPYINGMakefileredis.confruntest-sentineltestsBUGSdepsMANIFESTOruntestsentinel.confutilsCONTRIBUTINGINSTALLREADMEruntest-clustersrc[root@itzhouq32redis-3.0.0]#cpredis.conf../redis/bin/返回redis/bin目录,修改redis.conf配置文件[root@itzhouq32redis-3.0.0]#cd../redis/bin/[root@itzhouq32bin]#lsdump.rdbredis-check-aofredis-cliredis-sentinelredis-benchmarkredis-check-dumpredis.confredis-server[root@itzhouq32bin]#viredis.conf将redis.conf文件中的daemonize由false改为true表示后台启动7.后台启动测试[root@itzhouq32bin]#./redis-服务器redis.conf[root@itzhouq32bin]#ps-ef|grepredisroot46534628016:56pts/100:00:00./redis-cliroot47021017:11?00:00:02./redis-server*:6379root47821631017:37pts/000:00:00grepredis[root@itzhouq32bin]#进程中有redis,说明后台启动成功8.客户端登录并测试[root@itzhouq32bin]#./redis-cli127.0.0.1:6379>setusernamezhangsanOK127.0.0.1:6379>getusername"zhangsan"127.0.0.1:6379>exit[root@itzhouq32bin]#9。远程访问配置如果需要远程访问redis,需要在Linux防火墙中开放6379端口,并在防火墙中保存规则。[root@itzhouq32bin]#/sbin/iptables-IINPUT-ptcp--dport6379-jACCEPT[root@itzhouq32bin]#/etc/rc.d/init.d/iptablessaveiptables:保存防火墙规则到/etc/sysconfig/iptables:[确定][root@itzhouq32bin]#10。Java连接测试在Eclipse中导入jar包,编写测试类。packagecom.itzhouq.jedis;importorg.junit.Test;importredis.clients.jedis.Jedis;publicclassJedisTest{@Testpublicvoidtest01(){//1.获取连接对象Jedisjedis=newJedis("192.168.146.132",6379);//2。获取数据Stringusername=jedis.get("username");System.out.println(username);//张三//3.Storejedis.set("addr","Shanghai");System.out.println(jedis.get("addr"));//上海}}