`
dean_liu
  • 浏览: 75316 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

安装repcached memcached

 
阅读更多
分别在两台服务器中安装libevent与repcached memcached

一、安装libevent
1.先用:ls -al /usr/lib | grep libevent  查看是否已安装,如果已安装且版本低于1.3,则先通过:rpm -e libevent —nodeps 进行卸载。

2.下载libevent安装包:libevent-1.4.13-stable.tar.gz,然后解压。

3.切换到解压后的 libevent 主目录:cd libevent-1.4.13-stable

4.依次执行:
./configure --prefix=/usr (或 ./configure --program-prefix=/usr)  
make  
make install  

  注意:
1)执行 make install 时可能需要 root 权限。

2)libevent会安装到 /usr/lib 下。


5.测试libevent是否安装成功:ls -al /usr/lib | grep libevent
出现类似下图结果则表示安装成功:
lrwxrwxrwx.  1 root root     21 Jun 17 00:35 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3
-rwxr-xr-x.  1 root root 373214 Jun 17 00:35 libevent-1.4.so.2.1.3
-rw-r--r--.  1 root root 603890 Jun 17 00:35 libevent.a
lrwxrwxrwx.  1 root root     26 Jun 17 00:35 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.3
-rwxr-xr-x.  1 root root 137329 Jun 17 00:35 libevent_core-1.4.so.2.1.3
-rw-r--r--.  1 root root 228968 Jun 17 00:35 libevent_core.a
-rwxr-xr-x.  1 root root    860 Jun 17 00:35 libevent_core.la
lrwxrwxrwx.  1 root root     26 Jun 17 00:35 libevent_core.so -> libevent_core-1.4.so.2.1.3
lrwxrwxrwx.  1 root root     27 Jun 17 00:35 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.3
-rwxr-xr-x.  1 root root 295868 Jun 17 00:35 libevent_extra-1.4.so.2.1.3
-rw-r--r--.  1 root root 469074 Jun 17 00:35 libevent_extra.a
-rwxr-xr-x.  1 root root    867 Jun 17 00:35 libevent_extra.la
lrwxrwxrwx.  1 root root     27 Jun 17 00:35 libevent_extra.so -> libevent_extra-1.4.so.2.1.3
-rwxr-xr-x.  1 root root    825 Jun 17 00:35 libevent.la
lrwxrwxrwx.  1 root root     21 Jun 17 00:35 libevent.so -> libevent-1.4.so.2.1.3



6.如果libevent的安装目录为/usr/local/lib下,则还需要建立 libevent-1.4.so.2 到 /usr/lib 的软连接,这样其他程序运行时才能找到libevent库:ln -s /usr/local/lib/libevent-1.4.so.2  /usr/lib/libevent-1.4.so.2

二、安装repcached memcached
1.下载repcached安装包:memcached-1.2.8-repcached-2.2.1.tar.gz,然后解压。

2.切换到解压后的 repcached memcached 主目录:cd memcached-1.2.8-repcached-2.2.1

3.依次执行:
./configure --enable-replication 
make  
make install  


4.如果在64位系统中运行memcached可能会出现如下错误:
/usr/local/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
则使用libs参数调试:
LD_DEBUG=libs /usr/local/bin/memcached -v
可以看到以下输出:
     10641:     find library=libevent-1.4.so.2 [0]; searching
     10641:      search cache=/etc/ld.so.cache
     10641:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64                (system search path)
     10641:       trying file=/lib64/tls/x86_64/libevent-1.4.so.2
     10641:       trying file=/lib64/tls/libevent-1.4.so.2
     10641:       trying file=/lib64/x86_64/libevent-1.4.so.2
     10641:       trying file=/lib64/libevent-1.4.so.2
     10641:       trying file=/usr/lib64/tls/x86_64/libevent-1.4.so.2
     10641:       trying file=/usr/lib64/tls/libevent-1.4.so.2
     10641:       trying file=/usr/lib64/x86_64/libevent-1.4.so.2
     10641:       trying file=/usr/lib64/libevent-1.4.so.2
     10641:
/usr/local/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

可知memcached并没有在/usr/lib中加载libevent-1.4.so.2,而是在/usr/lib64中。
故在/usr/lib64中创建/usr/lib/libevent-1.4.so.2的软链接:
ln -s /usr/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2

三、验证
1.在第一个服务器执行:
[root@localhost ~]# /usr/local/bin/memcached -u nobody -l 192.168.73.201 -p 22122 -m 64 -x 192.168.73.202 -v
replication: connect (peer=192.168.73.202:11212)
replication: marugoto copying
replication: close
replication: listen


2.在第二个服务器执行:
[root@localhost ~]# /usr/local/bin/memcached -u nobody -l 192.168.73.202 -p 22122 -m 64 -x 192.168.73.201 -v
replication: connect (peer=192.168.73.201:11212)
replication: marugoto copying
replication: start

这时在第一个服务器中会输出:
replication: accept

3.在第一个服务器中设置key value对:
[root@localhost ~]# telnet 192.168.73.201 22122
Trying 192.168.73.201...
Connected to 192.168.73.201.
Escape character is '^]'.
set hey 0 0 4
dude
STORED
get hey
VALUE hey 0 4
dude
END
quit
Connection closed by foreign host


4.在第二个服务器中取出key value对:
[root@localhost ~]# telnet 192.168.73.202 22122
Trying 192.168.73.202...
Connected to 192.168.73.202.
Escape character is '^]'.
get hey
VALUE hello 0 4
dude
END
quit
Connection closed by foreign host.


5.好了,repcached memcached已经安装配置完成。
另外,安装telnet客户端的命令是:
yum -y install telnet

#后台运行:
/usr/local/bin/memcached -d -m 128 -u root -p 11211 -P /tmp/memcached.pid

# 结束memcache进程
kill `cat /tmp/memcached.pid`

参数:
      -d 启动守护进程(后台运行)
      -m 分配给memcache使用的内存,单位是MB
      -u 运行memcached的用户
      -l 监听的服务器IP
      -p 监听的服务器端口,默认是11211
      -c 最大运行的并发连接数,默认是1024
      -P(大写) 保存Memcache的pid文件,后面跟路径
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics