MySQL 最佳化(memcache)

來源:互聯網
上載者:User

標籤: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 最佳化(memcache)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.