Linux中管理Memcached的Service脚本的例子
2019/10/10/17:46:13 阅读:1789 来源:谷歌SEO算法 标签:
SEO技术
下面我们一起来看一个Linux中管理Memcached的Service脚本的例子,希望此例子可以对各位带来帮助,Memcached需要libevent支持,所以需要先检查libevent是否已经安装.
下面是Memcached的安装过程:
- #tarzvxfmemcached-1.4.9.tar.gz
- #cdmemcached-1.4.9
- #./configure--prefix=/usr/local/memcached
- #make
- #makeinstall
启动Memcached:
- #/usr/local/memcached/bin/memcached-d-m128-l127.0.0.1-p11211-uroot
参数128指定了内存使用量,接下来是为PHP安装memcache扩展:
- #gzip-dmemcache-2.2.6.tgz
- #tarxvfmemcache-2.2.6.tar
- #cdmemcache-2.2.6
- #/usr/local/php/bin/phpize
- #./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache//phpfensi.com
- #make
- #makeinstall
最后将如下配置信息添加到php.ini文件中:
- extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
- extension=memcache.so
备注:/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/这个路径可能会有不同,以您机器中的为准.
Memcached已在Linux中安装完毕,且被部署到/usr/local/memcached这个路径下,接下来我们来开始为其安装用于启动和停止的服务管理脚本.
首先,通过vi在/etc/rc.d/init.d路径下新建一个名为memcached的脚本文件,命令如下:
vi /etc/rc.d/init.d/memcached
然后,向其中写入Shell脚本如下:
- #!/bin/sh
- #
- #chkconfig:23459050
- #description:MemcachedServiceDaemon
- #
- #processname:Memcached
- #
- #Sourcefunctionlibrary.
- ./etc/rc.d/init.d/functions
- ./etc/sysconfig/network
- #[${NETWORKING}="no"]&&exit0
- #[-r/etc/sysconfig/dund]||exit0
- #./etc/sysconfig/dund
- #[-z"$DUNDARGS"]&&exit0
- MEMCACHED="/usr/local/memcached/bin/memcached"
- start()
- {
- echo-n$"StartingMemcached:"
- daemon$MEMCACHED-udaemon-d-m32-l127.0.0.1-p11211-c256-P/tmp/memcached.pid
- echo
- }
- stop()
- {
- echo-n$"ShuttingdownMemcached:"
- killprocmemcached
- echo
- }
- [-f$MEMCACHED]||exit1
- #Seehowwewerecalled.
- case"$1"in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- sleep3
- start
- ;;
- *)
- echo$"Usage:$0{start|stop|restart}"
- exit1
- esac
- exit0
保存退出vi后,执行下面的命令来安装这个脚本.
- chmod777/etc/rc.d/init.d/memcached
- chkconfig--addmemcached
- chkconfig--level235memcachedon
然后可以通过下面的命令来检查是否安装成功.
- chkconfig--list|grepmemcached
- servicememcachedstart
- servicememcachedstop
- servicememcachedrestart
热门评论