前端(nginx+php)ip:192.168.10.8
後端(獨立mysql)ip:192.168.10.5
軟體版本:libiconv-1.14.tar.gz mysql-5.1.63.tar.gz php-5.2.17.tar.gz php-5.2.17-fpm-0.5.14.diff.gz php-5.2.17-max-input-vars.patch
1.先在後端安裝mysql
在192.168.10.5上只安裝mysql.方法可以去看centos編譯安裝nginx+php-fpm+mysql裡的mysql安裝.
2.在前端安裝php-fpm nginx和mysql-client
這裡只說下安裝mysql-client和php的編譯安裝.
| 代碼如下 |
|
tar zxf mysql-5.1.63.tar.gz && cd mysql-5.1.63 ./configure --prefix=/usr/local/mysql --without-server |
這裡只需要加上--without-server就可以讓mysql變成用戶端了.
如果出現/bin/rm: cannot remove `libtoolt': No such file or directory,可以去看這篇文章Mysql安裝:/bin/rm: cannot remove `libtoolt': No such file or directory.
沒有問題後,執行命令:
| 代碼如下 |
|
| make && make install |
編譯php的時候只需要加上--with-mysql=mysql用戶端安裝目錄就可以了.這裡我給出編譯參數:
| 代碼如下 |
|
./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --with-fpm-log=/var/log/php-fpm.log \ --with-fpm-conf=/etc/php-fpm.conf --with-fpm-pid=/var/run/php-fpm.pid --with-config-file-path=/etc \ --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl \ --enable-ftp --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-gettext --with-mhash \ --enable-mbstring --with-mcrypt --enable-soap --enable-zip --with-iconv=/usr/local/libiconv \ --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --without-pear |
nginx的編譯沒有什麼好說的了,我前面centos編譯安裝nginx+php-fpm+mysql這篇文章裡已經有講過了.
3.進行測實驗證
當上面的一切都安裝好之後,在後端的mysql裡給出遠程許可權,如下:
| 代碼如下 |
|
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'; |
然後iptables上只允許192.168.10.8訪問mysql連接埠,其他都拒絕.如:
| 代碼如下 |
|
iptables -A RH-Firewall-1-INPUT -s 192.168.10.8 -p tcp -m tcp --dport 3306 -j ACCEPT iptables -A RH-Firewall-1-INPUT -p tcp --dport 3306 -j DROP services iptables save services iptables restart |
然後在192.168.10.8上進行測試,是否可以遠程連上mysql
mysql -h 192.168.10.5 -u root -p
如果可以連上,就繼續下一步的操作,不能連上的話請檢查上面是否有錯誤的地方.
現在我們加個php頁面來測試php是否可以連上mysql,指令碼如下:
| 代碼如下 |
|
<?php $link=mysql_connect("192.168.10.5","root","123456"); if(!$link) echo "bad!" ; else echo "ok!" ; mysql_close(); ?> |
成功的話是ok!的輸出,失敗的話是bad!的輸出,我這裡是成功的
mysql 5.5.x的只安裝用戶端.
需要的軟體:libiconv-1.14.tar.gz mysql-5.5.25a.tar.gz
1.安裝前的準備
安裝前的準備,可以去看這篇文章centos編譯安裝nginx+php-fpm+mysql
2.安裝libiconv
| 代碼如下 |
|
./configure --prefix=/usr/local/libiconv make && make install |
3.只安裝mysql用戶端
| 代碼如下 |
|
cmake . && make mysqlclient libmysql make install |
這樣就只安裝了mysql用戶端,然後可以輸入whereis mysql來查看mysql安裝位置.
whereis mysql
好了,可以看到跟yum安裝的差不多.
4.安裝php
以前mysql是5.1的時候,只需要加上--with-mysql=mysql用戶端安裝目錄就可以了,但在mysql 5.5.x這個參數就要改變下了,下面是php的編譯參數:
| 代碼如下 |
|
./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --with-fpm-log=/var/log/php-fpm.log --with-fpm-conf=/etc/php-fpm.conf \ --with-fpm-pid=/var/run/php-fpm.pid --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \ --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl --enable-ftp \ --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-gettext --with-mhash \ --enable-mbstring --with-mcrypt --enable-soap --enable-zip --with-iconv=/usr/local/libiconv \ --with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config |
大家可以看最後一行,--with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config這就是跟以前不同的行.好了,剩下的就不寫了