首页 > 代码库 > wordpress博客站点配置及数据库迁移

wordpress博客站点配置及数据库迁移

1.wordpress博客站点部署配置

1.1 检查环境

1.1.1 nginx.conf配置文件

###检查nginx配置文件

[root@web02 conf]# cat nginx.conf

worker_processes 1;

events {

   worker_connections  1024;

}

http {

   log_format  main  ‘$remote_addr - $remote_user [$time_local]"$request" ‘

                      ‘$status $body_bytes_sent"$http_referer" ‘

                      ‘"$http_user_agent""$http_x_forwarded_for"‘;

 

   access_log  logs/access.log  main;

 

   include       mime.types;

   default_type application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

    includeextra/www.conf;

    includeextra/bbs.conf;

    includeextra/blog.conf;

    includeextra/stat.conf;

}

###检查blog配置文件

[root@web02 conf]# pwd

/application/nginx/conf

[root@web02 conf]# cat extra/blog.conf

    server {

       listen       80;

       server_name  blog.etiantian.org;

       location / {

           root   html/blog;

           index  index.html index.htm;

        }

}

[root@web02 conf]# ps -ef|grep nginx

root      1879      1  0 03:17 ?        00:00:00 nginx: master process/application/nginx/sbin/nginx

www       2466   1879  0 08:58 ?        00:00:00 nginx: worker process       

root    126392   2548  0 12:03 pts/0    00:00:00 grep nginx

[root@web02 conf]# netstat -lntup|grep nginx

tcp       0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN     1879/nginx         

[root@web02 conf]# curl blog.etiantian.org

blog 10.0.0.7


1.1.2 修改nginx配置文件,使nginx程序与php程序建立联系

说明:利用nginxlocation区块实现动态请求与静态请求的分别处理

[root@web02 conf]# vim extra/blog.conf

    server {

       listen       80;

       server_name  blog.etiantian.org;

        # 静态请求处理的location

       location / {

           root   html/blog;

           index  index.php index.html index.htm;  <-- 需要注

意编辑修改默认首页文件

        }

        # 动态请求处理的location

        location ~* .*\.(php|php5)?$ {

            root html/blog;

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }

}

 

[root@web02 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.10.2/conf/nginx.confsyntax is ok

nginx: configuration file/application/nginx-1.10.2/conf/nginx.conf test is successful

[root@web02 conf]# /application/nginx/sbin/nginx -s reload

nginx负责接收用户的请求,静态数据(html js css 图片等)请求的话nginx直接处理了,动态页面(php$)就转交给php-fpm处理了,有数据请求呢,php就会和mysql进行交互,如果加了memcached,那么php会首先到memcached去找,mem没有的话再到mysql去找,同时会在mem存一份,以供下次数据请求。


1.2 编辑nginxphp连通性测试文件,并进行测试

echo‘<?php phpinfo(); ?>‘ >/application/nginx/html/blog/test_info.php

[root@web02 blog]# curl -I blog.etiantian.org

HTTP/1.1 200 OK

Server: nginx/1.10.2

Date: Mon, 22 May 2017 04:10:19 GMT

Content-Type: text/html

Content-Length: 14

Last-Modified: Fri, 19 May 2017 01:53:30 GMT

Connection: keep-alive

ETag: "591e501a-e"

Accept-Ranges: bytes


1.2.1 检查网页是否访问成功

[root@web02 blog]#curl  http://blog.etiantian.org/index.html            <-- 静态请求站

点文件信息测试

[root@web02 blog]# curl -I http://blog.etiantian.org/test_info.php  <-- 动态请求站

点文件信息测试

HTTP/1.1 200 OK

Server: nginx/1.10.2

Date: Mon, 22 May 2017 04:10:36 GMT

Content-Type: text/html

Connection: keep-alive

X-Powered-By: PHP/5.5.32

说明:当php服务停止时,9000端口信息消失,即停止PHP错误报502错误,linux系统测试完毕后,建议利用浏览器进行最终测试,测试效果更明显

些。

                           

 

1.3 编辑phpmysql连通性测试文件,并进行测试


1.3.1 创建wordpress数据库

[root@web02 blog]#  mysql-uroot -poldboy123

mysql> createdatabase wordpress;

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

| wordpress          |

+--------------------+

5 rows in set (0.00 sec)


1.3.2 添加数据库用户

mysql> grant all on wordpress.* to ‘wordpress‘@‘localhost‘identified by ‘oldboy123‘;

Query OK, 0 rows affected (0.06 sec)

注:grant  为添加用户;all为授权的权限;wordpress为数据库名 .(点为分隔符)*为数据库中所有表格;黄色底纹的wordpress为用户名

mysql>flushprivileges;

Query OK, 0 rows affected (0.04 sec)     ##添加完后更新数据库。

查看系统中的数据库用户

mysql> select user,host from mysql.user;

+-----------+-----------+

| user      | host      |

+-----------+-----------+

| root      | 127.0.0.1 |

| root      | ::1       |

|           | localhost |

| root      | localhost |

| wordpress | localhost |

|           | web02     |

| root      | web02     |

+-----------+-----------+

7 rows in set (0.00 sec)

drop userwordpress@‘172.16.1.8‘;    <--- 删除用户信息

select user,host frommysql.user;    <--- 查看用户信息

mysql -uwordpress-p123456           <--- 测试创建的用户连接

mysql>


1.3.3 测试添加的用户登录数据库

mysql> exit

Bye

[root@web02 blog]# mysql -uwordpress -poldboy123;

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clearthe current input statement.

 

mysql>

mysql> select user();

+---------------------+

| user()              |

+---------------------+

| wordpress@localhost |

+---------------------+

1 row in set (0.00 sec)

 

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| test              |

| wordpress         |      ##发现进入后

+--------------------+

3 rows in set (0.00 sec)

 

mysql>


1.3.4 查看数据库下面文件属组和属主为mysql

[root@web02 blog]# ll /application/mysql/data/

total 110620

-rw-rw---- 1 mysql mysql       56 May 22 10:22 auto.cnf

-rw-rw---- 1 mysql mysql 12582912 May 22 10:22ibdata1

-rw-rw---- 1 mysql mysql 50331648 May 22 10:22ib_logfile0

-rw-rw---- 1 mysql mysql 50331648 May 22 10:07ib_logfile1

drwx------ 2 mysql mysql     4096May 22 10:07 mysql

drwx------ 2 mysql mysql     4096 May 22 10:07 performance_schema

drwxr-xr-x 2 mysql mysql     4096 May 22 09:57 test

-rw-r----- 1 mysql root      2261 May 22 10:22 web02.err

-rw-rw---- 1 mysql mysql        5 May 22 10:22 web02.pid

drwx------ 2 mysql mysql     4096 May 22 12:16 wordpress

[root@web02 blog]# chown -R mysql.mysql/application/mysql/data/


1.3.5 测试phpmysql的联通性

进入blog下编辑生成一个test_mysql.php文件。

[root@web02 blog]# pwd

 pplication/nginx/html/blog

[root@web02 blog]# vim test_mysql.php

<?php

//$link_id=mysql_connect(‘主机名‘,‘用户‘,‘密码‘);

//mysql -u用户 -p密码 -h主机

$link_id=mysql_connect(‘localhost‘,‘wordpress‘,‘oldboy123‘)or mysql_error();

if($link_id){

            echo "mysql successful by oldboy !\n";

           }else{

             echo mysql_error();

            }

?>

[root@web02 blog]# curlblog.etiantian.org/test_mysql.php

mysql successful by oldboy !


1.4 配置博客软件

下载部署wordpress博客程序(https://cn.wordpress.org/   英文官网:https://www.wordpress.org/

     1,  网站下载:             wget https://cn.wordpress.org/wordpress-4.5.1-zh_CN.tar.gz

 2,网上下载上传到Linux tar xf wordpress-4.5.1-zh_CN.tar.gz

    mvwordpress/* /application/nginx/html/blog/

    chown -Rwww.www /application/nginx/html/blog/

     注意:确认hosts文件进行了解析

     浏览器页面进行wordpress部署      

     vimwp-config.php  可以修改wordpress上的数据库连接参数信息


1.4.1 解压软件

[root@web02 home]# cd /home/oldboy/tools/

[root@web02 tools]# rz -E

rz waiting to receive.

[root@web02 tools]# ls

libiconv-1.14                             nginx-1.10.2.tar.gz

libiconv-1.14.tar.gz                       php-5.5.32

mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz  php-5.5.32.tar.gz

nginx-1.10.2 

 [root@web02tools]# tar xfwordpress-4.7.3-zh_CN.tar.gz

[root@web02 tools]# mv wordpress/* /application/nginx/html/blog/

[root@web02 tools]# ll /application/nginx/html/blog/


1.4.2 更改目录属主属组

[root@web02 tools]# chown -R www.www/application/nginx/html/blog/

[root@web02 tools]# ll/application/nginx/html/blog/

total 200

-rw-r--r--  1www www    14 May 19 09:53 index.html

-rw-r--r--  1www www   418 Sep 25  2013 index.php

-rw-r--r--  1www www 19935 Jan  3 02:51 license.txt

-rw-r--r--  1www www  6956 Mar  7 13:14 readme.html

-rw-r--r--  1www www    20 May 22 12:09 test_info.php

-rw-r--r--  1www www   312 May 22 12:29 test_mysql.php

-rw-r--r--  1www www  5447 Sep 28  2016 wp-activate.php

drwxr-xr-x  9www www  4096 Mar  7 13:14 wp-admin

-rw-r--r--  1www www   364 Dec 19  2015 wp-blog-header.php

-rw-r--r--  1www www  1627 Aug 29  2016 wp-comments-post.php

-rw-r--r--  1www www  2930 Mar  7 13:14 wp-config-sample.php

drwxr-xr-x  5www www  4096 Mar  7 13:14 wp-content

-rw-r--r--  1www www  3286 May 25  2015 wp-cron.php

drwxr-xr-x 18 www www 12288 Mar  7 13:14 wp-includes

-rw-r--r--  1www www  2422 Nov 21 10:46wp-links-opml.php

-rw-r--r--  1www www  3301 Oct 25  2016 wp-load.php

-rw-r--r--  1www www 33939 Nov 21 10:46 wp-login.php

-rw-r--r--  1www www  8048 Jan 11 13:15 wp-mail.php

-rw-r--r--  1www www 16250 Nov 29 13:39 wp-settings.php

-rw-r--r--  1www www 29896 Oct 19  2016 wp-signup.php

-rw-r--r--  1www www  4513 Oct 15  2016 wp-trackback.php

-rw-r--r--  1www www  3065 Sep  1  2016xmlrpc.php


1.4.3 注意域名解析

注意本地的hosts文件和Windowshosts文件要有对应的域名解析

[root@web02 blog]# cat /etc/hosts

127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6

172.16.1.5 lb01

172.16.1.6 lb02

172.16.1.7 web01

172.16.1.8 web02

172.16.1.51 db01 db01.etiantian.org

172.16.1.31 nfs01

172.16.1.41 backup

172.16.1.61 m01

10.0.0.7   www.etiantian.org etiantian.org bbs.etiantian.org blog.etiantian.org

[root@web02 blog]#


1.4.4 测试并开始页面安装

浏览器中访问blog.etiantian.org/index.php

注:如果出现再次进入网站的时候可以使用强制刷新缓存文件(ctrl+F5

 


2.wordpress博客站点数据库迁移


2.1 环境准备


2.1.1 mysql安装软件

nginx上面传软件到新克隆的虚拟机(172.16.1.51DB01)上

[root@web02 ~]# cd /home/oldboy/tools/

[root@web02 ~]#scp -rpmysql-5.6.34-linux-glibc2.5-x86_64.tar.gz 172.16.1.51:/home/oldboy/tools/

 

###1.添加用户 

useradd-s /sbin/nologin  -M mysql

####2.解压 mysql 二进制包

cd/home/oldboy/tools

tarxf mysql-5.6.34-*-x86_64.tar.gz

####3.MySQL 移动到 /application/

mkdir-p /application/

mv/home/oldboy/tools/mysql-5.6.34-*-x86_64 /application/mysql-5.6.34

####4.创建软连接

ln -s/application/mysql-5.6.34/ /application/mysql

####5.MySQL用户管理 /application/mysql

chown-R mysql.mysql /application/mysql/

####6.安装这个软件  初始化数据库

#1.软件安装在哪里

#2.数据存放在哪里

#3.MySQL使用的用户谁?

/application/mysql/scripts/mysql_install_db--basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

 

#####To start mysqld at boot time you have to copy

#####support-files/mysql.server to the right placefor your system

#####mysql启动脚本默认放在support-files/mysql.server 

#####

#####记得给MySQL设置个密码

#####PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !

#####To do so, start the server, then issue the followingcommands:

#####

##### /application/mysql/bin/mysqladmin -u root          password ‘new-password‘

##### /application/mysql/bin/mysqladmin -u root -h web01 password‘new-password‘

####7.复制启动脚本授权

cp/application/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod+x /etc/init.d/mysqld

####8.修改启动脚本和 mysql命令 中的路径

sed-i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe/etc/init.d/mysqld

####9.复制默认的配置文件

\cp/application/mysql/support-files/my-default.cnf /etc/my.cnf

/etc/init.d/mysqldstart

 

###故障

##1./tmp权限

##2.主机名解析 hosts解析#ping 主机名

##3.一步一步执行

 

##

##/application/mysql/bin/mysql

##Welcome to the MySQL monitor.  Commands end with ; or \g.

##Your MySQL connection id is 1

##Server version: 5.5.49 MySQL Community Server(GPL)

##mysql>

####10.PATH路径

echo‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile

source/etc/profile

whichmysql

####11.加入开机自启动

chkconfig--add mysqld

chkconfigmysqld on

####12.MySQL root用户设置密码

/application/mysql/bin/mysqladmin-u root password ‘oldboy123‘

####13.重新登录MySQL数据库

mysql-uroot -poldboy123


2.2 wordpress博客站点数据库迁移


2.2.1 nginx服务器上备份数据库数据库信息

mysqldump-uroot -poldboy123 --all-databases >/tmp/mysqlbak.sql 

ll/tmp/bak.sql -h

[root@web02 tools]# scp -rp /tmp/mysqlbak.sql 172.16.1.51:/tmp


2.2.2 恢复数据库数据库信息

当上面的命令执行成功后,切换到db数据库,将nginx服务器上推送的数据库同步到本地数据库。

2.2.2.1         ##db01数据库上添加用户

        mysql-uroot -poldboy123 </tmp/bak.sql

       ###db01添加新的用户

        grantall on wordpress.* to wordpress@‘10.0.0.0/255.255.255.0‘identified by ‘oldboy123‘;

        flushprivileges;

2.2.2.2         ##数据库上导入数据

[root@DB tmp]# mysql -uroot -poldboy123</tmp/mysqlbak.sql

Warning: Using a password on the command lineinterface can be insecure.

[root@DB tmp]# mysql -uroot -poldboy123

mysql> show databases

    -> ;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql             |

| performance_schema |

| test              |

| wordpress         |

+--------------------+

5 rows in set (0.00 sec)


2.2.3 数据库迁移完毕,修改网站连接数据库的配置文件

 [root@guanli blog]# cd /application/nginx/html/blog

 [root@web02 blog]# vim wp-config.php   <-- 修改wordpress上的数据库连接参数信息

(省略数行)

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //

/** WordPress数据库的名称 */

define(‘DB_NAME‘, ‘wordpress‘);

 

/** MySQL数据库用户名 */

define(‘DB_USER‘, ‘wordpress‘);

 

/** MySQL数据库密码 */

define(‘DB_PASSWORD‘, ‘oldboy123‘);

 

/** MySQL主机 */

define(‘DB_HOST‘, ‘172.16.1.51‘);    <-- 修改连接的主机信息,将localhost修改为172.16.1.51

(省略数行)

[root@web02 blog]# mysql -uwordpress -poldboy123 -h 172.16.1.51       <-- 修改配置文件之前,先测试网站web服务器与迁移后的数据库连通性  


2.2.4 停止nginx上的mysql数据库

[root@web02 application]# /etc/init.d/mysqld stop   说明:web服务器数据库此时可以关闭了

2.2.5 检查确认nginx的配置文件

[root@web02 conf]# cat  nginx.conf

worker_processes 1;

events {

   worker_connections  1024;

}

http {

             log_format  main  ‘$remote_addr - $remote_user [$time_local]"$request" ‘

              ‘$status $body_bytes_sent "$http_referer" ‘

               ‘"$http_user_agent" "$http_x_forwarded_for"‘;

 

   access_log  logs/access.log  main;

 

   include       mime.types;

   default_type application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

    includeextra/www.conf;

    includeextra/bbs.conf;

    includeextra/blog.conf;

#    includeextra/stat.conf;

 

}

[root@web02 conf]#

[root@web02 extra]# cat blog.conf

server {

       listen       80;

       server_name  blog.etiantian.org;

        # 静态请求处理的location

       location / {

           root   html/blog;

           index  index.php index.htmlindex.htm;

        }

        # 动态请求处理的location

       location ~* .*\.(php|php5)?$ {

           root html/blog;

           fastcgi_pass  127.0.0.1:9000;

           fastcgi_index index.php;

           include fastcgi.conf;

        }

}

[root@web02 extra]#

2.2.5.1web服务器上测试数据库的连通性

[root@web01 blog]# mysql -uwordpress -poldboy123 -h172.16.1.51

Warning: Using a password on the command lineinterface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.6.34 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarks of theirrespective

owners.

 

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clearthe current input statement.

 

mysql> exit

Bye

[root@web01 blog]#

2.2.5.2         排错

[root@guanli extra]# curl -I blog.etiantian.org

curl: (7) couldn‘t connect to host

[root@guanli extra]# /application/nginx/sbin/nginx-t

nginx: the configuration file/application/nginx-1.10.2/conf/nginx.conf syntax is ok

nginx: configuration file/application/nginx-1.10.2/conf/nginx.conf test is successful

[root@guanli extra]# /application/nginx/sbin/nginx

[root@guanli extra]# curl -I blog.etiantian.org

HTTP/1.1 502 Bad Gateway

Server: nginx/1.10.2

Date: Tue, 30 May 2017 10:22:44 GMT

Content-Type: text/html

Content-Length: 537

Connection: keep-alive

ETag: "592c2c4a-219"

 

[root@guanli extra]# /application/php/sbin/php-fpm

[root@guanli extra]# curl -I blog.etiantian.org

HTTP/1.1 200 OK

Server: nginx/1.10.2

Date: Tue, 30 May 2017 10:23:30 GMT

Content-Type: text/html; charset=UTF-8

Connection: keep-alive

X-Powered-By: PHP/5.5.32

Link:<http://blog.etiantian.org/?rest_route=/>;rel="https://api.w.org/"

 

[root@guanli extra]#

2.2.6 测试访问网站


2.3 进行数据迁移到NFS共享服务器


2.3.1 先将原有目录中数据移出

cd /application/nginx/html/blog/wp-content/uploads

[root@web02 uploads]# pwd

/application/nginx/html/blog/wp-content/uploads        ###这个目录是blog的上传目录,当上传时,自动生成。

[root@web02 uploads]# mkdir /tmp/nfsbak -p  ##先建立一个目录,将原有的上传目录uploads中的文件移动到这个目录中,防止稍后挂载时,上传目录文件丢失

[root@web02 uploads]# mv ./* /tmp/wordpress_backup/

2.3.2  NFS服务器上配置创建共享目录

vim /etc/exports

 /data172.16.1.0/24(rw,sync,all_squash)

 showmount -e 172.16.1.31

 mount -t nfs172.16.1.31:/data /mnt/                    nginx上挂载nfs共享目录


2.3.3 nginx挂载共享目录

[root@web02 wp-content]# mount -t nfs 172.16.1.31:/data /application/nginx-1.10.2/html/blog/wp-content/uploads

[root@web02 wp-content]# df -h

Filesystem        Size  Used Avail Use% Mounted on

/dev/sda3         6.9G  3.6G  2.9G 56% /

tmpfs             491M     0  491M  0% /dev/shm

/dev/sda1         190M   34M  147M 19% /boot

172.16.1.31:/data 6.9G  1.5G  5.1G 23% /application/nginx-1.10.2/html/blog/wp-content/uploads

[root@web02 wp-content]# cd uploads/

[root@web02 uploads]# touch 1.txt

[root@web02 uploads]# ll

total 0

-rw-r--r-- 1 nfsnobody nfsnobody 0 May 23 11:221.txt


本文出自 “大东” 博客,转载请与作者联系!

wordpress博客站点配置及数据库迁移