Nginx 是一款小巧且高效的 Linux下 Web 服务器软件。由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发,已在一些俄罗斯大型网站上运行多年,相当稳定。第一公开版本 0.1.0 发布于 2004 年 10 月 4 日。2011 年 6 月 1 日,nginx 1.0.4 发布。
性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。相比 Apache,用 Nginx 作为 Web 服务器:使用资源更少,支持更多并发连接,效率更高。作为负载均衡服务器:Nginx 既可在内部直接支持 Rails 和 PHP,也可支持作为 HTTP 代理服务器对外进行服务。Nginx 用 C 编写而成,不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。作为邮件代理服务器:Nginx 同时也是一款非常优秀的邮件代理服务器(最早开发这个产品的目的之一,是作为邮件代理服务器)。Nginx 的安装非常简单,配置文件也很简洁(还支持 perl 语法)。Nginx 支持平滑加载新配置,还能够在不间断服务的情况下进行软件版本升级。
MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),MySQL数据库系统使用最常用的数据库管理语言--结构化查询语言(SQL)进行数据库管理。
数据库是一种用于存储数据集合的独立应用程序。每种数据库都会有一个或多个独特的 API,用来创建、访问、管理、搜索或复制数据库中保存的数据。除了数据库之外,也可以使用其他一些数据存储方式,比如说利用文件系统来存储文件,或者利用内存中的大型散列表,但这些系统均无法快速便利地提取或写入数据。
因此,现在业界一般采用关系型数据库管理系统(RDBMS)来存储并管理海量数据。之所以称其为关系型数据库,是因为所有数据都存储在不同的表中,表之间的关系是建立在主键或其他键(被称为外键)的基础之上的。
由于 MySQL 是开放源代码的,因此任何人都可以在 General Public License 的许可下下载并根据个性化的需要对其进行修改。MySQL 因为其速度、可靠性和适应性而备受关注。大多数人都认为在不需要事务化处理的情况下,MySQL 是管理内容最好的选择。
PHP(外文名:Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了 C 语言、Java 和 Perl 的特点,利于学习,使用广泛,主要适用于 Web 开发领域。PHP 独特的语法混合了C、Java、Perl 以及 PHP 自创的语法。
它可以比 CGI 或者 Perl 更快速地执行动态网页。用 PHP 做出的动态页面与其他的编程语言相比,PHP 是将程序嵌入到 HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成 HTML 标记的 CGI 要高许多;PHP 还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。
WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把 WordPress当作一个内容管理系统(CMS)来使用。
WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的,用户可以在支持 PHP 和 MySQL数据库的服务器上使用自己的博客。
WordPress有许多第三方开发的免费模板,安装方式简单易用。不过要做一个自己的模板,则需要你有一定的专业知识。比如你至少要懂的标准通用标记语言下的一个应用HTML代码、CSS、PHP等相关知识。
WordPress官方支持中文版,同时有爱好者开发的第三方中文语言包,如wopus中文语言包。WordPress拥有成千上万个各式插件和不计其数的主题模板样式。
丰富的插件和模板是WordPress非常流行的一个特性。WordPress插件数据库中有超过18000个插件,包括SEO、控件等等。个人可以根据它的核心程序提供的规则自己开发模板和插件。这些插件可以快速地把你的博客改变成cms、forums、门户等各种类型的站点。WordPress Theme 风格模板是世界上的程序里最多的,类型复杂,品质可嘉,样式繁多,只需要把不同的模板文件放到空间的 Theme目录下就可以自由的在后台变幻,方便使用,而且不管你安装的的什么语言包,都可以自由的使用这些风格。只需要把插件文件上传到你 FTP 的 plugin 目录下,就可以直接在后台启用管理,甚至功能强大点的插件会有一个自己的管理目录在后台出现,就像程序自带似的方便,这些插件囊括了几乎所有互联网上可以实现的功能。
你好多莉——好玩~--这不是普通的插件,它象征着一代人希望和热情,浓缩成 Louis Armstrong 的四个字:你好,多莉。在启用后,在您站点后台每个页面的右上角都可以看到一句来自《俏红娘》音乐剧的英文原版台词。
wp slug translate——很实用的一个插件,当你设置了按文章名字来自动填写固定链接的时候,它可以自动帮你翻译成英文,实在不能翻译也能自动转化成拼音。如果你写中文博客,这真的很有用,避免了乱码的出现!--set slug by translate title or slug from chinese to english with google translate or pinyin. 通过将title用google translate 翻译成英语或者拼音.
Link Manager——wordpress 3.5.1的链接呢?!没事,装了这个插件,立马就回来了!--Enables the Link Manager that existed in WordPress until version 3.5.
Most Popular Posts——按照评论的多少排列,显示热门文章!--Display a link to the most popular posts on your blog according to the number of comments.
MO Widgets——可以设置侧边栏在不同的页面显示不同的内容!--Useing it can easier to control your Widgets.Adds checkboxes to choose your Widget to show or hide on different pages;and add a Widget with support for including PHP.Thanks for Display widgets and Samsarin PHP Widget.|灵动边栏插件,使用它将使你更容易的控制你的边栏显示,安装激活以后会在小工具页面显示控制各个小工具在博客中任何页面是否显示,以实现不同页面不同侧边栏的效果;同时在小工具页面产生一个支持php语言的文本小工具,让你更容易的添加属于自己的边栏小工具.此插件在Display widgets和Samsarin PHP Widget基础上修改,在此感谢原作者.
WP No Category Base - WPML compatible——把文章分类的URL中的“category”去掉
GoogleXMLSitemaps——帮助你的网站更容易被google等搜索引擎收录!--This plugin will generate a special XML sitemap which will help search engines like baidu
(1)了解数据库服务的安装。
(2)了解主从数据库集群的配置架构。
(3)了解Nginx服务的架构与使用。
(4)了解Nginx服务的编译安装与配置。
(5)了解PHP环境的使用场景。
(6)了解PHP环境的编译安装与配置。
(7)了解分布式部署WordPress的架构。
(8)了解分布式部署WordPress应用的配置与操作。
IP |
主机名 |
节点 |
172.16.51.30 |
mysql1 |
主数据库节点 |
172.16.51.40 |
mysql2 |
从数据库节点 |
172.16.51.50 |
nginx |
Nginx节点 |
172.16.51.60 |
php |
PHP环境节点 |
将172.16.51.30主机名修改为mysql1,将172.16.51.40主机名修改为mysql2,将172.16.51.50主机名修改为nginx,将172.16.51.60主机名修改为pnp。如下所示:
mysql1节点:
[root@localhost ~]# hostnamectl set-hostname mysql1
[root@localhost ~]# logout
[root@mysql1 ~]# hostnamectl
Static hostname: mysql1
Icon name: computer-vm
Chassis: vm
Machine ID: 179f6c8f2e7942ef81b0f5565a6883fa
Boot ID: 69ad020d53e54892b9005f82e182c140
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
mysql2节点:
[root@localhost ~]# hostnamectl set-hostname mysql2
[root@localhost ~]# logout
[root@mysql2 ~]# hostnamectl
Static hostname: mysql2
Icon name: computer-vm
Chassis: vm
Machine ID: 179f6c8f2e7942ef81b0f5565a6883fa
Boot ID: 816b270a1275496caa3254300fc359c4
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
nginx节点:
[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# logout
[root@nginx ~]# hostnamectl
Static hostname: nginx
Icon name: computer-vm
Chassis: vm
Machine ID: 179f6c8f2e7942ef81b0f5565a6883fa
Boot ID: 9ac638fec1c64c94aab96d0acfa4f542
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
php节点:
[root@localhost ~]# hostnamectl set-hostname php
[root@localhost ~]# logout
[root@php ~]# hostnamectl
Static hostname: php
Icon name: computer-vm
Chassis: vm
Machine ID: 179f6c8f2e7942ef81b0f5565a6883fa
Boot ID: e48eac1312ca40beae638f6f43e0c31a
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
# setenforce 0
# getenforce
Permissive
# systemctl stop firewalld
使用本地CD设备,将其挂载到/opt/centos目录下:
# mkdir /opt/centos
# mount /dev/cdrom /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only
配置本地yum源,将/etc/yum.repos.d/下的文件移动到/opt目录下,并创建local.repo文件:
# mv /etc/yum.repos.d/* /opt/
# cat /etc/yum.repos.d/local.repo
[centos7]
name=centos7
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
nginx节点:
上传nginx-1.12.2.tar.gz压缩包、wordpress-4.7.3-zh_CN.zip压缩包。
php节点:
上传libmcrypt-2.5.8.tar.gz压缩包、php-5.6.27.tar.gz压缩包、wordpress-4.7.3-zh_CN.zip压缩包。
在mysql1和mysql2节点配置/etc/hosts文件:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.30 mysql1
192.168.200.40 mysql2
在mysql1和mysql2节点安装数据库服务,开启服务并设置开机自启动:
# yum install -y mariadb mariadb-server
# systemctl start mariadb
# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
在mysql1和mysql2节点初始化数据库,配置数据库root密码为000000:
# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we‘ll need the current
password for the root user. If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #默认按回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y #设置root密码
New password: #输入数据库root密码000000
Re-enter new password: #重复输入密码000000
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y #删除匿名用户
... Success!
Normally, root should only be allowed to connect from ‘localhost‘. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n #禁止远程root登录
... skipping.
By default, MariaDB comes with a database named ‘test‘ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y #删除测试数据库并访问它
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y #立即重新加载特权表
... Success!
Cleaning up...
All done! If you‘ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
修改mysql1节点的数据库配置文件,在配置文件/etc/my.cnf中的[mysqld]增添如下内容:
[root@mysql1 ~]# cat /etc/my.cnf
[mysqld]
log_bin = mysql-bin #记录操作日志
binlog_ignore_db = mysql #不同步mysql系统数据库
server_id = 30 #数据库集群中的每个节点id都要不同,一般使用IP地址的最后段的数字,例如192.168.200.30,server_id就写30
datadir=/var/lib/mysql #数据文件存放的目录
socket=/var/lib/mysql/mysql.sock #为MySQL客户端程序和服务器之间的本地通讯指定一个套接字文件
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
重启数据库服务,并进入数据库授权在任何客户端机器上可以以root用户登录到数据库,然后在主节点上创建一个user用户连接节点mysql2,并赋予从节点同步主节点数据库的权限:
[root@mysql1 ~]# systemctl restart mariadb
[root@mysql1 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> grant all privileges on *.* to root@‘%‘ identified by "000000";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant replication slave on *.* to ‘user‘@‘mysql2‘ identified by ‘000000‘;
Query OK, 0 rows affected (0.00 sec)
修改mysql2节点的数据库配置文件,在配置文件/etc/my.cnf中的[mysqld]增添如下内容:
[root@mysql2 ~]# cat /etc/my.cnf
[mysqld]
log_bin = mysql-bin #记录操作日志
binlog_ignore_db = mysql #不同步mysql系统数据库
server_id = 40 #数据库集群中的每个节点id都要不同,一般使用IP地址的最后段的数字,例如192.168.200.40,server_id就写40
datadir=/var/lib/mysql #数据文件存放的目录
socket=/var/lib/mysql/mysql.sock #为MySQL客户端程序和服务器之间的本地通讯指定一个套接字文件
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
在mysql2节点配置从节点连接主节点的连接信息,master_host为主节点主机名mysql1,master_user为上一步中创建的用户user:
[root@mysql2 ~]# systemctl restart mariadb
[root@mysql2 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> change master to master_host=‘mysql1‘,master_user=‘user‘,master_password=‘000000‘;
Query OK, 0 rows affected (0.01 sec)
开启从节点服务,使用show slave status\G命令,并查看从节点服务状态(如果Slave_IO_Running和Slave_SQL_Running的状态都为YES,则从节点服务开启成功):
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: mysql1
Master_User: user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 529
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 813
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 529
Relay_Log_Space: 1109
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 30
1 row in set (0.00 sec)
在nginx节点编译安装基础环境:
[root@nginx ~]# yum install gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel -y
在nginx节点创建制定用户:
[root@nginx ~]# groupadd -g 1001 nginx
[root@nginx ~]# useradd -u 900 nginx -g nginx -s /sbin/nologin
[root@nginx ~]# tail -1 /etc/passwd
nginx:x:900:1001::/home/nginx:/sbin/nologin
解压nginx-1.12.2.tar.gz压缩包,进入nginx-1.12.2目录并编译安装:
[root@nginx ~]# tar -zxf nginx-1.12.2.tar.gz
[root@nginx ~]# cd nginx-1.12.2/
[root@nginx-1.12.2]#./configure --prefix=/usr/local/nginx --with-http_dav_module \
--with-http_stub_status_module --with-http_addition_module \
--with-http_sub_module --with-http_flv_module --with-http_mp4_module \
--with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx
[root@nginx-1.12.2]# make && make install
编译安装完毕后,创建软连接并启动测试:
[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx nginx-1.12.2]# nginx
在浏览器访问nginx节点:
在php节点编译安装基础环境:
[root@php ~]# yum -y install gcc gcc-c++ libxml2-devel libcurl-devel openssl-devel bzip2-devel
在php节点解压libmcrypt-2.5.8.tar.gz压缩包,进入解压后目录,编译安装该服务:
[root@php ~]# tar -zxvf php-5.6.27.tar.gz
[root@php ~]# cd php-5.6.27/
[root@php php-5.6.27]# ./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm \
--enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir \
--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash \
--with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
[root@php php-5.6.27]# make && make install
创建用户id(nginx的id号要和nginx主机(172.16.51.50)上的保持一致):
[root@php php-5.6.27]# groupadd -g 1001 nginx
[root@php php-5.6.27]# useradd -u 900 nginx -g nginx -s /sbin/nologin
[root@php php-5.6.27]# tail -1 /etc/passwd
nginx:x:900:1001::/home/nginx:/sbin/nologin
复制php环境模板为并改名:
[root@php php-5.6.27]# cp php.ini-production /etc/php.ini
[root@php php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
赋予文件权限:
[root@php php-5.6.27]# chmod +x /etc/init.d/php-fpm
添加PHP服务到启动列表,并设置开机启动:
[root@php php-5.6.27]# chkconfig --add php-fpm
[root@php php-5.6.27]# chkconfig php-fpm on
修改PHP的主配置文件php-fpm.conf:
[root@php php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@php php-5.6.27]# vi /usr/local/php5.6/etc/php-fpm.conf
[root@php ~]# grep -n ‘^‘[a-Z] /usr/local/php5.6/etc/php-fpm.conf
25:pid = run/php-fpm.pid #pid进程文件,默认为none。
149:user = nginx #进程的发起用户和用户组,用户user是必须设置,group不是
150:group = nginx
164:listen = 192.168.200.60:9000 #监听ip和端口
224:pm = dynamic #选择进程池管理器如何控制子进程的数量
235:pm.max_children = 50 #同一时刻能够存货的最大子进程的数量
240:pm.start_servers = 5 #在启动时启动的子进程数量
245:pm.min_spare_servers = 5 #处于空闲"idle"状态的最小子进程,如果空闲进程数量小于这个值,那么相应的子进程会被创建
250:pm.max_spare_servers = 35 #最大空闲子进程数量,空闲子进程数量超过这个值,那么相应的子进程会被杀掉
启动php服务,检查是否启动(9000端口):
[root@localhost php-5.6.27]# service php-fpm start
Starting php-fpm done
[root@php ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.200.60:9000 0.0.0.0:* LISTEN 123948/php-fpm: mas
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1403/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2516/master
tcp6 0 0 :::22 :::* LISTEN 1403/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2516/master
至此php环境配置完毕。
在nginx节点修改配置文件:
[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
……
location / {
root /www; //更改网页目录
index index.php index.html index.htm; //添加index.php
}
……
location ~ \.php$ { //去掉location{}前的注释符
root /www; //更改目录为/www
fastcgi_pass 192.168.200.60:9000; //注意:在这里添加PHP主机IP地址
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
……
添加配置:
[root@nginx ~]# vi /usr/local/nginx/conf/fastcgi_params
fastcgi_param QUERY_STRING $query_string; //请求的参数;如?app=123
fastcgi_param REQUEST_METHOD $request_method; //请求的动作(GET,POST)
fastcgi_param CONTENT_TYPE $content_type; //请求头中的Content-Type字段
fastcgi_param CONTENT_LENGTH $content_length; //请求头中的Content-length字段
fastcgi_param SCRIPT_NAME $fastcgi_script_name; //脚本名称
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //脚本文件请求的路径
fastcgi_param REQUEST_URI $request_uri; //请求的地址不带参数
fastcgi_param DOCUMENT_URI $document_uri; //与document_uri; #与uri相同
fastcgi_param DOCUMENT_ROOT $document_root; //网站的根目录。在server配置中root指令中指定的值
fastcgi_param SERVER_PROTOCOL $server_protocol; //请求使用的协议,通常是HTTP/1.0或HTTP/1.1
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1; // cgi 版本
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; // nginx 版本号,可修改、隐藏
fastcgi_param REMOTE_ADDR $remote_addr; //客户端IP
fastcgi_param REMOTE_PORT $remote_port; //客户端端口
fastcgi_param SERVER_ADDR $server_addr; //服务器IP地址
fastcgi_param SERVER_PORT $server_port; //服务器端口
fastcgi_param SERVER_NAME $server_name; //服务器名,域名在server配置中指定的server_name
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
在nginx和php节点,创建/www目录,并修改用户和用户组:
# mkdir /www
# chown nginx:nginx /www/
在ngixn和php节点解压wordpress-4.7.3-zh_CN.zip压缩包,并将解压后的文件复制到/www目录:
# unzip wordpress-4.7.3-zh_CN.zip
# mv wordpress/* /www/
在nginx节点,修改WordPress应用的配置文件,WordPress应用提供了wp-config-sample.php模版文件,将模板文件复制为wp-config.php并修改:
[root@nginx ~]# cp /www/wp-config-sample.php /www/wp-config.php
[root@nginx ~]# vi /www/wp-config.php
……
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define(‘DB_NAME‘, ‘wordpress‘);
/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘root‘);
/** MySQL数据库密码 */
define(‘DB_PASSWORD‘, ‘000000‘);
/** MySQL主机 */
define(‘DB_HOST‘, ‘192.168.200.30‘);
/** 创建数据表时默认的文字编码 */
define(‘DB_CHARSET‘, ‘utf8‘);
/** 数据库整理类型。如不确定请勿更改 */
define(‘DB_COLLATE‘, ‘‘);
……
将该配置文件scp至php节点的/www目录下:
[root@nginx ~]# scp /www/wp-config.php root@192.168.200.60:/www/
在mysql1节点,登录数据库,使用命令创建WordPress数据库:
[root@mysql1 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.44-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
在nginx节点重启nginx服务:
[root@nginx ~]# nginx -s reload
在浏览器输入172.16.51.50进行访问,填写信息,点击安装WordPress:
进入WordPress后台界面:
点击左上角的“blog”,进入WordPress首页:
至此,分布式部署LNMP+WordPress应用已完成。
原文:https://www.cnblogs.com/y0620/p/13176289.html