Apache 服務器 ip 172.16.10.80 版本:httpd-2.4.10
php 服務器 ip:172.16.10.81 版本:php-5.4.40
MariaDB 服務器 ip:172.16.10.82 版本:MariaDB-5.43
一、編譯安裝Apache
1、安裝開發組件及依賴的組件 pcre-devel zlib-devl
# yum groupinstall"Development tools" "Server Platform Development" –y #yum install pcre-devel zlib-devel
2、安裝apr,apr-util
試驗使用的是httpd-2.4.10 所以必須安裝 1.4+ 版本的apr,apr-util
編譯安裝apr 1.5
#tar xf apr-1.5.0.tar.bz2 # ./configure --prefix=/usr/local/apr #make &&make install
編譯安裝 apr –util
# tar xf apr-util-1.5.3.tar.bz2 # cd apr-util-1.5.3 # ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr # make && make install
安裝httpd-2.49
#tar # tar xf httpd-2.4.9.tar.bz2 # cd httpd-2.4.9 # ./configure --prefix=/usr/local/apache--sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi--enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-modules=most--enable-mpms-shared=all --with-mpm=event # make && make install #因服務器上有rpm包安裝httpd沒有卸載所以安裝路徑換成/etc/httpd24 mkdir /usr/local/apache/manual make[1]: Leaving directory `/tmp/httpd-2.4.9' #安裝成功 創建HTTPD服務腳本文件
cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24 分別修改以下幾項即可
apachectl=/usr/local/apache/bin/apachectl #修改至httpd安裝目錄 httpd=${HTTPD-/usr/local/apache/bin/httpd} #修改至httpd安裝目錄 prog=httpd pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} #修改至安裝目錄
加執行權限
chmod +x /etc/rc.d/init.d/httpd24
加入啓動列表
# chkconfig --add httpd24 # chkconfig httpd24 on
導出頭文件
ln -sv /usr/local/apache/include/ /usr/include/httpd
安裝完成後修改環境變量:
#vim /etc/profile.d/httpd.sh export PATH=/usr/local/apache/bin:$PATH #加入以下內容 ./etc/profile.d/httpd.sh #加載環境變量
配置完成可以啓動了
#service httpd24 strart
查看端口啓動狀態
ss –tunl
tcp LISTEN 0 128 :::80
httpd服務器安裝成功
二、安裝MariaDB-5.5.43
1、準備使用存儲數據的位置,實驗中使用了新建了邏輯卷掛載至/mysql目錄下
fdisk/dev/sda #創建 8e分區20G cat/proc/partitons #查看內核有無讀取 partx–a /dev/sda #刷新 pvcreate/dev/sd{5,6} #創建PV vgceratemyvg /dev/sd{5,6} #創建VG lvcreate–L 10G –n mydata /dev/myvg #創建LV mke2fs–t ext4 –L mydata /dev/myvg/mydata #格式化並添加標籤
2、添加mysql用戶,並修改數據目錄使用mysql用戶運行
# groupadd -r mysql # useradd -g mysql -r mysql # chown -R mysql:mysql /mysql
3、安裝並初始化mysql-5.5.43
[root@localhost tmp]# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
[root@localhost tmp]# cd /usr/local/
[root@localhost tmp]# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
[root@localhost tmp]# cd /usr/local/
[root@localhost tmp]# # scripts/mysql_install_db --user=mysql --datadir=/mysql
#初始化數據庫,並指定用戶和數據存放位置
4、爲mysql提供主配置文件:
[root@localhost mysql]# mkdir /etc/mysql
[root@localhost mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
修改/etc/mysql/my.cnf
在[mysql]中添加 datadir=/data/mydata thread_concurrency #線程數是CPU的核心數兩倍查看CPU核心: lscpu innodb_file_per_table= on
5、爲mysql提供服務腳本,並添加啓動
cp mysql.server/etc/rc.d/init.d/mysqld chmod +x/etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on
6、 修改環境變量
vim /etc/profile.d/mysql.sh exportPATH=/usr/local/mysql/bin:$PATH . /etc/profile.d/mysql.sh #重讀配置文件
7、輸出mysql的庫文件給系統庫查找路徑:
[root@localhost mysql]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql-x86_64.conf
# ldconfig #而後讓系統重新載入系統庫
8、輸出mysql的頭文件至系統頭文件路徑/usr/include:
# ln -sv /usr/local/mysql/include /usr/include/mysql service mysqld start
三、編譯安裝php
php除了依賴開發工具包外還需要 bzip2-devel,libmcrypt-devel,libxml2-devel,bzip2-devel包 可使用rpm 命令查看有沒有安裝
[root@localhost ~]# rpm -qa bzip2-devel libmcrypt-devel libxml2-devel bzip2-devel libmcrypt-devel-2.5.8-9.el6.x86_64 libxml2-devel-2.7.6-14.el6_5.2.x86_64 bzip2-devel-1.0.5-7.el6_0.x86_64
安裝完依賴關係包後就可以解壓縮編譯安裝PHP-2.4.10了
./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-openssl--with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm--with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d--with-bz2 --with-pdo-mysql=mysqlnd # 這裏使用fpm方式 主要在--enable-fpm 這個參數,另外數據庫是在單獨的服務器上所以所有mysql相關的參數全部指定爲 mysqlnd # make && make intall
導出php配置文件
#cd php-5.4.40 #mkdir /etc/php # cp php.ini-production /etc/php/php.ini
配置服務腳本
#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
給執行權限
#chmod +x /etc/rc.d/init.d/php-fpm
加入chkconfig
#chkconfig –add php-fpm
配置php-fpm 配置文件
#cp /usr/local/php5/etc/
編輯php-fpm的配置文件:
# vim /usr/local/php5/etc/php-fpm.conf
配置fpm的相關選項爲你所需要的值,並啓用pid文件(如下最後一行):
pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 8 pid = /usr/local/php5/var/run/php-fpm.pid #啓用此項 error_log = log/php-fpm.log #錯誤日誌文件目錄 listen = 172.16.10.81:9000 #監聽地址 #保存退出
嘗試啓動服務
#service php-fpm start
使用ss –tunl查看
tcp LISTEN 0 128 172.16.10.81:9000 #php-fpm監聽在9000端口啓動成功
四、httpd,php,mariadb全部配置完成限制最後配置httpd,和php 服務器
在apache 和 php 服務器上建立2個相同的目錄
/web/www/index.php
配置172.16.10.80
vim /etc/httpd24/httpd.conf
關閉中心主機
#DocumentRoot "/usr/local/apache/htdocs"
啓用httpd的相關模塊 在Apache httpd 2.4以後已經專門有一個模塊針對FastCGI的實現,此模塊爲mod_proxy_fcgi.so,它其實是作爲mod_proxy.so模塊的擴充,因此,這兩個模塊都要加載 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #Virtual hosts Include /etc/httpd24/extra/httpd-vhosts.conf #開啓這項 #定位AddType;添加下面兩行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps # vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost*:80> ServerAdmin [email protected] DocumentRoot "/web/www" ServerName www.xuphoto.com ServerAlias xuphoto.com ErrorLog"logs/dummy-host.example.com-error_log" CustomLog"logs/dummy-host.example.com-access_log" combined ProxyRequests Off ProxyPassMatch ^/(.*\.php)$fcgi://172.16.10.81:9000/web/www/$1 <Directory "/web/www"> Options none AllowOverride none Require all granted </Directory> </VirtualHost>
爲了提供服務器訪問速度可以給 172.16.10.81 安裝xcache組件
1、安裝
# tar xfxcache-3.2.0.tar.gz
# cd xcache-3.2.0
#/usr/local/php5/bin/phpize
#./configure --enable-xcache --with-php-config=/usr/local/php5/bin/php-config
# make&& make install
安裝結束時,會出現類似如下行:
Installingshared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、編輯php.ini,整合php和xcache:
首先將xcache提供的樣例配置導入php.ini
# mkdir/etc/php.d
# cp xcache.ini /etc/php.ini
接下來編輯/etc/php.d/xcache.ini,找到zend_extension開頭的行,修改爲如下行:
zend_extension= /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/xcache.s
測試訪問
安裝Discuz
分別傳出一份相同的到 172.16.10.80 和172.16.10.81 /web/www/discuz目錄
執行安裝數據庫指定至 172.16.10.82服務器並在10.82服務器上建立數據庫,並授權至此實驗目的已經基本達到。