一、wordpress简介
WordPress是一套利用PHP语言和MySQL数据库开发的开源免费Blog(博客,网站)程序,用户可以在支持PHP环境和MySQL数据库的服务器上建立Blog站点。它的功能非常强大,插件众多,易于扩充功能。其安装和使用也非常方便。目前WordPress已经成为主流的Blog搭建平台,很多发布平台都是根据WordPress二次开发的,如果你也想拥有自己的Blog,可购买网上的域名及空间,然后搭建LNMP环境,在部署Word-Press程序后就可以轻松成就自己的梦想了。
二、WordPress博客承诺更新搭建准备
1、在web02服务器上,部署了LNMP,暂且在web02服务器搭建。
2、创建数据库wordpress,用于存放blog数据。
mysql>create database wordpress;
mysql>use wordpress;
3、下载WordPress博客程序,并放置到blog域名对应的虚拟机站点目录下
#cd /server/tools
#wget https://www.wordpress.org/latest.zip
#<==www.wordpress.org速度非常慢,可以在网站https://www.wpdaxue.com/wordpress-download下载好后,再上传到服务器,
#tar xf wordpress-5.1.1.zip #<==解压后文件为wordpress
#mv wordpress/* /application/nginx/html/blog/
# rm -f index.html test_mysql.php test_info.php
#<==/application/nginx/html/blog/下原理建的文件删除。
4、Nginx子文件配置
[root@web02/application/nginx/conf/extra]#cat 04_blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.php index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
#nginx -t
#nginx -s reload
5、开始安装博客程序
(1)在Windows系统打开浏览器,输入:http://blog.mifengdiandi.xyz/
Database Name:wordpress 事先创建好了
username:暂时使用root#<==搭建好后可以修改,或先创建数据库用户
password:数据库用户的密码
Database host:数据库安装的服务器
Table prefix:默认即可
(2)进行安装
(3)填写相关信息
后台管理账号:mifeng
登录密码:123456
Search Engine Visibility(隐私):打钩,运行搜索引擎对本站点进行索引。
(4)成功安装提示
(5)博客管理后台登录界面
(6)管理后台登录后界面
三、实现wordpress博客程序URL静态化
1、settings→permalinks设置
选择自定义:/archives/%post_id%.html
2、nginx子配置文件
[root@web02/application/nginx/conf/extra]#cat 04_blog.conf
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
#nginx -t
#nginx -s reload
3、访问刚发布的博客
四、搭建一个mysql专用服务器db01服务器
1、mysql搭建过程
企业级LNMP环境部署实践里安装mysql数据库步骤一样。
2、数据迁移
从web02迁移到db01上。
web02备份:
#mysqldump -uroot -p123456 -A -B|gzip >/tmp/web02_db.sql.gz
#scp /tmp/web02_db.tar.gz 192.168.40.137:/tmp #<==192.168.40.137为db01的IP地址。上传到db01服务器。
[root@web02~]#systemctl stop mysqld #<==停止mysql服务
[root@web02~]#systemctl disable mysqld
db01导入数据:
[root@db01/tmp]#gzip -d web02_db.sql.gz #<==解压
#mysql </tmp/web02_db.sql #<==导入数据。
导入成功。
3、为确保安全,博客访问数据库的用户root改为其他用户
db01操作:
[wordpress]>grant all privileges on wordpress.* to wordpress@'172.16.1.%' identified by '123456';
创建用户:wordpress,密码:123456,172.16.1.%为客户地址段。
搭建的所有服务器第二个网卡的IP地址都为172.16.1.**。
web02操作:
[root@web02/application/nginx/html/blog]#vim wp-config.php
修改用户DB_USER,DB_HOST,172.16.1.51为db01第二个网卡的IP。
DB_HOST可以是域名:db01.mifengdiandi.xyz,
在hosts文件里配置上:172.16.1.51 db01.mifengdiandi.xyz。
4、测试
可以正常访问。