IP-10.0.0.8php
1.安裝nginxhtml
mkdir -p /server/tools cd /server/tools yum install -y pcre pcre-devel openssl openssl-devel gcc gcc+ wget http://nginx.org/download/nginx-1.8.0.tar.gz useradd www -M -s /sbin/nologin tar xf nginx-1.8.0.tar.gz cd nginx-1.8.0/ sed -i "179s/#//" auto/cc/gcc mkdir /application ./configure --prefix=/application/nginx-1.8.0 --user=www \ --group=www --with-http_stub_status_module --with-http_ssl_module make && make install ln -s /application/nginx-1.8.0/ /application/nginx # Centos7採用yum方式安裝nginx rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm yum -y install nginx systemctl start nginx.service
2.安裝phpmysql
yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel\ libpng-devel freetype-devel libcurl-devel gd-devel libxslt-devel \ mhash mcrypt libmcrypt libmcrypt-devel # libiconv-devel沒有這包 cd /server/tools/ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar xf libiconv-1.14.tar.gz cd libiconv-1.14/ ./configure --prefix=/usr/local/libiconv make && make install # PHP的編譯參數 cd /server/tools/ wget http://cn2.php.net/distributions/php-5.6.10.tar.gz tar -zxvf php-5.6.10.tar.gz cd php-5.6.10 ./configure --prefix=/opt/php --with-mysql \ --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \ --with-iconv-dir=/usr/local/libiconv --with-zlib \ --with-libxml-dir --enable-xml --with-curl --enable-fpm \ --enable-mbstring --with-gd --with-openssl --with-mhash \ --enable-sockets --with-xmlrpc --enable-zip --enable-soap \ --with-libdir=/usr/lib64 --with-jpeg-dir=/usr/lib64 \ --with-freetype-dir=/usr/lib64 --with-png-dir=/usr/lib64 \ --with-xsl --with-fpm-user=www --with-fpm-group=www make make install clean
3.解決問題nginx
# 安裝MySQL參考上一篇博文 # 解決缺乏共享庫的問題,兩種方法(先用find查到這個庫的位置): vi /etc/ld.so.conf /opt/mysql-5.6.21/libmysql/ ldconfig # 生效 ln -s /opt/mysql-5.6.21/libmysql/libmysqlclient.so.18 /usr/lib64/ # 若是make的時候報:ext/phar/phar.phar沒有這個文件 cd php-5.6.10 touch ext/phar/phar.phar # 本機沒有安裝mysql時,可使用下面的參數 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd # 配置並啓動php-fpm cp php.ini-production /opt/php/lib/php.ini cd /opt/php/etc/ cp php-fpm.conf.default php-fpm.conf cd /server/tools/php-5.6.10/sapi/fpm/ cp init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm service php-fpm start # 或者/opt/php/sbin/php-fpm cat blog.conf server { listen 80; server_name blog.etiantian.com; location / { root html/blog; index index.php index.html; } location ~.*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } /application/nginx/sbin/nginx -s reload mkdir /application/nginx/html/blog/ echo "<?php phpinfo(); ?>" > /application/nginx/html/blog/test.php # 鏈接數據庫測試 cat /application/nginx/html/blog/conn_mysql.php <?php $con = mysql_connect("localhost","root","root123") or mysql_error(); if ($con){ echo "connect mysql successfully"; } else{ echo mysql_error(); } ?>
4.搭建WordPress博客web
create database wordpress; grant all on wordpress.* to wordpress@'localhost' identified by '123456'; show grants for wordpress@'localhost'\G; # 若是受權授大了,在user表中刪除用戶是不行的,得drop而後從新受權 drop user wordpress@'localhost'; # revoke貌似不太好使 revoke all on *.* from wordpress@localhost; wget https://cn.wordpress.org/wordpress-4.5.1-zh_CN.tar.gz cp -a wordpress/* /application/nginx/html/blog/ # 這個權限是爲了讓先能用,之後還要改 chown -R www.www /application/nginx/html/blog/ # 如今blog目錄下的文件有22個,安裝後會多出一個配置文件 # 訪問blog.etiantian.com,點擊安裝,會生成一個鏈接數據庫的配置文件--wp-config.php # 圖片上傳目錄爲:/application/nginx/html/blog/wp-content/uploads
5.分離數據庫sql
# 導出wordpress數據並修改鏈接數據庫的文件(web01上) vi wp-config.php define('DB_HOST', '172.16.1.51'); mysqldump -uroot -poldboy123456 wordpress -B | gzip > bak.sql.gz # 導入數據(db01上) mysql -uroot -poldboy123456 < /tmp/bak.sql grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456'; # 在其餘服務器上就能以這樣的語句訪問51的數據庫了 mysql -u wordpress -h 172.16.1.51 -p
6.靜態圖片放在nfs上數據庫
# 10.0.0.31是以前的NFS服務器,在10.0.0.31上建立用戶,與10.0.0.8上的www的id相同 useradd -u 891 www vi /etc/exports /data 172.16.1.0/24(rw,sync,all_squash,root_squash,anonuid=891,anongid=891) mkdir /data/nfs-blog chown -R www.www /data/ # 在web01上操做 rpm -qa rpcbind nfs-utils /etc/init.d/rpcbind status cd /application/nginx/html/blog/wp-content/uploads mv 2018 /tmp/ mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/ cp -a /tmp/2018/ . 排錯: touch: cannot touch `aaa': Permission denied # 掛載完以後,沒法建立文件,是由於在/etc/exports中將anonuid寫成了893, # 在改爲891以後,仍是沒法寫入,重啓客戶端rpcbind以後,能夠正常寫入.
7.wordpress實現僞靜態centos
管理站點-設置-固定連接-自定義結構: /archives/%post_id%.html 文章的url就會變成這樣的形式: http://blog.etiantian.com/archives/9.html cat blog.conf server { listen 80; server_name blog.etiantian.com; location / { root html/blog; index index.php index.html; try_files $uri $uri/ /index.php?$args; } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }