Repcached实现Memcached主从复制功能(2)

/* FreeBSD 4.x doesn't have IOV_MAX exposed. */   
#ifndef IOV_MAX   
#if defined(__FreeBSD__) || defined(__APPLE__)   
# define IOV_MAX 1024   
#endif   
#endif

修改为   

/* FreeBSD 4.x doesn't have IOV_MAX exposed. */   
#ifndef IOV_MAX   
# define IOV_MAX 1024   
#endif

重新编译和安装:   

make && make install

查看帮助:   

./bin/memcached -h

memcached 1.2.8   
repcached 2.2.1   
-p <num> TCP port number to listen on (default: 11211)   
-U <num> UDP port number to listen on (default: 11211, 0 is off)   
-s <file> unix socket path to listen on (disables network support)   
-a <mask> access mask for unix socket, in octal (default 0700)   
-l <ip_addr> interface to listen on, default is INDRR_ANY   
-d run as a daemon   
-r maximize core file limit   
-u <username> assume identity of <username> (only when run as root)   
-m <num> max memory to use for items in megabytes, default is 64 MB   
-M return error on memory exhausted (rather than removing items)   
-c <num> max simultaneous connections, default is 1024   
-k lock down all paged memory. Note that there is a   
limit on how much memory you may lock. Trying to   
allocate more than that would fail, so be sure you   
set the limit correctly for the user you started   
the daemon with (not for -u <username> user;   
under sh this is done with 'ulimit -S -l NUM_KB').   
-v verbose (print errors/warnings while in event loop)   
-vv very verbose (also print client commands/reponses)   
-h print this help and exit   
-i print memcached and libevent license   
-P <file> save PID in <file>, only used with -d option   
-f <factor> chunk size growth factor, default 1.25   
-n <bytes> minimum space allocated for key+value+flags, default 48   
-R Maximum number of requests per event   
limits the number of requests process for a given con nection   
to prevent starvation. default 20   
-b Set the backlog queue limit (default 1024)   
-x <ip_addr> hostname or IP address of peer repcached   
-X <num:num> TCP port number for replication. <listen:connect> (default: 11212)

修改memcached目录所有者:   

cd ..   
chown -R memcached.memcached memcached

配置主从复制

参数说明:
-x 设置从哪个IP上进行同步。
-X 指定数据同步的端口。
Memcached默认服务端口是11211,默认同步监听端口是11212。
 
启动Master:
/usr/local/memcached/bin/memcached -d -m 100 -l 192.168.11.51 -p 11211 -u memcached -c 1024 -x 192.168.11.52 -X 11212 -P /var/run/memcached/memcached-rep.pid

查看监听端口:
netstat -tupln | grep memcached

tcp 0 0 192.168.11.51:11211 0.0.0.0:* LISTEN 18634/memcached
tcp 0 0 192.168.11.51:11212 0.0.0.0:* LISTEN 18634/memcached
udp 0 0 192.168.11.51:11211 0.0.0.0:* 18634/memcached


启动Slave:
/usr/local/memcached/bin/memcached -d -m 100 -l 192.168.11.52 -p 11211 -u memcached -c 1024 -x 192.168.11.51 -X 11212 -P /var/run/memcached/memcached-rep.pid

说明:-x 192.168.11.51用于同步的Master的IP地址。
查看监听端口:
netstat -tupln | grep memcached

tcp 0 0 192.168.11.52:11211 0.0.0.0:* LISTEN 24262/memcached
udp 0 0 192.168.11.52:11211 0.0.0.0:* 24262/memcached

验证数据同步

在Master创建数据:
[root@test01 bin]# telnet 192.168.11.51 11211

Trying 192.168.11.51...
Connected to 192.168.11.51.
Escape character is '^]'.
get key1
END
set key1 0 0 2
aa
STORED
quit
Connection closed by foreign host.

在Slave获取数据:
 [root@test02 bin]# telnet 192.168.11.52 11211

Trying 192.168.11.52...
Connected to 192.168.11.52.
Escape character is '^]'.
get key1
END
get key1
VALUE key1 0 2
aa
END
quit
Connection closed by foreign host.


在Slave创建数据:
[root@test02 bin]# telnet 192.168.11.52 11211

Trying 192.168.11.52...
Connected to 192.168.11.52.
Escape character is '^]'.
get key2
END
set key2 0 0 3
b
STORED
get key2
VALUE key2 0 3
b
END
quit
Connection closed by foreign host.


在Master获取数据:
[root@test01 bin]# telnet 192.168.11.51 11211

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/3a8dc6beb373b3a9042c4c3d43c54afb.html