CentOS 7.x安装部署Memcached服务器的详细方法
操作系统:CentOS7.x64位
实现目的:安装部署Memcached服务器
一、防火墙设置
CentOS7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。
1、关闭firewall:
systemctlstopfirewalld.service#停止firewall
systemctldisablefirewalld.service#禁止firewall开机启动
2、安装iptables防火墙
yuminstalliptables-services#安装
vi/etc/sysconfig/iptables#编辑防火墙配置文件
#sampleconfigurationforiptablesservice
#youcaneditthismanuallyorusesystem-config-firewall
#pleasedonotaskustoaddadditionalports/servicestothisdefaultconfiguration
*filter
:INPUTACCEPT[0:0]
:FORWARDACCEPT[0:0]
:OUTPUTACCEPT[0:0]
-AINPUT-mstate--stateRELATED,ESTABLISHED-jACCEPT
-AINPUT-picmp-jACCEPT
-AINPUT-ilo-jACCEPT
-AINPUT-ptcp-mstate--stateNEW-mtcp--dport22-jACCEPT
-AINPUT-ptcp-mstate--stateNEW-mtcp--dport11211-jACCEPT
-AINPUT-jREJECT--reject-withicmp-host-prohibited
-AFORWARD-jREJECT--reject-withicmp-host-prohibited
COMMIT
:wq!#保存退出
systemctlrestartiptables.service#最后重启防火墙使配置生效
systemctlenableiptables.service#设置防火墙开机启动
/usr/libexec/iptables/iptables.initrestart#重启防火墙
二、关闭SELINUX
vi/etc/selinux/config
#SELINUX=enforcing#注释掉
#SELINUXTYPE=targeted#注释掉
SELINUX=disabled#增加
:wq!#保存退出
setenforce0#使配置立即生效
三、系统约定
软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
四、下载软件包
1、下载libevent
http://ftp.lfs-matrix.net/pub/blfs/conglomeration/libevent/libevent-2.0.22-stable.tar.gz
2、下载memcached
http://memcached.org/files/memcached-1.4.34.tar.gz
五、安装编译工具包
yuminstall-yapr*autoconfautomakebisonbzip2bzip2*cloog-pplcompat*cppcurlcurl-develfontconfigfontconfig-develfreetypefreetype*freetype-develgccgcc-c++gtk+-develgdgettextgettext-develglibckernelkernel-headerskeyutilskeyutils-libs-develkrb5-devellibcom_err-devellibpnglibpng-devellibjpeg*libsepol-devellibselinux-devellibstdc++-devellibtool*libgomplibxml2libxml2-devellibXpm*libxml*libtifflibtiff*makempfrncurses*ntpopensslopenssl-develpatchpcre-develperlphp-commonphp-gdpolicycoreutilstelnett1libt1lib*nasmnasm*wgetzlib-devel
六、安装配置memcached
1、安装libevent
cd/usr/local/src
tarzxvflibevent-2.0.22-stable.tar.gz
cdlibevent-2.0.22-stable
./configure--prefix=/usr/local/libevent
make
makeinstall
2、安装memcached
cd/usr/local/src
tarzxvfmemcached-1.4.34.tar.gz
cdmemcached-1.4.34
./configure--enable-sasl--prefix=/usr/local/memcached-with-libevent=/usr/local/libevent
make
makeinstall
3、测试Memcached
groupaddmemcached#创建组
useradd-gmemcachedmemcached-s/bin/false#创建账号
ln-s/usr/local/memcached/bin/memcached/usr/local/bin/memcached#添加软连接
启动Memcache的服务器端的命令为:
/usr/local/memcached/bin/memcached-d-m4096-uroot-l192.168.4.6-p11211-c1024-P/usr/local/memcached/memcached.pid
或者
/usr/local/memcached/bin/memcached-d-m4096-umemcached-l192.168.4.6-p11211-c1024
参数说明:
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,这里是4096MB
-u是运行Memcache的用户,比如root或者memcached
-l是监听的服务器IP地址,这里指定服务器的IP地址192.168.4.6,不设置默认监听服务器所有IP地址
-p是设置Memcache监听的端口,默认为11211
-c选项是最大运行的并发连接数,默认是1024
-P是设置保存Memcache的pid文件,/usr/local/memcached/memcached.pid
开机自启动,在/etc/rc.d/rc.local中加入一行
/usr/local/memcached/bin/memcached-d-m4096-uroot-l192.168.4.6-p11211-c1024-P/usr/local/memcached/memcached.pid
也可以使用下面的命令:
/usr/local/memcached/bin/memcached-d-m4096-p11211-umemcached
ip不指定时,默认监听本地所有ip地址,用户最好选择是非root用户,例如memcached
关闭Memcached服务
cat/usr/local/memcached/memcached.pid#查看进程
kill22856#结束进程
或者
killallmemcached#结束服务
系统运维www.osyunwei.com温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链接
4、设置Memcached开机启动
vi/etc/rc.d/init.d/memcached
#!/bin/sh
#
#memcached:MemCachedDaemon
#
#chkconfig:-9025
#description:MemCachedDaemon
#
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
./etc/sysconfig/network
MEMCACHED="/usr/local/memcached/bin/memcached"
start()
{
echo-n$"Startingmemcached:"
daemon$MEMCACHED-umemcached-d-m4096-p11211-c1024
echo
}
stop()
{
echo-n$"Shuttingdownmemcached:"
killprocmemcached
echo
}
[-f$MEMCACHED]||exit0
#Seehowwewerecalled.
case"$1"in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
condrestart)
stop
start
;;
*)
echo$"Usage:$0{start|stop|restart|reload|condrestart}"
exit1
esac
exit0
:wq!#保存退出
chmod775/etc/rc.d/init.d/memcached#赋予文件执行权限
chkconfigmemcachedon#设置开机启动
/etc/rc.d/init.d/memcachedstart#启动
至此,Linux下Memcached服务器部署完成。