首页 小组 文章 搜索 用户
全部 linux Nginx Apache PHP DNS windows 其它 同步与备份 js 数据库 前端 unix

把memcached服务端纳入systemd管理支持debian和ubuntu及centos

天边的云
发表于 2021-01-15 17:09:47

注意此脚本支持centos7.x和ubuntu16.x及debian8.x或以上版本,更低的版本不支持,memcached运行于nobody用户下,非常安全

编译安装memcached,每个发行版本不一样,所以自行安装支持组件

osyum="http://yum.osyum.com"
libevent=$(curl $osyum/ver/libevent.txt)
memcachedserver=$(curl $osyum/ver/memcachedserver.txt)
wget http://yum.osyum.com/linux/libevent/$libevent.tar.gz
wget http://www.memcached.org/files/$memcachedserver.tar.gz
tar -zxf $libevent.tar.gz 
tar -zxvf $memcachedserver.tar.gz 
cd $libevent
mkdir -p /usr/local/libevent
./configure --prefix=/usr/local/libevent
make && make install
echo "/usr/local/libevent/lib/" >> /etc/ld.so.conf
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib/libevent-2.0.so.5
ldconfig
cd ..
cd $memcachedserver 
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make && make install
ln /usr/local/memcached/bin/memcached /usr/bin/memcached

创建memcached配置文档

mkdir -p /usr/local/memcached/etc
touch /usr/local/memcached/etc/memcached.ini

编辑/usr/local/memcached/etc/memcached.ini并录入以下信息

PORT=11211
USER=nobody
MAXCONN=1024
CACHESIZE=64
OPTIONS=""

保存并退出

创建启动文件

touch /lib/systemd/system/memcached.service

录入以下信息

[Unit]
Description=Memcached server
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=/usr/local/memcached/etc/memcached.ini
ExecStart=/usr/local/memcached/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

[Install]
WantedBy=multi-user.target

保存并退出。

创建软连

ln -s /lib/systemd/system/memcached.service /etc/systemd/system/multi-user.target.wants/memcached

载入启动

systemctl daemon-reload 

开机自启

systemctl enable memcached

开始服务

systemctl start memcached



143 0

评论