Notes on the installation of Redis3.0 in CentOS 6.5

Keywords: Linux Redis Jedis iptables firewall

CentOS 6.5 install Redis3.0

1. Install C compilation environment

First, you need to install the C environment for compiling Redis, and execute the following commands at the command line:

[root@itzhouq32 tools] yum install gcc-c++

2. Upload redis3.0 to Linux

3. Unzip redis. I unzip it to / usr/local

[root@itzhouq32 tools]# tar -xvf redis-3.0.0.tar.gz -C /usr/local

4. compilation

Enter the decompressed directory and compile with make

[root@itzhouq32 tools]# cd /usr/local/
[root@itzhouq32 local]# ls
bin  games    jdk1.8.0_201  lib64    redis-3.0.0  share  src
etc  include  lib           libexec  sbin         soft   tomcat
[root@itzhouq32 local]# cd redis-3.0.0/
[root@itzhouq32 redis-3.0.0]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
CONTRIBUTING     INSTALL  README     runtest-cluster  src
[root@itzhouq32 redis-3.0.0]# make

5. installation

Install in the original directory. The current directory is / usr/local/redis

[root@itzhouq32 redis-3.0.0]# make PREFIX=/usr/local/redis install

6. Modify the configuration file

Enter the redis-3.0.0 directory, find the redis.conf configuration file, and copy it to the redis/bin directory

[root@itzhouq32 local]# ls
bin  games    jdk1.8.0_201  lib64    redis        sbin   soft  tomcat
etc  include  lib           libexec  redis-3.0.0  share  src
[root@itzhouq32 local]# cd redis-3.0.0/
[root@itzhouq32 redis-3.0.0]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
CONTRIBUTING     INSTALL  README     runtest-cluster  src
[root@itzhouq32 redis-3.0.0]# cp redis.conf ../redis/bin/

Return to the redis/bin directory and modify the redis.conf configuration file

[root@itzhouq32 redis-3.0.0]# cd ../redis/bin/
[root@itzhouq32 bin]# ls
dump.rdb         redis-check-aof   redis-cli   redis-sentinel
redis-benchmark  redis-check-dump  redis.conf  redis-server
[root@itzhouq32 bin]# vi redis.conf

Changing the daemonize in redis.conf file from false to true indicates background startup

7. Background start test

[root@itzhouq32 bin]# ./redis-server redis.conf
[root@itzhouq32 bin]# ps -ef | grep redis
root       4653   4628  0 16:56 pts/1    00:00:00 ./redis-cli
root       4702      1  0 17:11 ?        00:00:02 ./redis-server *:6379    
root       4782   1631  0 17:37 pts/0    00:00:00 grep redis
[root@itzhouq32 bin]#

There is redis in the process, indicating that the background is started successfully.

8. Client login and test

[root@itzhouq32 bin]# ./redis-cli 
127.0.0.1:6379> set username zhangsan
OK
127.0.0.1:6379> get username
"zhangsan"
127.0.0.1:6379> exit
[root@itzhouq32 bin]#

9. Remote access configuration

If you need to access redis remotely, you need to open port 6379 in the Linux firewall and save the rules to the firewall.

[root@itzhouq32 bin]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
[root@itzhouq32 bin]# /etc/rc.d/init.d/iptables save
iptables: Save firewall rules to /etc/sysconfig/iptables:      [Determine]
[root@itzhouq32 bin]#

10. Java connection test

Import the jar package in Eclipse and write a test class.

package com.itzhouq.jedis;

import org.junit.Test;

import redis.clients.jedis.Jedis;

public class JedisTest {
    @Test
    public void test01() {
        //1. Get the connection object
        Jedis jedis = new Jedis("192.168.146.132", 6379);
        
        //2. Data acquisition
        String username = jedis.get("username");
        System.out.println(username);//zhangsan
        
        //3. storage
        jedis.set("addr", "Shanghai");
        System.out.println(jedis.get("addr"));//Shanghai
    }
}

Posted by jwwceo on Tue, 19 Nov 2019 10:43:52 -0800