Install redis cluster in CentOS
1. [root @ localhost liu] # wgethttp: // download. redis. io/redis-2.8.21.tar.gz or wget http://download.redis.io/releases/redis-3.0.2.tar.gz
2. Decompress tar -zxvfredis-stable.tar.gz 3. Check whether tcl rpm-qa is installed. | if grep tcl does not, install yum install-y tcl4. Enter the decompressed directory. After making is successful, run make test to ensure no errors. 5. Run make install to copy redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server to usr/local/ 6. Copy the configuration file to the cp redis under the/etc directory. conf/etc 5 and 6 can also be replaced with {here, we will not make install. We will directly use the make file usr/local/to create the redis folder, copy six executable files to the directory bin and configure them to etc [root @ localhost local] # mkdir-p redis/{etc, bin, var} the configuration file path below is the new path} 7. Create your own init. d script to enter,/etc/init. d/directory. Create a New redis file as follows:
###########################
#chkconfig: 2345 10 90
#description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
##############################
Save and exit chmod + x/etc/init. d/redis set to boot chkconfig redis on // if this is a failure, change the configuration file yes to no, set to boot, and then modify the configuration file to edit the configuration file vim redis. change confdaemonize no to yes # whether to run port 6379 in the background to 12002 # port dir. /change to dir/data/redis_data or/www/redis_1_2/# data DIRECTORY startup service: service redis start stop service: service redis stop Configure Firewall to open the corresponding port: vi/etc/sysconfig/iptables-a input-m state -- state NEW-m tcp-p tcp -- dport 6379-j ACCEPT restart Firewall service iptables restart Cluster Master/Slave Configuration
Redis master-slave replication one master service can have multiple slave services, one slave service can have multiple slave services.
The configuration is relatively simple. You only need to change the slaveof parameter configuration in the redis. conf file.
The format of the slaveof parameter on the slave server is as follows: slaveof <masterip> <masterport>
If the master server has a password, you need to configure the masterauth parameter.
Masterauth parameter format: masterauth <master-password>
For example, add the requirepass liubobind 192.168.10.16 slave server (192.168.10.25: 6379) configuration file slaveof 192.168.10.16 6379 // ip address of the master server in the configuration file of the master server (192.168.10.16: 6379, the Write function of the masterauth liubobind 192.168.10.25 slave service is disabled by default, and it is not recommended to write data to the slave server. The clients of the apsaradb for Redis database can be reasonably read and written separately in applications. Use keepalive to implement master failover No route to host can temporarily disable the Firewall service iptables stop client remote connection
Usage: redis-cli [OPTIONS] [cmd [arg [arg...]
-H <Host ip address>. The default value is 127.0.0.1.
-P <port>. The default value is 6379.
-A <password>: If redis is locked, the password must be passed.
-- Help: displays help information.
Through the introduction of rendis-cli usage, connecting to 101 on 103 should be simple:
[root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379
redis 192.168.1.103:6379>
Set each string value user.1.name = zhangsan for 101 on 103.
redis 192.168.1.103:6379> set user.1.name zhangsan
OK
If OK is displayed, the setting is successful. Then, log on to MySQL 103 directly to see if this value can be obtained.
Test whether the instance has been started #/usr/local/bin/redis-cli ping performance test #/usr/local/bin/redis-benchmark to disable the service #/usr/local/bin/redis -Force-p 6379 shutdown to refresh data to the disk [Redis writes data to the disk asynchronously by default] #/usr/local/bin/redis-cli-p 6379 save if an exception occurs
Exception 1:
Make [2]: cc: Command not found
Cause of exception: gcc Is Not Installed
Solution: yum install gcc-c ++
Exception 2:
Zmalloc. h: 51: 31: error: jemalloc/jemalloc. h: No such file or directory
Cause of exception: Some compilation dependencies or issues left behind by the original compilation
Solution: make distclean. Clean up and then make.
Make test is required after make is successful. An exception occurred in make test.
Exception 1:
Couldn't execute "tclsh8.5": no such file or directory
Cause of exception: tcl is not installed
Solution: yum install-y tcl.
Daemonize: whether to run in daemon mode
Pidfile: pid File Location
Port: the port number of the listener.
Timeout: Request timeout
Loglevel: log information level
Logfile: Location of the log file
Databases: number of databases Enabled
Save **: the frequency at which snapshots are saved. The first "*" indicates the duration and the third "indicates the number of write operations performed. Snapshots are automatically saved when a certain number of write operations are performed within a certain period of time. You can set multiple conditions.
Rdbcompression: whether to use Compression
Dbfilename: Data snapshot file name (only file name, excluding directory)
Dir: directory for storing data snapshots (this is the Directory)
Appendonly: whether to enable appendonlylog. If it is enabled, a log is recorded for each write operation, which improves data risk resistance but affects efficiency.
Appendfsync: How to synchronize appendonlylog to the disk (three options are force-call fsync for each write, enable fsync once per second, and do not call fsync to wait for the system to synchronize itself)