1001、单机安装基于LNMP结构的WordPress网站、web与数据库服务分离

news/2024/5/19 2:06:34/文章来源:https://blog.csdn.net/weixin_56619848/article/details/124742630

project 第1部分

文章目录

  • project 第1部分
    • project1 整体架构
    • 一、单机安装基于LNMP(Linux Nginx Mysql PHP)结构的WordPress网站
      • 1、 基本环境准备
      • 2、配置nginx
      • 3、配置数据库服务器
      • 4、部署wordpress
    • 二、web与数据库服务分离
      • 准备数据库服务器
      • 自由扩展:

project1 整体架构

在这里插入图片描述1、

一、单机安装基于LNMP(Linux Nginx Mysql PHP)结构的WordPress网站

1、 基本环境准备

  • 创建虚拟机,并配置防火墙、SELINUX、主机名、IP地址、yum
[root@zzgrhel8 ~]# clone-vm7    # 克隆一台7版本的虚拟机
Enter VM number: 1
VM tedu_node01 ... ...
[root@zzgrhel8 ~]# virsh start tedu_node01     # 启动虚拟机
[root@zzgrhel8 ~]# virsh console tedu_node01   # 访问虚拟机的控制台
localhost login: root
Password: 123456# 执行以下命令初始化
hostnamectl set-hostname web1
nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.168.2.11/24
nmcli connection down eth1
nmcli connection up eth1
echo a | passwd --stdin root# 退出控制台,以ssh方式登陆
[root@localhost ~]# logout
CentOS Linux 7 (Core)
Kernel 3.10.0-862.el7.x86_64 on an x86_64
web1 login:    # 按ctrl+]退回到真机# 以ssh方式登陆
[root@zzgrhel8 ~]# ssh 192.168.2.11
[root@web1 ~]# cat /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever - Base
baseurl=ftp://192.168.2.254/centos-1804
enabled=1
gpgcheck=0

2、配置nginx

  • nginx安装及基本配置
[root@web1 ~]# yum -y install gcc openssl-devel pcre-devel
[root@zzgrhel8 ~]# scp /linux-soft/2/lnmp_soft.tar.gz 192.168.2.11:/root
[root@web1 ~]# tar xf lnmp_soft.tar.gz 
[root@web1 ~]# cd lnmp_soft/
[root@web1 lnmp_soft]# tar xf nginx-1.12.2.tar.gz 
[root@web1 lnmp_soft]# cd nginx-1.12.2/
[root@web1 nginx-1.12.2]# ./configure --with-http_ssl_module --with-http_stub_status_module
[root@web1 nginx-1.12.2]# make && make install
  • 安装数据库,并配置php支持连接数据库
[root@web1 ~]# yum install -y mariadb-server mariadb-devel php php-fpm php-mysql
  • 配置服务
# mariadb数据库服务
[root@web1 ~]# systemctl enable mariadb.service --now
[root@web1 ~]# ss -tlnp | grep :3306
LISTEN     0      50           *:3306
# php-fpm服务,处理php动态程序
[root@web1 ~]# systemctl enable php-fpm.service --now
[root@web1 ~]# ss -tlnp | grep :9000
LISTEN     0      128    127.0.0.1:9000# 配置nginx
[root@web1 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT ${MAINPID}[Install]
WantedBy=multi-user.target
[root@web1 ~]# systemctl enable nginx --now
[root@web1 ~]# ss -tlnp | grep :80
LISTEN     0      128          *:80
  • 修改nginx配置文件,实现动静分离
[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
... ...43         location / {44             root   html;45             index  index.php index.html index.htm;46         }... ...65         location ~ \.php$ {66             root           html;67             fastcgi_pass   127.0.0.1:9000;68             fastcgi_index  index.php;69         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_scri    pt_name;70             include        fastcgi.conf;71         }
[root@web1 ~]# systemctl restart nginx  # 重启服务# 测试对php的支持
[root@web1 ~]# vim /usr/local/nginx/html/index.php
<?phpphpinfo();
?>
# 相关日志位置:/usr/local/nginx/logs和/var/log/php-fpm/目录
# 浏览器访问http://192.168.2.11/查看结果
# 如果可以看到php信息的网页,则正确。如下:

在这里插入图片描述

# 测试完后,删除网页:
[root@web1 ~]# rm -f /usr/local/nginx/html/index.php

3、配置数据库服务器

  • 创建程序所需的数据库
  • 授权用户可以访问数据库
[root@web1 ~]# mysql
# 创建名为wordpress的数据库,字符编码采用utf8mb4
MariaDB [(none)]> create database wordpress character set utf8mb4;
# 创建名为wordpress的用户,可以对wordpress拥有全部权限,他的登录密码也是wordpress。该用户既可以在本机登录,也可以在其他客户端地址登录。
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'wordpress';
MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.2.11' identified by 'wordpress';
MariaDB [(none)]> grant all on wordpress.* to wordpress@'%' identified by 'wordpress';
MariaDB [(none)]> flush privileges;   # 刷新权限# 测试账号连接数据库
# -u指定数据库账户名称,-p指定数据库账户的密码,-h指定需要远程数据库的IP地址
[root@web1 ~]# mysql -uwordpress -pwordpress -h192.168.2.11 wordpress

4、部署wordpress

  • 复制程序文件到nginx工作目录
# 解压
[root@web1 ~]# cd lnmp_soft/
[root@web1 lnmp_soft]# yum install -y unzip
[root@web1 lnmp_soft]# unzip wordpress.zip 
[root@web1 lnmp_soft]# cd wordpress/
[root@web1 wordpress]# tar xf wordpress-5.0.3-zh_CN.tar.gz 
[root@web1 wordpress]# cd wordpress/
[root@web1 wordpress]# cp -r * /usr/local/nginx/html/
# php程序是由php-fpm处理的,php-fpm以apache身份运行
[root@web1 wordpress]# ps aux | grep php-fpm
# 为了让php-fpm程序能对html目录进行读写操作,需要为他授予权限
[root@web1 wordpress]# chown -R apache:apache /usr/local/nginx/html
  • 访问http://192.168.2.11/readme.html可以查阅wordpress使用说明
  • 访问http://192.168.2.11/进行初始化,它将自动跳转到http://192.168.2.11/wp-admin/setup-config.php
    在这里插入图片描述点击该页面最下方的“现在就开始”
    在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述注意:以上页面为后台管理页面。前台用户可以查看到的页面如下:
    在这里插入图片描述

二、web与数据库服务分离

准备数据库服务器

  • 初始化:配置防火墙、SELINUX、YUM、主机名、IP地址
[root@zzgrhel8 ~]# clone-vm7
Enter VM number: 2
VM tedu_node02 Create
[root@zzgrhel8 ~]# virsh start tedu_node02 
[root@zzgrhel8 ~]# virsh console tedu_node02
CentOS Linux 7 (Core)
Kernel 3.10.0-862.el7.x86_64 on an x86_64
localhost login: root
Password: 123456# 执行以下命令初始化
hostnamectl set-hostname database
nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.168.2.21/24
nmcli connection down eth1
nmcli connection up eth1
echo a | passwd --stdin root# 使用ssh远程连接
[root@localhost ~]# logout
CentOS Linux 7 (Core)
Kernel 3.10.0-862.el7.x86_64 on an x86_64
database login:   # 按ctrl+]
[root@zzgrhel8 ~]# ssh 192.168.2.21
[root@database ~]# vim /etc/yum.repos.d/local.repo 
[local_repo]
name=CentOS-$releasever - Base
baseurl=ftp://192.168.2.254/centos-1804
enabled=1
gpgcheck=0# 安装mariadb-server并启动
[root@database ~]# yum install -y mariadb-server mariadb-devel
[root@database ~]# systemctl enable mariadb.service --now 
  • 创建数据库,并授权
[root@database ~]# mysql
MariaDB [(none)]> create database wordpress character set utf8mb4;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'%' identified by 'wordpress';
  • 为了测试数据迁移成功与否,可以再创建新的BLOG。迁移完数据后,BLOG仍在,则数据未丢失。
    在这里插入图片描述在这里插入图片描述点击右上角的“发布”后,回到首页,查看结果:
    在这里插入图片描述- 向用户发布停服更新通知。然后迁移数据库
# 1. 在源服务器上备份数据库中的数据。备份数据库wordpress中的数据到wordpress.sql文件
[root@web1 ~]# mysqldump wordpress > wordpress.sql
# 2. 将备份文件拷贝到新数据库服务器
[root@web1 ~]# scp wordpress.sql 192.168.2.21:/root/
# 3. 在新数据库服务器上,导入数据。将wordpress.sql中的数据导入到wordpress数据库中
[root@database ~]# mysql wordpress < wordpress.sql 
# 4. 修改php网站,将数据库服务器地址,指向新数据库服务器
[root@web1 ~]# vim /usr/local/nginx/html/wp-config.php32 define('DB_HOST', '192.168.2.21');
# 5. 停止web1上的mariadb数据库,wordpress网站仍然可以访问
[root@web1 ~]# systemctl stop mariadb
[root@web1 ~]# systemctl disable mariadb
# 6. 停止database上的mariadb数据库,wordpress将不能访问
[root@database ~]# systemctl stop mariadb
# 7. 测试后,再启动database上的mariadb。
[root@database ~]# systemctl start mariadb

附:查看数据库中的内容

# 1. 登录数据库
[root@database ~]# mysql 
# 2. 查看有哪些数据库
MariaDB [(none)]> show databases;
# 3. 进入名为wordpress的数据库
MariaDB [(none)]> use wordpress;
# 4. 查看数据库中的表
MariaDB [wordpress]> show tables;
# 5. 查看注册的用户信息
MariaDB [wordpress]> select * from wp_users;
MariaDB [wordpress]> select * from wp_users\G
# 6. 查看文章
MariaDB [wordpress]> select * from wp_posts\G

自由扩展:

自己搭建discuz

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_874634.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

阿里云——手把手教你搭建个人网站

言归正传&#xff0c;阿里算是做云服务最早的一批了&#xff0c;当时的其他几家有名气的现在基本都死了&#xff0c;只有阿里这支部队熬过来了&#xff0c;就我了解的几家云商做个简单的介绍&#xff1a; 青云&#xff1a;有情怀有理想&#xff0c;不过短板也很明显&#xff0c…

Servlet+JSP+MySQL社交网站

在网站架构上&#xff0c;采用MVC设计模式&#xff0c;实现将网站的页面显示与业务逻辑分离&#xff0c;使其各司其职&#xff1b;在数据库操作上&#xff0c;利用DAO模式&#xff08;Data Access Object数据存取对象&#xff09;技术&#xff0c;将程序中的类对象映射成为数据…

《大型网站系统与JAVA中间件实践》pdf版电子书网盘附下载链接+仪式感技术书阅读法

附Java/C/C/机器学习/算法与数据结构/前端/安卓/Python/程序员必读书籍书单大全&#xff1a; 书单导航页&#xff08;点击右侧 极客侠栈 即可打开个人博客&#xff09;&#xff1a;极客侠栈 ①【Java】学习之路吐血整理技术书从入门到进阶最全50本&#xff08;珍藏版) ②【算法…

《大型网站技术架构:核心原理与案例分析李智慧》pdf版电子书网盘附下载链接+仪式感技术书阅读法

附Java/C/C/机器学习/算法与数据结构/前端/安卓/Python/程序员必读书籍书单大全&#xff1a; 书单导航页&#xff08;点击右侧 极客侠栈 即可打开个人博客&#xff09;&#xff1a;极客侠栈 ①【Java】学习之路吐血整理技术书从入门到进阶最全50本&#xff08;珍藏版) ②【算法…

SSM(springMVC+spring+mybatis)旅游网站项目源码,课程设计(毕业设计)

最近在翻文件的时候发现大四时的毕业设计&#xff0c;一个旅游网站&#xff0c;虽然代码写得很烂&#xff0c;但还是可以跑起来&#xff0c;想着删了还不如分享一下&#xff0c;毕竟我也觉得做毕设是真的无聊又浪费时间......... 整体功能图(其实是做得很敷衍&#xff0c;大部…

如何使用TFilter网站快速获取FIR滤波器的相关系数

最近需要对数据进行滤波&#xff0c;考虑到赛灵思已经有免费的FIR滤波器的ip核&#xff0c;便准备使用硬件进行滤波。但是不论是怎样使用FIR滤波器&#xff0c;都离不开相关系数的确定。实际设计中&#xff0c;不可能拿笔去一个个数值的计算&#xff0c;因此需要借助工具。 网上…

Linux基础PHP网站搭建

我们以ubuntu20.04为例&#xff0c;接下为了方便操作我们用Xshell连接Ubuntu20.04 输入&#xff1a;apt-get install apache2 &#xff08;安装apache&#xff0c;遇到选择全部选择Y&#xff09; 输入&#xff1a;service apache2 restart &#xff08;重新启动apache2…

自己做了个网站 网址:http://www.sunshinelin.club

网址&#xff1a; http://www.sunshinelin.club 当初做这个网站的目的就是为了能够自己用&#xff0c;想做什么功能就写什么功能。感觉使用自己的东西比较有成就感。 这个是网站的首页 我用的ssmshiro后台框架开发&#xff0c;服务是阿里云的centOS 在开发的时候会遇到各…

PHP网站上传大文件失败

问题&#xff1a; 上传较大的视频文件失败 解决&#xff1a; 1.修改网站本身的上传大小限制 2.修改php.ini文件&#xff0c;修改这两个参数post_max_size,upload_max_filesize&#xff0c;根据自己的需要设置大小&#xff0c;单位为M 3.IIS的设置&#xff0c;在发布网站 …

旧手机建立自己的博客网站之踩坑记||在旧手机上建立自己的服务器(2)||2020年新货

接上一篇 接下来配置LNPM环境。 方案一 根据大佬的博文安装时会出现以下情况网站搜索无果&#xff0c;全是让改软件源的&#xff0c;改完后问题依然&#xff0c;其实分析后可知&#xff0c;无法定位就是源里面没有软件或者源错误&#xff0c;所以 这里不指定版本安装。 这里…

将网站、网页变成灰白色调的哀悼风格界面的CSS代码

下面来分享下使网站变成灰白色调&#xff0c;哀悼风格界面的代码&#xff1a; html { filter: grayscale(100%); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%); filter:progid:DXImageTransform…

Web实现:仿电子仪器网站 含HTML CSS部分 内含效果图

效果图&#xff1a; index.html <!DOCTYPE html> <html> <head><title>公司首页</title><link rel"stylesheet" type"text/css" href"css/index.css"> </head> <body><div id"all&quo…

Web实现:徐州旅游网站 含html和css 内含效果图

实现内容&#xff1a; 在首页中插入了背景音乐&#xff0c;在各页面中介绍了徐州当地景点和附近酒店&#xff0c;可以报名参加旅游团&#xff0c;也可以对服务进行投诉反馈。 效果图1&#xff1a; 效果图2&#xff1a; 效果图3&#xff1a; index.html <!DOCTYPE html&g…

Web实现:完整版垃圾分类网站 html+css 内含效果图

实现&#xff1a;完整版垃圾分类网站 效果图1&#xff1a; 效果图2&#xff1a; 效果图3&#xff1a; index.html: <!DOCTYPE html> <html> <head><title>首页</title><link rel"stylesheet" type"text/css" href&qu…

使用bootstrap中的栅格系统轻松实现网站响应式布局

网站分为主体和底部两大部分&#xff0c;使用bootstrap中的栅格系统实现网站响应式布局&#xff1a; .html文件&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" c…

Python爬虫英语四六级网站查询准考证号

本文仅限于学习交流&#xff01;&#xff01;&#xff01; 一、思路 在四六级查询网站&#xff1a;http://cet-kw.neea.edu.cn/Home/QueryTestTicket 1、先找查询接口&#xff0c;因此咱们先正儿八经的查询一次。 2、F12通过检查&#xff0c;发现了查询接口、验证码图片、查…

如何给网站添加ico图标

<link rel"shortcut icon" href"${base}/static/favicon.ico" type"image/x-icon" />

10个很棒的学习iOS开发的网站

这里罗列了一些不同的网站&#xff0c;教你如何创建用户界面和伟大的应用程序以及App Store的开发。这些教程中的大部分是完全免费的。 1) Apple Learning Objective C 2) Design then Code 3) Mobile Tutsplus 4) Team Tree House 5) Introduction to iOS Development Cod…

鼠标事件mouseover mouseout 和mouseenter mouseleave的区别

mouseover mouseout&#xff1a;在鼠标进入或者离开作用元素或者其子元素时&#xff0c;都会触发 在进入son的时候&#xff0c;因为离开了father&#xff0c;所以会触发一次mouseout&#xff0c;同理&#xff0c;在再次进入father的时候&#xff0c;也因为离开了son&#xff0c…