标签:mysql
MySQL调优(mamcache)
架构
Web+memcache [192.168.5.14]
Memcached [192.168.5.16]
Mysql [192.168.5.15]
搭建lamp架构[5.14]
yum install http* php* mysql* -y
添加网站
/etc/init.d/httpd start
修改网页配置
vim read.php
$memcachehost = ‘192.168.5.16‘;
$conn=mysql_connect("192.168.5.15","root","123456");
vim write.php
$memcachehost = ‘192.168.5.16‘;
$conn=mysql_connect("192.168.5.15","root","123456");
安装memcache客户端
tar xf memcache-2.2.7.tgz -C /usr/src/
cd memcache-2.2.7/
ls(没有configure的解决方法)
phpize(-bash:phpize: command not found 的解决方法:yum install php-devel)
./configure --enable-memcache--with-php-config=/usr/bin/php-config
make && make install
vim /etc/php.ini(查找PHP调用模块的存放目录)
extension_dir = "/usr/lib/php/modules
ls /usr/lib/php/modules(查看PHP可以调用哪些模块)
dbase.so memcache.so phpcups.so
vim /etc/php.ini
extension_dir ="/usr/lib/php/modules"(该行下加入)
extension=memcache.so(让PHP调用memcache模块)
/etc/init.d/httpd reload
php –m(查看PHP调用哪些模块,等价于访问<?phpphpinfo()?>这个页面)
必须有memcache 和mysql模块
安装MySQL
yum install mysql* -y
/etc/init.d/mysqld start
建数据库
# mysql
mysql> create database db1;
mysql> use db1;
mysql> create table T1(IDint)engine=innodb;
mysql> grant all on *.* to‘root‘@‘192.168.5.14‘ identified by ‘123456‘;
mysql> flush privileges;
mysql> exit
生成数据
seq 1 19999999 >/tmp/big
# mysql
mysql> use db1;
mysql> load data infile ‘/tmp/big‘into table T1;
mysql> exit
远程测试
mysql -h 192.168.5.15 -u root -p123456
安memcached服务端
tar xf libevent-2.0.22-stable.tar.gz -C/usr/src/
cd libevent-2.0.22-stable/
./configure --prefix=/usr/local/libevent && make&& make install
tar xf memcached-1.4.22.tar.gz -C/usr/src/
./configure--prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
开启memcached
/usr/local/memcached//bin/memcached -uroot -p 11211 -l 192.168.5.16 -P /var/run/memcached.pid -m 128m -c 2048 –d
-u 运行memcache服务的用户
-P 端口号
-l 监听地址
-p(大) 指定pid放到哪个文件中
-m 从内存上划分多少容量来缓存数据
-c 并发是多少
-d 以后台执行
本文出自 “运维之道” 博客,请务必保留此出处http://lrtao2010.blog.51cto.com/10425744/1702252
标签:mysql
原文地址:http://lrtao2010.blog.51cto.com/10425744/1702252