Document directory
- 4.2 Use scp to copy files and directories
- 4.3 configure redis. conf for slave
- 5.1 start the server
- 5.2 Test Synchronization
1. Introduction
Redis is a key-value storage system. Similar to Memcached, Memcached supports more storage value types, including string, list, set, and zset ). These data types support push/pop, add/remove, Intersection Set and difference set, and more abundant operations, and these operations are atomic. On this basis, redis supports sorting in different ways. Like memcached, data is cached in the memory to ensure efficiency. The difference is that redis periodically writes the updated data to the disk or writes the modification operation to the append record file, and on this basis implements master-slave (master-slave) synchronization. Redis is a high-performance key-value database. The emergence of redis largely compensates for the shortage of key/value storage such as memcached, and can play a good complementary role in relational databases in some cases. It provides Python, Ruby, Erlang, and PHP clients for ease of use.
2. Install the test environment
Centos 1, 6.3
3. Configure redis master (master server 192.168.2.136)
3.1 install redis
Linux Installation
$ wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz$ tar xzf redis-2.6.13.tar.gz$ cd redis-2.6.13$ make
Note: before installation, make sure that your server has installed gcc and tcl.
3.2 Create related directories
Mkdir-p/usr/local/webserver/redis/confmkdir-p/usr/local/webserver/redis/runmkdir-p/usr/local/webserver/redis/dbcp redis. conf/usr/local/webserver/redis/conf/# cd srccp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server mkreleasehdr. sh/usr/local/webserver/redis/vim/usr/local/webserver/redis/conf/redis. conf # modify the following three daemonize yes -- yes enable the daemon pidfile/usr/local/webserver/redis/run/redis. pid-Redis writes the pid to the file dir/usr/local/webserver/redis/db when running as a daemon-port 6380
3.3 create an enabling redis script
vim /usr/local/webserver/redis/start.sh#!/bin/bash/usr/local/webserver/redis/redis-server /usr/local/webserver/redis/conf/redis.conf
3.4 create a script to close the redis Process
vim /usr/local/webserver/redis/stop.sh#!/bin/bashkill `cat /usr/local/webserver/redis/run/redis.pid`
4. Create two slave server (192.168.2.8.0 and 192.168.2.138)
4.1 create related directories
mkdir -p /usr/local/webserver/redis/confmkdir -p /usr/local/webserver/redis/runmkdir -p /usr/local/webserver/redis/db
4.2 Use scp to copy files and directories
# Run scp/usr/local/webserver/redis/* root@192.168.2.137 on 192.168.2.small: /usr/local/webserver/redis/-r #192.168.2.138 execute scp/usr/local/webserver/redis/* root@192.168.2.138: /usr/local/webserver/redis/-r # enter the passwords and copy them.
4.3 configure redis. conf for slave
# Run vim/usr/local/webserver/redis/conf/redis on 192.168.2.6.2. confport 6381 pidfile/usr/local/webserver/redis-slave1/run/redis. piddir/usr/local/webserver/redis-slave1/dbslaveof 192.168.2.136 6380 # Run vim/usr/local/webserver/redis/conf/redis on 192.168.2.138. confport 6382 pidfile/usr/local/webserver/redis-slave1/run/redis. piddir/usr/local/Web server/redis-slave1/dbslaveof 192.168.2.136 6380
5. Start redis and check master-slave Synchronization
5.1 start the server
# Start redis/usr/local/webserver/redis/start. sh on the master and slave servers respectively # verify if netstat-nlpt | grep redis-server is enabled
5.2 Test Synchronization
#192.168.2.136 master $ set param haibrother # 192.168.2.20.slave $ get param $ haibrother #192.168.2.138 slave $ get param $ haibrother # synchronization successful