一、Linux
操作系統:CentOS 6.4
1.配置好可用的yum源
2.開發環境支持:
# yum groupinstall -y "Development tools" # yum groupinstall -y "Server Platform Development"
二、Apache
編譯安裝httpd-2.4.9
1.安裝pcre-devel(依賴包)
#yum install pcre-devel -y (關於pcre:http://baike.baidu.com/view/3963592.htm)
2.安裝apr,apr-util
#tar -xf apr-1.5.0.tar.bz2 -C /usr/src/ #cd /usr/src/apr-1.5.0 #./configure --prefix=/usr/local/apr //指定其安裝位置 # make && make install (關於apr: http://zh.wikipedia.org/wiki/Apache%E5%8F%AF%E7%A7%BB%E6%A4%8D%E8%BF%90%E8%A1%8C%E6%97%B6) #tar -xf apr-util-1.5.3.tar.bz2 -C /usr/src/ # cd /usr/src/apr-util-1.5.3 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr # make && make install
3.安裝httpd
#tar -xf httpd-2.4.9.tar.bz2 -C /usr/src # cd /usr/src/httpd-2.4.9 # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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=most --with-mpm=event ================================================================ 釋義: --prefix=/usr/local/apache #→指定其安裝位置 --sysconfdir=/etc/httpd #→指定配置文件安裝位置 --enable-so #→啓用基於DSO的方式動態加載模塊 --enable-ssl #→啓用基於https協議的功能 --enable-cgi #→啓用基於cgi協議的功能 --enable-rewrite #→啓用支持URL重寫的功能 --with-zlib #→指定支持在互聯網上發送數據報文時,通用的壓縮庫的API --with-pcre #→指定支持poll的cgi --with-apr=/usr/local/apr #→指定par的安裝路徑 --with-apr-util=/usr/local/apr-util/ #→指定par-util的安裝路徑 --enable-modules=most #→啓用大多數常用的模塊 --enable-mpms-shared=all #→啓用加載所有的mpm模塊 --with-mpm=event #→指定接下來httpd的工作模式是event ====================================================================== # make && make install
模塊加載的方式:
a).靜態:使用--with-mpm=指定模塊名稱;一旦編譯安裝完成,無法卸載,只能從新編譯安裝。
b).動態:使用--enable-mpms-shared選項即可啓用此特性。當給出的參數爲all時,所有此平臺支持的MPM模塊都會被安裝。可運行時加載,構建 MPM 爲動態模塊允許通過修改LoadModule指令內容來改變MPM,而不用重新編譯安裝。
配置:
a).設置pid文件的路徑:
#vim /etc/httpd/httpd.conf //添加 PidFile "/var/run/httpd.pid"
b).配置httpd服務腳本
#vim /etc/rc.d/init.d/httpd //修改 apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd}
c).權限+啓動
# chmod +x /etc/rc.d/init.d/httpd # chkconfig --add httpd # chkconfig --list httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off # chkconfig httpd on # chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
驗證:
# service httpd start # ps -elFH
三、MySQL
1.安裝
# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local # ln -sv /usr/local/mysql-5.5.33-linux2.6-x86_64 mysql 創建軟連接,易於操作
2.爲數據庫創建邏輯卷
# fdisk /dev/sda //10G #pvcreate /dev/sda3 //創建物理卷 #vgcreate myvg /dev/sda8 //創建卷組 #lvcreate -L 8G -n mydata myvg //創建邏輯卷 #mke2fs -t ext4 /dev/myvg/mydata //格式化邏輯卷 # mkdir /mydata //創建邏輯卷掛載目錄 #mkdri -pv /mydata/data //創建mysql數據存放目錄 # vim /etc/fstab //添加開機自動掛載 /dev/myvg/mydata /mydata ext4 defaults 0 0 # mount -a //掛載
3.新建用戶以安全方式運行進程
#groupadd -r mysql //創建系統組mysql #useradd -r -s /sbin/nologin -g mysql mysql -M -D /mydata/data mysql //創建系統用戶mysql #chown -R mysql:mysql /mydata/data //設置目錄屬主屬組
4.初始化mysql
# cd /usr/local/mysql # scripts/mysql_install_db --datadir=/mydata/data --user=mysql //初始化數據庫 # chown -R root . //設置當前目錄所有文件屬主爲root
5.提供腳本
#cd /usr/local/mysql #cp support-files/mysql.server /etc/rc.d/init.d/mysqld //設置腳本mysqld #chmod +x /etc/rc.d/init.d/mysqld //給腳本執行權限 # chkconfig --add mysqld //添加開機啓動 # chkconfig mysqld on
6.提供配文件
#cd /usr/local/mysql #cp support-files/my-large.cnf /etc/my.cnf #vim /etc/my.cnf thread_concurrency = 2 //修改,併發線程數,bithread_concurrency的值爲CPU個數乘以2 datadir = /mydata/data #添加,mysql數據文件的存放路徑:
7.其他配置
# vim /etc/profile.d/mysqld.sh export PATH=/usr/local/mysql/bin:$PATH # source /etc/profile.d/mysqld.sh #vim /etc/man.config MANPATH /usr/local/mysql/man //添加此行 # ln -sv /usr/local/mysql/include /usr/include/mysql //輸出mysql的頭文件至系統頭文件路徑/usr/include # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf //輸出mysql的庫文件給系統庫 #ldconfig //重載系統庫:
8.啓動服務
# service mysqld start # ss -rnl | grep 3306
9.用戶初始化
#mysql mysql> use mysql mysql> select host,user,password from user; mysql> DELETE FROM user WHERE user = ''; //刪除空用戶 mysql> DELETE FROM user WHERE user = '::1'; //刪除ipv6用戶 mysql> UPDATE user SET password = PASSWORD('Hoolee') WHERE password = ''; //爲root用戶設置密碼 mysql> FLUSH PRIVILEGES;
四、PHP
編譯安裝PHP,將php當作httpd的模塊的方式安裝在httpd上,從而實現php與httpd通信
1.解決開發環境和依賴關係
# yum -y install bzip2-devel # yum -y install libmcrypt-devel # yum -y groupinstall "Desktop Platform Development"
2.安裝php
# tar xf php-5.4.26.tar.bz2 # cd /usr/src/php-5.4.26/ # ./configure--prefix=/usr/local/php --with-openssl --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache2/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts =============================================================== 釋義: --prefix=/usr/local/php //指定其安裝位置 --with-openssl //指定支持openssl功能 --with-mysql=mysqlnd //指定與mysql服務器的鏈接 --with-mysqli=mysqlnd //指定與mysql服務器的鏈接 --with-pdo-mysql=mysqlnd //指定與mysql服務器的鏈接 --enable-mbstring //支持多字節string --with-freetype-dir //指定安裝的字體庫頭文件 --with-jpeg-dir //指定jpeg類型的庫 --with-png-dir //指定支持png類型的庫 --with-zlib //支持互聯網上通用壓縮庫,先壓縮再傳送,減少帶寬 --with-libxml-dir=/usr //指定xml庫文件的路徑 --enable-xml //啓用支持xml功能 --enable-sockets //啓用php支持套接字功能 --with-apxs2=/usr/local/apache2/bin/apxs //基於apxs實現讓php編譯成apache模塊 --with-mcrypt //支持額外的加密庫 --with-config-file-path=/etc //指定php配置文件放置路徑 --with-config-file-scan-dir=/etc/php.d //指定php配置文件的分段文件放置路徑 --with-bz2 //指定支持壓縮庫 --enable-maintainer-zts //當apache使用worker或event這兩個MPM,編譯時使用該選項 ====================================================================== [root@www php-5.4.26]# make && make install
附:
a).若使用PHP5.3以上版本,爲鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包。mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。
--with-mysql=mysqlnd
--with-mysqli=mysqlnd
--with-pdo-mysql=mysql
3.提供配置文件
# cp php.ini-production /etc/php.ini
4.修改httpd配置,支持php
# vim /etc/httpd/httpd.conf //定位AddType,添加 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps //#定位至DirectoryIndex, 補充 #DirectoryIndex index.php index.html
5.測試
//創建授權測試用戶 #mysql -u root -pHoolee mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'172.16.1.2' IDENTIFIED by 'testpass'; mysql> FLUSH PRIVILEGES; mysql>\q; //創建測試頁面 #vim /usr/local/apache/htdocs/vim index.php <?php $link = mysql_connect('172.16.1.2','test','testpass'); if ($link) echo "Connect to Mysql server success!"; else echo "Connect to Mysql server failure!"; mysql_close(); phpinfo(); ?> # service httpd reload
瀏覽器訪問:172.16.1.2成功
五、Xcache
1.安裝xcache
# tar xf xcache-3.0.3.tar.gz # cd xcache-3.0.3 # /usr/local/php/bin/phpize //phpize是用來安裝php擴展模塊的,通過phpize可以建立php的 外掛模塊,若你想在原來編譯好的php中加入memcached或者 ImageMagick等擴展模塊,就需要使用phpize # # ./configure --enable=xcache --with-php-config=/usr/local/php/bin/ php-config # make && make install //顯示xcache模塊路徑:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2.編輯配置文件,整合php + xcache
# vim xcache.ini //添加模塊路徑 extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so # cp xcache.ini /etc/php.d/
3.測試
a).安裝 phpmyadmin
b).使用ab命令做壓力測試