一、安装环境版本
Linux版本:CentOS Linux release 7.5.1804
libevent版本:libevent-1.4.14b-stable
memcached版本:memcached-1.4.5
二、检查libevent
libevent是memcached必需的依赖包。首先检查系统中是否安装了libevent
检查命令:rpm -qa|grep libevent
[root@xh local]# rpm -qa|grep libevent
libevent-2.0.21-4.el7.x86_64
这个是系统自带的版本,卸载了重装。
卸载:rpm -e libevent-2.0.21-4.el7.x86_64
[root@xh local]# rpm -e libevent-2.0.21-4.el7.x86_64
error: Failed dependencies:
libevent is needed by (installed) nfs-utils-1:1.3.0-0.54.el7.x86_64
libevent-2.0.so.5()(64bit) is needed by (installed) nfs-utils-1:1.3.0-0.54.el7.x86_64
发现有依赖绑定,就是被其他工具引用了。因为是新系统,也没有安装其他工具,直接强制卸载。
强制卸载:rpm -e –nodeps libevent-2.0.21-4.el7.x86_64
[root@xh local]# rpm -e --nodeps libevent-2.0.21-4.el7.x86_64
[root@xh local]# rpm -qa|grep libevent
卸载完成后,再次查询,已经没有libevent。
三、安装libevent-1.4.14b-stable
以下操作建议直接使用root用户执行。
1.首先下载libevent安装包到本地
wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
如果下载报错,后面加上 –no-check-certificate 试试。
2.解压缩安装包
下载到哪个目录无所谓,解压时最好是 /usr/local/ 目录下
tar -zxvf libevent-1.4.14b-stable.tar.gz -C /usr/local/
建议解压后的目录,把 libevent-1.4.14b-stable 重命名为 libevent。
3.进入解压后的目录
[root@xh local]# cd /usr/local/libevent-1.4.14b-stable/
4.配置编译、安装
编译的目录可以自己定义,建议使用/usr、/usr/local ,此处我使用 /usr/local/libevent-1.4.14b-stable(你不要是问我为什么,问就是搞错了,后悔来不及了!所以听从建议哈!)
[root@xh libevent-1.4.14b-stable]# ./configure -prefix=/usr/local/libevent-1.4.14b-stable
[root@xh libevent-1.4.14b-stable]# make
[root@xh libevent-1.4.14b-stable]# make install
5.验证是否安装成功
ls -al /usr/local/libevent-1.4.14b-stable/lib | grep libevent (红色字体地方填写自己的安装目录)
[root@xh libevent-1.4.14b-stable]# ls -al /usr/local/libevent-1.4.14b-stable/lib | grep libevent
lrwxrwxrwx. 1 root root 21 Oct 21 14:14 libevent-1.4.so.2 -> libevent-1.4.so.2.2.0
-rwxr-xr-x. 1 root root 442592 Oct 21 14:14 libevent-1.4.so.2.2.0
-rw-r--r--. 1 root root 806898 Oct 21 14:14 libevent.a
lrwxrwxrwx. 1 root root 26 Oct 21 14:14 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.2.0
-rwxr-xr-x. 1 root root 165576 Oct 21 14:14 libevent_core-1.4.so.2.2.0
-rw-r--r--. 1 root root 270444 Oct 21 14:14 libevent_core.a
-rwxr-xr-x. 1 root root 1018 Oct 21 14:14 libevent_core.la
lrwxrwxrwx. 1 root root 26 Oct 21 14:14 libevent_core.so -> libevent_core-1.4.so.2.2.0
lrwxrwxrwx. 1 root root 27 Oct 21 14:14 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.2.0
-rwxr-xr-x. 1 root root 345816 Oct 21 14:14 libevent_extra-1.4.so.2.2.0
-rw-r--r--. 1 root root 644692 Oct 21 14:14 libevent_extra.a
-rwxr-xr-x. 1 root root 1025 Oct 21 14:14 libevent_extra.la
lrwxrwxrwx. 1 root root 27 Oct 21 14:14 libevent_extra.so -> libevent_extra-1.4.so.2.2.0
-rwxr-xr-x. 1 root root 983 Oct 21 14:14 libevent.la
lrwxrwxrwx. 1 root root 21 Oct 21 14:14 libevent.so -> libevent-1.4.so.2.2.0
安装完libevent之后为了让动态链接库为系统所共享,需要执行以下动态链接库的管理命令ldconfig
不过在执行ldconfig命令之前需要注意以下libevent的安装目录。具体参见:http://chenzhou123520.iteye.com/blog/1925196
注意:
如果编译地址没有选择/usr、/usr/local,libevent-1.4.14b-stable安装完成后需要执行下面一条命令将lib共享:
[root@xh local]# export LD_LIBRARY_PATH=/usr/local/libevent-1.4.14b-stable/lib:$LD_LIBRARY_PATH
四、安装memcached-1.4.5
1.首先是下载memcached的安装包
wget http://memcached.org/files/old/memcached-1.4.5.tar.gz
手动下载可以去 https://github.com/memcached/memcached/wiki/ReleaseNotes 里面查找。
2.修改安装包的执行操作权限
chmod 777 memcached-1.4.5.tar.gz
3.解压安装包到指定目录
tar -zxvf memcached-1.4.5.tar.gz -C /usr/local/
4.进入解压后的目录
[root@xh /]# cd /usr/local/memcached-1.4.5/
5.配置、编译、安装
注:configure时需要指定libevent的安装路径
[root@xh memcached-1.4.5]# ./configure -with-libevent=/usr/local/libevent-1.4.14b-stable/ -prefix=/usr/local/memcached-1.4.5
[root@xh memcached-1.4.5]# make
[root@xh memcached-1.4.5]# make install
在 make 时可能会出现安装报错 :
error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
解决方法:
修改memcached 的安装文件/usr/local/memcached-1.4.5/Makefile,其中有一行”CFLAGS = -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls“,把”-Werror” 删除即可顺利执行,警告不用管。
6.安装成功后启动并验证
(1)启动
[root@xh memcached-1.4.5]# /usr/local/memcached-1.4.5/bin/memcached -d -m 10m -p 11211 -u root
启动参数介绍如下:
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,这里是10MB,
-u 是运行Memcache的用户,这里是root,
-l 是监听的服务器IP地址,如果有多个地址的话,这里指定了服务器的IP地址192.168.0.200,
-p 是设置Memcache监听的端口,这里设置了11211 默认端口,最好是1024以上的端口,
-c 选项是最大运行的并发连接数,默认是1024,这里设置了256,按照服务器的负载量来设定,
-P 是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,也可以启动多个守护进程,不过端口不能重复。
(2)验证
先输入命令 telnet 192.168.10.17 11211
出现以下打印连接成功,
Trying 192.168.10.17…
Connected to 192.168.10.17.
Escape character is ‘^]’.
不要退出,后面接着输入 stats,然后回车,会打印Memcache的一些基本启动信息:
[root@xh memcached-1.4.5]# telnet 192.168.10.17 11211
Trying 192.168.10.17...
Connected to 192.168.10.17.
Escape character is '^]'.
stats
STAT pid 28188
STAT uptime 3797
STAT time 1666340603
STAT version 1.4.5
STAT pointer_size 64
STAT rusage_user 0.023713
STAT rusage_system 0.052170
STAT curr_connections 10
STAT total_connections 12
STAT connection_structures 11
STAT cmd_get 0
STAT cmd_set 0
......
END
其中stats 命令是查看状态,这就表示启动完成了。
退出telnet命令:quit
(3)编写memcached启动脚本
在目录下 /usr/local/memcached-1.4.5/bin 创建文件 startup.sh,内容如下:
[root@xh local]# cd /usr/local/memcached-1.4.5/bin
[root@xh bin]# touch startup.sh
[root@xh bin]# vim startup.sh
#!/bin/sh
echo "Start to start memcached server $(date)..."
MEMCACHED=/usr/local/memcached-1.4.5/bin/memcached
usage()
{
echo "usage: `basename $0` port"
}
if [ -n "$1" ]
then
{
pid=`ps aux|grep memcached|grep "$1" |grep -v grep|awk '{print $2}'`
if [ -n "$pid" ]
then
{
sleep 2
echo "kill memcached which port is $1 begin"
echo "pid:$pid"
kill -9 $pid
echo "kill memcached which port is $1 end"
sleep 2
}
fi
echo "begin to start memcached in port $1"
LOG_FILE=/var/log/memcached/memcached_$1.log
rm -f $LOG_FILE
$MEMCACHED -d -m 2048 -p $1 -u root -vv >> $LOG_FILE 2>&1
echo "start memcached end"
tail -f $LOG_FILE
}
else
{
usage
exit 1
}
fi
注意memcached 路径配置。
memcached启动:sh startup.sh 11211
memcached停止:查找进程,然后kill,如下,
[root@xh bin]# ps -ef | grep memcached
root 28188 1 0 15:20 ? 00:00:00 /usr/local/memcached-1.4.5/bin/memcached -d -m 10m -p 11211 -u root
root 34666 13519 0 16:54 pts/0 00:00:00 grep --color=auto memcached
[root@xh bin]# kill -9 28188
[root@xh bin]# ps -ef | grep memcached
root 34675 13519 0 16:54 pts/0 00:00:00 grep --color=auto memcached
7.设置开机启动
(后面再补。)
8.配置日志
如果要给memcached上配置日志,参见:http://chenzhou123520.iteye.com/blog/1925209
(完)。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/62141.html