centos 下mysql 与memcached的整合

一、     成功安装的软件列表

mysql-5.1.43-linux-x86_64-icc-glibc23.tar.gz

libvent-1.4.7-stable.tar.gz

memcached-1.2.6.tar.gz

libmemcached-0.26.tar.gz

memcached_functions_mysql_1.0.tar.gz

二、     安装步骤

通过filezilla root 用户登录把

libevent-1.4.7-stable.tar.gz

memcached-1.2.6.tar.gz

libmemcached-0.26.tar.gz

memcached_functions_mysql_1.0.tar.gz

4个安装文件 传输到 centos 下的/root/Desktop 目录下

mysql-5.1.43-linux-x86_64-icc-glibc23.tar.gz

传输到 centos 下的/usr/local 目录下

1、安装MySQL

先检查系统是否装上了mysql,如果有将其卸载掉

rpm -qa | grep -i mysql

注意mysql的大小写,大小写都有可能。

定要用—nodeps卸载,不检查依赖性关系(强制性卸载)

rpm -e --nodeps mysql*

创建用户mysql,并设置密码

groupadd mysql

useradd -g mysql mysql

passwd mysql

MySQL安装在/usr/local/mysql的目录下并设置相关权限操作

cd /usr/local

由于刚开始以用户siku 登录所以会报权限不够的错误。

执行 su root

输入root 的密码  如下图:

tar xzvf  mysql-5.1.43-linux-x86_64-icc-glibc23.tar.gz

ln -s mysql-5.1.43-linux-x86_64-icc-glibc23 mysql

cd mysql

./scripts/mysql_install_db --user=mysql

如果出现下列错误请安装compat-libstdc++-33-3.2.3-61.x86_64.rpm

执行rpm -ivh compat-libstdc++-33-3.2.3-61.x86_64.rpm

./scripts/mysql_install_db --user=mysql

文件安装成功。

chown -R root .

chown -R mysql data

cd /etc/rc.d/init.d

cp /usr/local/mysql/support-files/mysql.server  mysql

chmod +x mysql

/sbin/chkconfig --del mysql

/sbin/chkconfig --add mysql

/etc/rc.d/init.d/mysql start

    运行命令,进入命令行操作,默认密码为空

/usr/local/mysql/bin/mysql

安装成功!

2、安装libevent/usr/lib目录

memcached使用了libevent所以必须先安装libevent。安装libevent/usr/lib:

cd /root/Desktop

tar xvf  libevent-1.4.7-stable.tar.gz

cd libevent-1.4.7-stable

./configure --prefix=/usr

make

make install

安装成功

 


3、安装memcached/usr/local/memcached目录

Cd ..

tar xvf memcached-1.2.6.tar.gz

cd memcached-1.2.6

./configure --prefix=/usr/local/memcached --with-libevent=/usr

make

make install

运行如下命令测试安装是否成功:

/usr/local/memcached/bin/memcached -h

提示/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2:

cannot open shared object file: No such file or directory

出现上述错误一般是由于库文件依赖有问题,这是需要使用libs命令

#LD_DEBUG=libs /usr/local/memcached/bin/memcached -h

     30596:     find library=libevent-1.4.so.2 [0]; searching

     30596:      search cache=/etc/ld.so.cache

     30596:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64

/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64

(system search path)

     30596:       trying file=/lib64/tls/x86_64/libevent-1.4.so.2

     30596:       trying file=/lib64/tls/libevent-1.4.so.2

     30596:       trying file=/lib64/x86_64/libevent-1.4.so.2

     30596:       trying file=/lib64/libevent-1.4.so.2

     30596:       trying file=/usr/lib64/tls/x86_64/libevent-1.4.so.2

     30596:       trying file=/usr/lib64/tls/libevent-1.4.so.2

     30596:       trying file=/usr/lib64/x86_64/libevent-1.4.so.2

     30596:       trying file=/usr/lib64/libevent-1.4.so.2

     30596:

/usr/local /memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2:

cannot open shared object file: No such file or directory

可以看到是在加载/usr/lib64/libevent-1.4.so.2文件时出现了问题系统中确实是没有该文件的查找后发现 libevent-1.4.so.2存在于/usr/lib目录这可能是libevent64Linux系统上的一个bug没有关系复制一份或者建一个软链接即可解决问题。

下面建立一个软链接:

#ln -s /usr/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2

 

笔者采用上述memcached版本出现上述蓝色部分的错误,当没错误的使用,可以使用命令:

/usr/local/memcached/bin/memcached –h

memcached命令帮助信息如下结果:

memcached 1.4.4

-p <num>      TCP port number to listen on (default: 11211)

-U <num>      UDP port number to listen on (default: 11211, 0 is off)

-s <file>     UNIX socket path to listen on (disables network support)

-a <mask>     access mask for UNIX socket, in octal (default: 0700)

-l <ip_addr>  interface to listen on (default: INADDR_ANY, all addresses)

-d            run as a daemon

-r            maximize core file limit

-u <username> assume identity of <username> (only when run as root)

-m <num>      max memory to use for items in megabytes (default: 64 MB)

-M            return error on memory exhausted (rather than removing items)

-c <num>      max simultaneous connections (default: 1024)

-k            lock down all paged memory.  Note that there is a

              limit on how much memory you may lock.  Trying to

              allocate more than that would fail, so be sure you

              set the limit correctly for the user you started

              the daemon with (not for -u <username> user;

              under sh this is done with 'ulimit -S -l NUM_KB').

-v            verbose (print errors/warnings while in event loop)

-vv           very verbose (also print client commands/reponses)

-vvv          extremely verbose (also print internal state transitions)

-h            print this help and exit

-i            print memcached and libevent license

-P <file>     save PID in <file>, only used with -d option

-f <factor>   chunk size growth factor (default: 1.25)

-n <bytes>    minimum space allocated for key+value+flags (default: 48)

-L            Try to use large memory pages (if available). Increasing

              the memory page size could reduce the number of TLB misses

              and improve the performance. In order to get large pages

              from the OS, memcached will allocate the total item-cache

              in one large chunk.

-D <char>     Use <char> as the delimiter between key prefixes and IDs.

              This is used for per-prefix stats reporting. The default is

              ":" (colon). If this option is specified, stats collection

              is turned on automatically; if not, then it may be turned on

              by sending the "stats detail on" command to the server.

-t <num>      number of threads to use (default: 4)

-R            Maximum number of requests per event, limits the number of

              requests process for a given connection to prevent

              starvation (default: 20)

-C            Disable use of CAS

-b            Set the backlog queue limit (default: 1024)

-B            Binding protocol - one of ascii, binary, or auto (default)

-I            Override the size of each slab page. Adjusts max item size

              (default: 1mb, min: 1k, max: 128m)

各参数的含义在另一文档有说明,启动memcached命令:

#/usr/local/memcached/bin/memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211

至此,memcached安装成功并在本地以11211端口启动!

4、安装libmemcached

安装命令如下:

cd /root/Desktop

tar xzf libmemcached-0.26.tar.gz

cd libmemcached-0.26

./configure –with-memcached=/usr/local/memcached/bin/memcached

make

make install

5、安装memcached UDFs for MySQL

命令如下:

cd /root/Desktop

tar xzf memcached_functions_mysql-1.0.tar.gz

cd memcached_functions_mysql-1.0

./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/

执行上述命令后,如果出现找不到libmemcached的错误,那么请执行下列命令:

export LD_LIBRARY_PATH=/usr/local/lib

然后再执行:

make

make install

编译完成后,将编译好的库文件复制到mysql 的插件目录下,以便加载使用。

cp /usr/local/mysql/lib/mysql/libmemcached_functions_mysql* /usr/local/mysql/lib/plugin/

进入memcached_functions_mysql的源码目录,在目录下添加UDFSQL文件用于初始化,命令如下:

#/usr/local/mysql/bin/mysql <sql/install_functions.sql

 

至此,相关的软件的编译和安装完成。

 

四、注意事项和错误解决方案

1、注意事项

    MySQL官方提供三个版本下载,分别是RPM/二进制/源码版,由于编译安装memcached UDFs for MySQL时需要指定MySQL的相关信息,采用RPM版(安装文件路径分散,对LinuxMySQL不是非常熟悉的人,难以把握)不合适。MySQL官方不推荐使用源码版(个人觉得那是高手使用的东西,需要自己编译,安装特别麻烦,用它是自找苦吃),故本人采用的是二进制版(MySQL已经编译完成)的MySQL。至于如何区别MySQL的二进制版和源码版的信息,自己Google!

    安装的时候请注意软件版本,否则可能导致不成功。

    本人虚拟机里面测试安装,最初装了虚拟机的VMware Tools,软件一直没装成功,不知是否是这样的一个错误导致。建议在虚拟机里面安装软件环境先不要安装虚拟机的VMware Tools

2、错误指南:

Error1:

    上述的错误一般是由于软件的版本不兼容导致的,所以建议重新选择安装libmemcached的版本。

Error2:

    上述的错误是由命令:

    ./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/

导致安装memcached UDFs for MySQL导致找不到libmemcachedlib环境,故本人采用命令加入该libmencachedLib环境

    export LD_LIBRARY_PATH=/usr/local/lib

再重复上述编译就OK了。

    总结:上述两个错误时安装的过程中最易犯也是最难检查的。

 

五、参考资料

http://www.libing.name/2009/02/06/mysql-map-data-to-memcached.html

http://hg.tangent.org/memcached_functions_mysql/file/724eeccc55bc/README

http://download.tangent.org/

http://forums.mysql.com/read.php?150,182016,182016#msg-182016

 

 

你可能感兴趣的:(vmware,mysql,linux,centos,memcached)