实验环境
准备两台虚拟机,能够互通
192.168.1.173 | nginx 服务 |
---|---|
192.168.1.174 | php服务 |
需要用到的文件
wordpress-4.7.3-zh_C.zip 提取码:s8qx
lnmp.zip 提取码:5xwd
第一台
[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# bash
[root@nginx ~]#
第二台
[root@localhost ~]# hostnamectl set-hostname php
[root@localhost ~]# bash
[root@php ~]#
1.2使用网络源安装后面所需要使用到的工具
两台上都要安装
我这使用的是MobaXterm-SSH连接工具
提取码:355t
[root@nginx ~]# yum -y install unzip net-tools
[root@php ~]# yum -y install unzip net-tools
1.3配置本地源
上传wordpress-4.7.3-zh_C.zip 和 lnmp.zip 到两台虚拟机
[root@nginx ~]# ls
anaconda-ks.cfg lnmp.zip wordpress-4.7.3-zh_C.zip
[root@php ~]# ls
anaconda-ks.cfg lnmp.zip wordpress-4.7.3-zh_C.zip
使用unzip命令解压lnmp.zip
可以看到多出一个lnmp文件
[root@nginx ~]# unzip lnmp.zip
[root@nginx ~]# ls
anaconda-ks.cfg lnmp lnmp.zip wordpress-4.7.3-zh_C.zip
[root@php ~]# unzip lnmp.zip
[root@php ~]# ls
anaconda-ks.cfg lnmp lnmp.zip wordpress-4.7.3-zh_C.zip
创建一个bak文件将原有的repo文件移动进去
[root@nginx ~]# mkdir /etc/yum.repos.d/bak
[root@nginx ~]# mv /etc/yum.repos.d/C* /etc/yum.repos.d/bak
[root@php ~]# mkdir /etc/yum.repos.d/bak
[root@php ~]# mv /etc/yum.repos.d/C* /etc/yum.repos.d/bak
在两台虚拟机上分别挂载本地镜像
[root@nginx ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@php ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
创建配置文件如下
local.repo为自己创建的文件
[root@nginx ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///mnt
gpgcheck=0
enabled=1
[lnmp]
name=lnmp
baseurl=file:///root/lnmp
gpgcheck=0
enabled=1
[root@nginx ~]# yum clean all
已加载插件:fastestmirror
正在清理软件源: centos lnmp
Cleaning up list of fastest mirrors
Other repos take up 135 M of disk space (use --verbose for details)
[root@nginx ~]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
centos | 3.6 kB 00:00
lnmp | 2.9 kB 00:00
(1/3): centos/group_gz | 165 kB 00:00
(2/3): lnmp/primary_db | 153 kB 00:00
(3/3): centos/primary_db | 3.2 MB 00:00
源标识 源名称 状态
centos centos 4,067
lnmp lnmp 178
可以看到lnmp有178个包,说明成功了
将配置文件复制到另一台
输入yes 必须全称yes
输入密码即可
[root@nginx ~]# scp /etc/yum.repos.d/local.repo root@192.168.1.174:/etc/yum.repos.d/
The authenticity of host '192.168.1.175 (192.168.1.175)' can't be established.
ECDSA key fingerprint is SHA256:cF3uwwqzrZmRkguWmlw9zjFTDEVtzjDnMhhIpx+f1Ik.
ECDSA key fingerprint is MD5:9f:98:f9:a1:71:8f:28:ce:ad:19:a1:06:e1:bf:6e:5a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.175' (ECDSA) to the list of known hosts.
root@192.168.1.174's password:
local.repo 100% 127 105.0KB/s 00:00
1.4分别关闭防火墙和SElinux
[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# setenforce 0
[root@php ~]# systemctl stop firewalld
[root@php ~]# setenforce 0
2.安装服务
2.1第一台上安装nginx服务
[root@nginx ~]# yum -y install nginx
启动服务
[root@nginx ~]# nginx
在浏览器中通过ip访问,我的ip为192.168.1.174
可以看到Welcome to nginx! 说明实验成功
[root@php ~]# yum -y install php php-fpm php-mysql
3.实现wordpress安装
3.1创建用户ID
在php上创建
[root@php ~]# groupadd -g 1001 nginx
[root@php ~]# useradd -u 900 nginx -g nginx -s /sbin/nologin
3.2修改nginx中的配置文件
[root@nginx ~]# vi /etc/nginx/conf.d/default.conf
#省略了前后代码
#只需找到下列代码并修改
location / {
root /www; #修改网页目录
index index.php index.html index.htm; #添加index.php
}
#去掉下列代码的注释并修改
location ~ \.php$ {
root /www; #修改网页目录
fastcgi_pass 192.168.1.175:9000; #这里的ip为php主机的ip
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
修改fastcgi_params文件在里面添加一行
[root@nginx ~]# vi /etc/nginx/fastcgi_params
#省略前后代码,找到下面的代码,并在指定位置下添加一行
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;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
先重启虚拟机,再重启nginx服务,不然可能会失败。
[root@nginx ~]# systemctl restart nginx
3.3修改php中的文件
[root@php ~]# vi /etc/php-fpm.d/www.conf
#找到下列代码并修改
listen = 192.168.1.175:9000 #这里ip为php节点的ip
listen.allowed_clients = 192.168.1.174 #这里ip为nginx节点的ip
user = nginx
group = nginx
重启php服务
[root@php ~]# systemctl restart php-fpm
3.4创建网页目录
在 nginx 和 php 节点,创建/www 目录,并修改用户和用户组
[root@nginx ~]# mkdir /www
[root@nginx ~]# chown nginx:nginx /www
[root@php ~]# mkdir /www
[root@php ~]# chown nginx:nginx /www
3.4部署wordpress
在nginx和php节点分别解压wordpress并移动到/www下
[root@nginx ~]# unzip wordpress-4.7.3-zh_CN.zip
[root@nginx ~]# mv wordpress/* /www/
[root@php ~]# unzip wordpress-4.7.3-zh_CN.zip
[root@php ~]# mv wordpress/* /www/
在nginx节点安装数据库服务,启动并初始化
注意:重启虚拟机后需要重新挂载镜像,关闭防火墙、SElinux
[root@nginx ~]# yum -y install mariadb mariadb-server
[root@nginx ~]# systemctl restart mariadb
[root@nginx ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@nginx ~]# mysql_secure_installation
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
New password:
Re-enter new password:
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
... 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!
登录数据库,创建wordpress库,并授权
-p后面的为数据库密码
[root@nginx ~]# mysql -uroot -p000000
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "000000";
Query OK, 0 rows affected (0.00 sec)
退出数据库
在nginx节点修改wordpress的配置文件
[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.1.174');
/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');
/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');
将文件拷贝到php节点上
[root@nginx ~]# scp /www/wp-config.php root@192.168.1.175:/www/
在 Nginx 节点重启 Nginx 服务
[root@nginx ~]# nginx -s reload
在浏览器中输入ip即可访问到下图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)