【Memcache】32位redhat6系统安装memcache

一:准备工作

检查服务器上是否已安装libeventrpm包,具体操作如下:

# rpm –q
libevent

若没有,请在linux软件安装包中找到libevent-.rpm,上传至服务器,然后用命令rpm –u libevent-.rpm安装

二:软件安装

使用root用户将memcached-1.4.5.tar.gz上传至服务器上的/usr/local目录下,用root用户登录服务器进行如下安装操作:

# cd
/usr/local

# tar zxvf memcached-1.4.5.tar.gz

# cd
memcached-1.4.5

# ./configure

# make

# make
install

查看memcached是否安装成功

# ls -al
/usr/local/bin/mem*

成功如下图

memcache安装成功图

三:编写memcache系统服务

# cd
/etc/rc.d/init.d

# vi memcached

i键,进入编辑模式,输入如下信息(不包含中文注释),其中MEMCACHEDMEMCACHED_PIDMEMCACHED_IPMEMCACHED_USERMEMCACHED_PORT MEMCACHED_MEMORY请按实际情况配置



1.2. <span class="pln">#!/bin/sh </span>
3. <span class="pln"># </span>
4. <span class="pln"># memcached: MemCached Daemon </span>
5. <span class="pln"># </span>
6. <span class="pln"># chkconfig: - 90 25 </span>
7. <span class="pln"># description: MemCached Daemon </span>
8. <span class="pln"># </span>
9. <span class="pln"># Source function library.</span>
10. <span class="pln">. /etc/rc.d/init.d/functions</span>
11. <span class="pln">. /etc/sysconfig/network</span>
12. <span class="pln">RETVAL=0 </span>
13. <span class="pln">#memcached安装目录下的memcached脚本路径</span>
14. <span class="pln">#MEMCACHED=/root/memcached/bin/memcached</span>
15. <span class="pln">MEMCACHED=/usr/local/memcached-1.4.21 </span>
16. <span class="pln">#memcached_pid存放路径,可自行定义,但须确保存在该目录</span>
17. <span class="pln">MEMCACHED_PID=/root/logs/memcached.pid</span>
18. <span class="pln">#启动memcached的服务器IP</span>
19. <span class="pln">MEMCACHED_IP=10.1.195.88</span>
20. <span class="pln">#启动memcached的用户</span>
21. <span class="pln">MEMCACHED_USER=root</span>
22. <span class="pln">#启动memcached的端口</span>
23. <span class="pln">MEMCACHED_PORT=11211</span>
24. <span class="pln">#启动内存 单位(M)</span>
25. <span class="pln">MEMCACHED_MEMORY=8192m</span>
26.27. <span class="pln">start()</span>
28. <span class="pln">{</span>
29. <span class="pln"> if [ -e $MEMCACHED_PID];then</span>
30. <span class="pln"> echo "memcached already running...."</span>
31. <span class="pln"> exit 0</span>
32. <span class="pln"> fi</span>
33. <span class="pln"> echo -n $"Starting memcached: "</span>
34. <span class="pln"> daemon $MEMCACHED -u $MEMCACHED_USER -d -m $MEMCACHED_MEMORY -l $MEMCACHED_IP -p $MEMCACHED_PORT</span>
35. <span class="pln"> RETVAL=$?</span>
36. <span class="pln"> echo</span>
37. <span class="pln"> [ $RETVAL = 0 ] &amp;&amp; touch $MEMCACHED_PID</span>
38. <span class="pln"> return $RETVAL</span>
39. <span class="pln">}</span>
40. <span class="pln">stop()</span>
41. <span class="pln">{</span>
42. <span class="pln"> echo -n $"Shutting down memcached: "</span>
43. <span class="pln"> killproc memcached</span>
44. <span class="pln"> RETVAL=$?</span>
45. <span class="pln"> echo</span>
46. <span class="pln"> [ $RETVAL = 0 ] &amp;&amp; rm -f $MEMCACHED_PID</span>
47. <span class="pln">}</span>
48. <span class="pln">#[ -f $MEMCACHED] || exit 0</span>
49. <span class="pln"># See how we were called.</span>
50. <span class="pln">case "$1" in</span>
51. <span class="pln">start)</span>
52. <span class="pln"> start</span>
53. <span class="pln"> ;;</span>
54. <span class="pln">stop)</span>
55. <span class="pln"> stop</span>
56. <span class="pln"> ;;</span>
57. <span class="pln">restart)</span>
58. <span class="pln"> stop</span>
59. <span class="pln"> sleep 3</span>
60. <span class="pln"> start</span>
61. <span class="pln"> ;;</span>
62. <span class="pln">*)</span>
63. <span class="pln"> echo $"Usage: $0 {start|stop|restart}"</span>
64. <span class="pln"> exit 1</span>
65. <span class="pln">esac</span>
66. <span class="pln">exit $RETVAL</span>


ESC键,退出编辑模式,输入命令:wq保存退出。

四:启动memcache服务

使用命令service memcached start启动memcached服务,出现如下信息即启动成功:

Service  memcached          [OK]

在本地机器telnet memcached服务器的11211端口,能够连接上即表示服务正常启动。

五:常见问题记录

1. libevent没有安装

下载libevent安装包,编译安装

       ./configure –prefix=/usr

       make 

       make install


 

your support will encourage me to continue to create!
版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)