1, compilation environment preparation 1.1 environment confirmation
Redis is an open source, support network, memory-based, key-value-pair storage database, written using ANSI C. Therefore, the C-language compilation environment GCC or g++ is required to build the Redis server.
First verify that the system has a C language compilation environment, the terminal run the following command:
#gcc –version
Or
#g + +--version
The following typeface indicates that there is a C language compilation environment in the system and does not require installation.
GCC (gcc) 4.1.2 20080704 (Red Hat 4.1.2-44)
Copyright (C) 2006 free Software Foundation, Inc.
This was free software; See the source for copying conditions. There is NO
Warranty Not even to merchantability or FITNESS for A particular PURPOSE
Or
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
Copyright (C) 2006 free Software Foundation, Inc.
This was free software; See the source for copying conditions. There is NO
Warranty Not even to merchantability or FITNESS for A particular PURPOSE.
If not, you will need to install GCC, g++ in the system.
1.2 64-bit Redhat install GCC, g++
Copy the required RPM packages from the installation to the target machine and install them in the following order:
(1) Install GCC, the software installation sequence can not be wrong
# RPM-IVH glibc-common-2.12-1.25.el6.x86_64.rpm
# RPM-IVH kernel-headers-2.6.32-131.0.15.el6.x86_64.rpm
# RPM-IVH libgcc-4.4.5-6.el6.x86_64.rpm
# RPM-IVH glibc-2.12-1.25.el6.x86_64.rpm
# RPM-IVH libgomp-4.4.5-6.el6.x86_64.rpm
# RPM-IVH nscd-2.12-1.25.el6.x86_64.rpm
# RPM-IVH glibc-headers-2.12-1.25.el6.x86_64.rpm
# RPM-IVH glibc-devel-2.12-1.25.el6.x86_64.rpm
# RPM-IVH mpfr-2.4.1-6.el6.x86_64.rpm
# RPM-IVH ppl-0.10.2-11.el6.x86_64.rpm
# RPM-IVH cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
# RPM-IVH cpp-4.4.5-6.el6.x86_64.rpm
# RPM-IVH gcc-4.4.5-6.el6.x86_64.rpm
(2) Installation gcc-c++
# RPM-IVH libstdc++-4.4.5-6.el6.x86_64.rpm
# RPM-IVH libstdc++-devel-4.4.5-6.el6.x86_64.rpm
# RPM-IVH gcc-c++-4.4.5-6.el6.x86_64.rpm
Note that this installation is not a problem under normal circumstances, but it will be an error when installing the first RPM package in some environments. This is the time to add "--nodeps–force" to all the commands, like this:
# RPM-IVH glibc-common-2.12-1.25.el6.x86_64.rpm--nodeps–force
Running again is no problem.
2. Installation and configuration Redis2.1 installation Redis
Unzip the redis-2.6.16.tar.gz and install. Steps and related commands are as follows:
#tar –xvzf redis-2.6.16.tar.gz
#cd redis-2.6.16
#make
Some versions of Linux will have an error when made, as shown in 2.1.
Figure 2.1 Compiling Redis error
A program that parses a 32-bit reason has an error compiling in a system of 64. Workaround:
(1) The extracted Redis folder is deleted, re-decompression;
(2) access to the extracted Redis folder execution: Make cflags= "-march=i686"
After make succeeds, several executables are generated in the SRC folder and run:
./redis-server
The screen shown in 2.2 will appear.
Figure 2.2 Redis Service Open screen
2.2 Configuration Redis2.2.1 Copy to the specified folder
#mkdir-P/usr/local/webserver/redis/conf
#mkdir-P/usr/local/webserver/redis/run
#mkdir-P/usr/local/webserver/redis/db
#cp redis.conf/usr/local/webserver/redis/conf/
#cd CD REDIS-2.6.16/SRC
Copy all executable files from the SRC directory to the installation directory
#cp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server mkreleasehdr.sh/usr/local/webserver/ redis/
2.2.2 Modify the following options in the configuration file
#vi/usr/local/webserver/redis/conf/redis.conf
Daemonize Yes
Pidfile/usr/local/webserver/redis/run/redis.pid
dir/usr/local/webserver/redis/db
2.2.3 Creating a service script
(1) Startup script
#vi/usr/local/webserver/redis/start.sh
#!/bin/bash
/usr/local/webserver/redis/redis-server/usr/local/webserver/redis/conf/redis.conf
(2) Stop script
#vi/usr/local/webserver/redis/stop.sh
#!/bin/bash
Kill ' Cat/usr/local/webserver/redis/run/redis.pid '
(3) Assigning permissions to a service script
chmod a+x/usr/local/webserver/redis/start.sh/usr/local/webserver/redis/stop.sh
2.2.4 Start Redis Service
#/usr/local/webserver/redis/start.sh
Verify that the service is successful:
#netstat-nlpt | grep 6379
2.2.5 Initiating Client Authentication
#/usr/local/webserver/redis/redis-cli
>set Key1 Val1
>get Key1
2.2.6 Stop Redis Service
#/usr/local/webserver/redis/stop.sh
2.3java Client Instance
In the Java client, only the Jedis dependent jar package: Jedis-2.1.0.jar introduced, you can establish a connection, and then read and write operations, as shown in 2.3.
Figure 2.3 Java Client Connection and read and write Redis
3. Redis Master-slave configuration 3.1Redis master/slave master-slave configuration
Here we configure 1 Master + 1 sets of slave for example, where:
Master ip:192.168.32.166 port:6379
Slave ip:192.168.32.188 port:6379
Note that the IP addresses of both machines must be within the same network segment, otherwise the cluster cannot be implemented. The Redis service is installed and configured on both machines according to the above steps. Modify the configuration file on the slave machine so that it becomes the slave of Master. The command and configuration are as follows:
#vi/usr/local/webserver/redis/conf/redis.conf
Slaveof 192.168.32.166 6379
3.2 Starting the Redis service
First turn on the service on the host, then boot the service from the machine.
3.3 Verifying the M/s service is in effect
On the host:
/usr/local/webserver/redis/redis-cli
>set Key1 Val1
>quit
From the machine:
/usr/local/webserver/redis/redis-cli
>get Key1
"Val1" (indicates that the data was successfully synchronized)
Redis installation and master-slave configuration