1、安装Memcached服务端
1) 手工安装
a) 安装libevent库
Debian/Ubuntu: apt-get install libevent-devRedhat/Centos: yum install libevent-develb) 下载解压并安装
wget https://memcached.org/latest[you might need to rename the file]tar -zxf memcached-1.x.x.tar.gzcd memcached-1.x.x./configure --prefix=/usr/local/memcachedmake && make test && sudo make install
ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached
/bin/cp scripts/memcached.sysv /etc/init.d/memcached
sed -i 's@^USER=.*@USER=root@' /etc/init.d/memcached
sed -i 's@chown@#chown@' /etc/init.d/memcached
sed -i 's@/var/run/memcached/memcached.pid@/var/run/memcached.pid@' /etc/init.d/memcached
sed -i 's@^prog=.*@prog="/usr/local/memcached/bin/memcached"@' /etc/init.d/memcached #前面有软链接,这里可以省略
chmod +x /etc/init.d/memcached
chkconfig --add memcached
chkconfig memcached on
cd ..
2) 自动安装
For Debian or Ubuntu: apt-get install memcached
For Redhat/Fedora: yum install memcached
编译安装结果打印
[root@localhost memcached-1.4.37]# make install
make install-recursive
make[1]: 进入目录“/data/software/memcached-1.4.37”
Making install in doc
make[2]: 进入目录“/data/software/memcached-1.4.37/doc”
make install-am
make[3]: 进入目录“/data/software/memcached-1.4.37/doc”
make[4]: 进入目录“/data/software/memcached-1.4.37/doc”
make[4]: 对“install-exec-am”无需做任何事。
/usr/bin/mkdir -p '/usr/local/memcached/share/man/man1'
/usr/bin/install -c -m 644 memcached.1 '/usr/local/memcached/share/man/man1'
make[4]: 离开目录“/data/software/memcached-1.4.37/doc”
make[3]: 离开目录“/data/software/memcached-1.4.37/doc”
make[2]: 离开目录“/data/software/memcached-1.4.37/doc”
make[2]: 进入目录“/data/software/memcached-1.4.37”
make[3]: 进入目录“/data/software/memcached-1.4.37”
/usr/bin/mkdir -p '/usr/local/memcached/bin'
/usr/bin/install -c memcached '/usr/local/memcached/bin'
/usr/bin/mkdir -p '/usr/local/memcached/include/memcached'
/usr/bin/install -c -m 644 protocol_binary.h '/usr/local/memcached/include/memcached'
make[3]: 离开目录“/data/software/memcached-1.4.37”
make[2]: 离开目录“/data/software/memcached-1.4.37”
make[1]: 离开目录“/data/software/memcached-1.4.37”
2、启动Memcached
1) service memcached start #或者执行下面
2) memcached -p 11211 -l 127.0.0.1 -d -u root -P /var/run/memcached.pid -m 64M -c 1024
3) 几个参数的解释:
- -p memcached监听的TCP端口
- -l 监听的ip地址,127.0.0.1是本机,当然也可以写上你的服务器IP,如:10.0.0.10,这是我服务器的IP地址,如果你需要多个服务器都能够读取这台memcached的缓存数据,那么就必须设定这个ip
- -d 以daemon方式运行,将程序放入后台
- -u memcached的运行用户,我设定的是nobody
- -P memcached的pid文件路径
- -m memcached可以使用的最大内存数量
- -c memcached同时可以接受的最大的连接数
如果你希望以socket方式来访问memcached,那么在启动的时候就必须去掉 -l和-p参数,并加上-s参数:
- -s memcached的socket文件路径