您好,登錄后才能下訂單哦!
memcached是一套分布式的高速緩存系統,運行在內存中。memcached缺乏認證以及安全管制,這代表應該將memcached服務器放置在防火墻后。
實驗準備
實驗步驟
1、安裝環境包
[root@localhost libevent-2.1.8-stable]# yum install gcc gcc-c++ make -y
2、安裝Libevent軟件本體
掛載軟件包,并到掛載目錄下解壓
[root@localhost memcached]# tar zxf libevent-2.1.8-stable.tar.gz -C /opt/
[root@localhost memcached]# cd /opt/libevent-2.1.8-stable/
//配置并編譯安裝
[root@localhost libevent-2.1.8-stable]# ./configure \
--prefix=/usr/local/libevent
[root@localhost libevent-2.1.8-stable]# make && make install
3、配置、安裝Memcached
[root@localhost memcached]# tar zxf memcached-1.5.6.tar.gz -C /opt/
[root@localhost memcached]# cd /opt/memcached-1.5.6/
[root@localhost memcached-1.5.6]# ./configure \
--prefix=/usr/local/memached \
--with-libevent=/usr/local/libevent/
[root@localhost memcached-1.5.6]# make && make install
//建立軟鏈接
[root@localhost memcached-1.5.6]# ln -s /usr/local/memached/bin/* /usr/local/bin/
啟動服務
[root@localhost memcached-1.5.6]# memcached -d -m 32m -p 11211 -u root
//“-d”:以守護進程的方式運行(后臺運行)
//“-m”:指定最大使用內存大小
//“-p”:指定端口
//“-u”:指定用戶
[root@localhost memcached-1.5.6]# netstat -atnp | grep 11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 12591/memcached
tcp6 0 0 :::11211 :::* LISTEN 12591/memcached
#關閉防火墻和安全功能
[root@localhost memcached-1.5.6]# systemctl stop firewalld.service
[root@localhost memcached-1.5.6]# setenforce 0
4、安裝Telent用于連接Memcached
[root@localhost memcached-1.5.6]# yum install telnet -y
//連接memcached
[root@localhost memcached-1.5.6]# telnet 192.168.142.66 11211
Trying 192.168.142.66...
Connected to 192.168.142.66.
Escape character is '^]'.
安裝LAMP架構
詳情見本人博客 LAMP架構之Discuz論壇(實操部分)https://blog.51cto.com/14449528/2447886
論壇搭建部分可不做
1、數據庫中進行提權
[root@localhost ~]# mysql -uroot -p
mysql> create database sky;
mysql> grant all on sky.* to 'skyuser'@'%' identified by '123123';
mysql> flush privileges;
2、測試PHP工具能否連接數據庫
[root@localhost htdocs]# vim /usr/local/httpd/htdocs/index.php
<?php
$link=mysql_connect('192.168.142.132','skyuser','123123');
if($link) echo "<h2>Success!!!</h2>";
else echo "Fail!!";
mysql_close();
?>
3、安裝、配置memcache客戶端
[root@localhost memcached]# tar zxf memcache-2.2.7.tgz -C /opt/
[root@localhost memcached]# cd /opt/memcache-2.2.7/
[root@localhost memcache-2.2.7]# /usr/local/php5/bin/phpize //為memcache生成啟動腳本
[root@localhost memcache-2.2.7]# ./configure \
--enable-memcache \
--with-php-config=/usr/local/php5/bin/php-config
//編譯&安裝
[root@localhost memcache-2.2.7]# make && make install
修改PHP的配置文件
[root@localhost memcache-2.2.7]# vim /usr/local/php5/php.ini
//736行后添加
extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"
extension = memcache.so
4、建立測試頁面
[root@localhost memcache-2.2.7]# vim /usr/local/httpd/htdocs/index.php
<?php
$memcache = new Memcache();
$memcache->connect('192.168.142.136',11211); //memached服務端地址
$memcache->set('key',Memcache test Successfull!!!',0,60);
$result = $memcache->get('key');
unset($memcache);
echo $result;
?>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。