Lammp的搭建
拓撲圖
Apache+php的搭建:
httpd-2.4.4.tar.bz2
apr-1.4.6.tar.gz
apr-1.4.6.tar.gz 需要這3個軟件包
[root@wang ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/ 解壓apr軟件包
[root@wang ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/ 解壓aprutil軟件包
[root@wang ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ 解壓httpd軟件包
[root@wang ~]# cd /usr/local/src/apr-1.4.6/ 進入apr目錄
[root@wang apr-1.4.6]# ./configure --prefix=/usr/local/apr 進行編譯
[root@wang apr-1.4.6]# make && make install 安裝
[root@wang apr-1.4.6]# cd ../apr-util-1.5.1/ 切換到apr-util目錄
[root@wang apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/bin/apr-1-config 編譯,指定工具安裝路徑,指定apr的路徑
[root@wang apr-util-1.5.1]# make && make install 進行編譯安裝
[root@wang apr-util-1.5.1]# cd ../httpd-2.4.4/ 配置httpd
./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-ssl \
--enable-rewrite \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr-util/bin/apu-1-config \
--with-pcre \
--with-z \
--enable-mpms-shared=all 進行編譯配置
出現錯誤提示,需要安裝pcre-devel包
[root@wang ~]# yum --disablerepo=\* --enablerepo=c6-media install pcre-devel -y 安裝包
然後再進行編譯配置
出現這個錯誤提示,需要安裝[root@wang ~]# yum --disablerepo=\* --enablerepo=c6-media install openssl-devel -y
再進行編譯配置通過後
[root@wang httpd-2.4.4]# make && make install 配置安裝
完成後
[root@wang httpd-2.4.4]# cd /usr/local/apache/ 進入apache目錄
[root@wang apache]# vim /etc/profile 編輯profile文件
/usr/local/apache/bin 增加新的路徑
[root@wang apache]# . /etc/profile 進行更新
[root@wang apache]# httpd -k start 測試是否能啓動
[root@wang apache]# netstat -tupln |grep 80 查看80端口是否開啓
[root@wang apache]# vim /etc/man.config 編輯man配置文件
加入MANPATH /usr/local/apache/man
[root@wang apache]# man ab 嘗試下是否生效
[root@wang apache]# cd /usr/include/ 進入include目錄
[root@wang include]# ln -s /usr/local/apache/include/ apache 做個鏈接
[root@wang ~]# cd /etc/init.d/ 進入目錄
[root@wang init.d]# touch httpd 創建httpd文件
[root@wang init.d]# chmod a+x httpd 加入可執行權限
[root@wang init.d]# vim httpd 進行編輯
#!/bin/bash
2 prog=/usr/local/apache/bin/httpd
3 lockfile=/var/lock/subsys/httpd
4 # description: the apache service
5 # chkconfig: 2345 88 44
6 start(){
7 if [ -e $lockfile ];then
8 echo "the apache service is started"
9 else
10 echo -n "the apache service is starting ...."
11 sleep 1
12 $prog -k start && echo "ok" && touch $lockfile || echo "failer"
13 fi
14
15 }
16
17 stop(){
18 if [ !e $lockfile ];then
19 echo "the apache service is stopped"
20 else
21 echo "the apache service is stoping..."
22 $prog -k stop && echo "ok" && rm -rf $lockfile || echo "failer"
23 fi
24
25 }
26
27
28 case "$1" in
29 start)
30 start
31 ;;
32 stop)
33 stop
34 ;;
35 restart)
36 stop
37 start
38 ;;
39 *)
40 echo "Usage: start|stop|restart"
41 ;;
42 esac
添加此代碼來實現httpd啓動關閉動態效果
[root@wang init.d]# chkconfig --add httpd 加入httpd服務
[root@wang init.d]# chkconfig --list |grep httpd 查看服務啓動
PHP源碼安裝
[root@wang ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ 解壓軟件包
[root@wang ~]# cd /usr/local/src/php-5.5.8/ 進入目錄
[root@wang php-5.5.8]# ./configure \
./configure \
--prefix=/usr/local/php \
--enable-fpm \
--enable-sockets \
--with-mysql=mysqlnd \ (使用mysqlnd模塊調用另外主機的mysql)
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--enable-xml \
--with-png-dir \
--with-jpeg-dir \
--with-zlib \
--with-freetype-dir \
--with-config-file-path=/etc/php \
--with-config-file-scan-dir=/etc/php5.d 配置編譯
接下來需要make && make isntall 因爲時間比較長,睡眠的時候可能連接斷開所以需要screen來實現安裝
[root@wang ~]# yum --disablerepo=\* --enablerepo=c6-media install screen -y 安裝screen
[root@wang php-5.5.8]# screen 使用screen
又打開了一個窗口 ctrl+a+d可以離開 screen -ls可以查看
恢復的話 screen -r 編號
[root@wang php-5.5.8]# make && make install 然後進行後臺配置安裝
安裝完成後:
[root@wang php-5.5.8]# cd /usr/local/apache/modules/ 進入模塊目錄
[root@wang modules]# ll |grep php
-rwxr-xr-x. 1 root root 23450184 Aug 24 06:41 libphp5.so 查看是否有php模塊
[root@wang modules]# vim /etc/httpd/httpd.conf 進入配置文件
加入此語句 AddType application/x-httpd-php .php
加入 index.php
[root@wang modules]# service httpd restart 重啓httpd
進行測試apache是否能與php進行結合
[root@wang modules]# cd ../htdocs/
[root@wang htdocs]# vim index.php 創建一個網頁文件
寫入此函數
[root@wang htdocs]# mkdir /etc/php /etc/php5.d 創建2個目錄
[root@wang htdocs]# cd /usr/local/src/php-5.5.8/
[root@wang php-5.5.8]# cp php.ini-production /etc/php/php.ini 拷貝文件到php.ini
[root@wang php-5.5.8]# service httpd restart 重啓httpd
然後輸入網頁查看下
成功與php進行了關聯
memcached的搭建
在開一臺虛擬機,將ip地址設爲僅主機模式並將ip地址設置爲192.168.3.101
[root@wang ~]# yum --disablerepo=\* --enablerepo=c6-media install lftp telnet -y 安裝常用的軟件包
下載這memecached軟件包
還有libevent軟件
[root@wang ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/
[root@wang ~]# tar -zxvf memcached-1.4.13.tar.gz -C /usr/local/src/ 拆解包
[root@wang ~]# cd /usr/local/src/libevent-2.0.16-stable/ 進入目錄
[root@wang libevent-2.0.16-stable]# ./configure --prefix=/usr/local/libevent 進行配置(需要安裝開發包)
[root@wang libevent-2.0.16-stable]# make && make install
[root@wang libevent-2.0.16-stable]# cd /usr/local/libevent/ 切換到目錄
[root@wang libevent]# vim /etc/ld.so.conf.d/libevent.conf 編輯配置文件導出庫
/usr/local/libevent/lib
編輯爲此
[root@wang libevent]# ldconfig 刷新緩存
[root@wang libevent]# ldconfig -pv |grep libevent 查看是否成功
[root@wang libevent]# cd /usr/local/src/memcached-1.4.13/ 切換到此目錄
[root@wang memcached-1.4.13]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/ 進行配置
[root@wang memcached-1.4.13]# make && make install 進行安裝
[root@wang memcached-1.4.13]# cd /usr/local/memcached/ 進入目錄
[root@wang memcached]# vim /etc/profile
加入path路徑
[root@wang memcached]# . /etc/profile 刷新緩存
[root@wang memcached]# memcached -h 查看memcached的幫助
[root@wang memcached]# memcached -d -m 64 -p 11211 -u nobody -vv 開啓memcached
[root@wang memcached]# telnet 127.0.0.1 11211 登錄進去進行測試
stats 查看狀態
set foo 0 0 3 設置一個鍵值
bar 存儲值
get foo 取鍵值查看
quit 退出
[root@wang memcached]# service iptables stop 關閉防火牆
[root@wang memcached]# chkconfig iptables off
[root@wang memcached]# setenforce 0
Apache+php主機
下載memcache軟件
[root@wang ~]# tar -zxvf memcache-2.2.5.tgz -C /usr/local/src/ 進行解壓
[root@wang ~]# cd /usr/local/src/memcache-2.2.5/
[root@wang memcache-2.2.5]# /usr/local/php/bin/phpize 執行php擴展
[root@wang memcache-2.2.5]# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config 進行memechache配置
[root@wang memcache-2.2.5]# make && make install 進行安裝
[root@wang memcache-2.2.5]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/ 進入目錄
[root@wang no-debug-non-zts-20121212]# ll
total 1348
-rwxr-xr-x. 1 root root 216204 Sep 13 07:22 memcache.so
-rwxr-xr-x. 1 root root 687720 Sep 12 18:44 opcache.a
-rwxr-xr-x. 1 root root 472259 Sep 12 18:44 opcache.so 可以查看到相應的模塊
[root@wang no-debug-non-zts-20121212]# cp memcache.so /etc/php 將模塊拷貝到/etc/php目錄下
[root@wang no-debug-non-zts-20121212]# vim /etc/php/php.ini 編輯php.ini文件
將模塊進行如上改變
[root@wang no-debug-non-zts-20121212]# service php-fpm restart 重啓php
進入頁面查看是否有memcache模塊
有該模塊
進行測試
[root@wang no-debug-non-zts-20121212]# cd /usr/local/apache/htdocs/ 進入目錄
[root@wang htdocs]# vim index2.php
<?php
error_reporting(E_ALL & ~E_NOTICE);
$mc = new memcache;
$mc->addServer("192.168.3.101", 11211);
$mc->set("foo", "Hello!");
$mc->set("bar", "Memcached...");
$arr = array(
$mc->get("foo"),
$mc->get("bar")
);
var_dump($arr);
?>
編輯此測試頁面
[root@wang memcached]# tenlent 127.0.0.1 11211 telnet進入memachaed
stats 查看狀態
get2次 set 1次
訪問此頁面
出現此更新
set get 變化了