小型LAMP架构搭建

LAMP架构实现


构建上图所示lamp架构

主机类型 主机名 系统 IP
Client Clinet Fedora30 192.168.73.153
DNS DNS CentOS7.6 192.168.73.101
HTTPD+PHP HTTPD CentOS7.6 192.168.73.110
HTTPD+PHP HTTPD2 CentOS7.6 192.168.73.111
NFS nfs CentOS7.6 192.168.73.120
MySQL Master CentOS7.6 192.168.73.130
MySQL Slave1 CentOS7.6 192.168.73.131
MySQL Slave2 CentOS7.6 192.168.73.132

一、搭建MySQL主从

在所有MySQL服务器安装MySQL服务

yum install mariadb-server -y

Master节点操作

1.配置主节点服务器

[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=1
log-bin=/data/bin/mysql-bin
binlog-format=row

2.创建二进制日志目录

[mysqld]
server-id=1
log-bin=/data/bin/mysql-bin
binlog-format=row

3.启动MySQL服务

[[email protected] ~]# systemctl start mariadb

4.创建一个用来主从复制的账号

[[email protected] ~]# mysql -e "GRANT REPLICATION SLAVE ON *.* TO ‘repluser‘@‘192.168.73.%‘ IDENTIFIED BY ‘111111‘;"

5.查看二进制日志,记录日志大小

[[email protected] ~]# mysql -e "SHOW MASTER LOGS;"
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |     26753 |
| mysql-bin.000002 |    921736 |
| mysql-bin.000003 |       402 |
+------------------+-----------+

Slave1节点操作

1.修改配置文件

[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=2
read-only

2.启动服务

[[email protected] ~]# systemctl start mariadb

3.CHANGE MASTER TO

[[email protected] ~]# mysql
MariaDB [(none)]> CHANGE MASTER TO   MASTER_HOST=‘192.168.73.130‘,   MASTER_USER=‘repluser‘,   MASTER_PASSWORD=‘111111‘,   MASTER_PORT=3306,   MASTER_LOG_FILE=‘mysql-bin.000003‘,   MASTER_LOG_POS=402;
Query OK, 0 rows affected (0.01 sec)

4.查看slave状态

MariaDB [(none)]> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 192.168.73.130
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 402
               Relay_Log_File: mariadb-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: No
            Slave_SQL_Running: No
              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: 402
              Relay_Log_Space: 245
              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: NULL
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: 0
1 row in set (0.00 sec)

ERROR: No query specified

5.启动复制线程

MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.00 sec)

6.查看slave状态

MariaDB [(none)]> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.73.130
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 402
               Relay_Log_File: mariadb-relay-bin.000002
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql-bin.000003
             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: 402
              Relay_Log_Space: 825
              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: 1
1 row in set (0.00 sec)

ERROR: No query specified

7.测试
主节点导入测试表

[[email protected] ~]# mysql < hellodb_innodb.sql 

8.slave1节点查看

[[email protected] ~]# mysql -e "SHOW DATABASES;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+

Slave1节点搭建完毕

Slave2节点操作

1.修改配置文件

[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=3
read-only

2.启动MySQL服务

[[email protected] ~]# systemctl restart mariadb 

3.CHANGE MASTER TO

[[email protected] ~]# mysql
MariaDB [(none)]> CHANGE MASTER TO   MASTER_HOST=‘192.168.73.130‘,   MASTER_USER=‘repluser‘,   MASTER_PASSWORD=‘111111‘,   MASTER_PORT=3306,   MASTER_LOG_FILE=‘mysql-bin.000003‘,   MASTER_LOG_POS=402;
Query OK, 0 rows affected (0.01 sec)

4.查看slave状态

MariaDB [(none)]> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 192.168.73.130
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 402
               Relay_Log_File: mariadb-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: No
            Slave_SQL_Running: No
              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: 402
              Relay_Log_Space: 245
              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: NULL
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: 0
1 row in set (0.00 sec)

ERROR: No query specified

5.启动复制线程

MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.00 sec)

6.查看数据库是否同步

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

数据库主从搭建完毕

二、搭建HTTPD+PHP

分别在两台httpd主机上安装httpd和php-fpm

yum install httpd php-fpm php-mysql -y

配置httpd服务器

1.查看fcgi相关模块是否启用

[[email protected] ~]# httpd -M | grep proxy
 proxy_module (shared)                      #已经启用
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_connect_module (shared)
 proxy_express_module (shared)
 proxy_fcgi_module (shared)                 #已经启用
 proxy_fdpass_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_scgi_module (shared)
 proxy_wstunnel_module (shared)

2.修改httpd配置文件

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
    DirectoryIndex index.php index.html

addtype application/x-httpd-php .php
addtype applictaion/x-httpd-php-source .phps
proxyrequests off
proxyPassMatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost/data/test/$1

<Virtualhost *:80>
servername blog.mylinuxops.com
Documentroot /data/test
<directory /data/test>
require all granted
</directory>
</Virtualhost>

3.修改php-fpm配置文件

[[email protected] ~]# vim /etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /var/run/php.sock
listen.mode = 0666
;listen.allowed_clients = 127.0.0.1

4.修改php.ini中时区

[[email protected] ~]# vim /etc/php.ini
date.timezone = Asia/Shanghai

5.启动httpd、php-fpm

[[email protected] ~]# systemctl start httpd php-fpm

6.创建测试页

[[email protected] ~]# mkdir /data/test
[[email protected] ~]# vim /data/test/index.php
<?php
$dsn=‘mysql:host=192.168.73.130;dbname=test‘;
$username=‘repluser‘; $passwd=‘111111‘;
$dbh=new PDO($dsn,$username,$passwd);
var_dump($dbh);
phpinfo();
?>

7.测试

配置httpd2服务器

1.从httpd服务器将httpd配置文件及php-fpm配置文件复制至httpd2

[[email protected] ~]# scp /etc/httpd/conf/httpd.conf  192.168.73.111:/etc/httpd/conf/httpd.conf
[[email protected] ~]# scp /etc/php-fpm.d/www.conf 192.168.73.111:/etc/php-fpm.d/www.conf 

2.启动服务

[[email protected] ~]# systemctl start httpd php-fpm 

3.创建测试页

[[email protected] ~]# mkdir /data/test
[[email protected] ~]# vim /data/test/index.php
<?php
$dsn=‘mysql:host=192.168.73.130;dbname=test‘;
$username=‘repluser‘; $passwd=‘111111‘;
$dbh=new PDO($dsn,$username,$passwd);
var_dump($dbh);
phpinfo();
?>

4.测试

配置dns服务器

1.安装bind服务

[[email protected] ~]# yum install bind -y

2.修改主配置文件

[[email protected] ~]# vim /etc/named.conf
//      listen-on port 53 { 127.0.0.1; };
//      listen-on-v6 port 53 { ::1; };

//      allow-query     { localhost; };

3.添加区域记录

[[email protected] ~]# vim /etc/named.rfc1912.zones
zone "mylinuxops.com" IN {
        type master;
        file "mylinuxops.com.zone";
};

4.创建区域数据库文件

[[email protected] etc]# cp -p /var/named/named.localhost /var/named/mylinuxops.com.zone
[[email protected] etc]# vim /var/named/mylinuxops.com.zone
$TTL 1D
@       IN SOA  master admin.mylinuxops.com (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      master
master  A       192.168.73.101
www     A       192.168.73.110
www     A       192.168.73.111

5.检查语法错误

[[email protected] etc]# named-checkconf
[[email protected] etc]# named-checkzone mylinuxops.com /var/named/mylinuxops.com.zone
zone mylinuxops.com/IN: loaded serial 0
OK

6.启动服务

[[email protected] etc]# systemctl start named

7.测试

[[email protected] etc]# dig www.mylinuxops.com @192.168.73.101

; <<>> DiG 9.9.4-RedHat-9.9.4-72.el7 <<>> www.mylinuxops.com @192.168.73.101
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10093
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.mylinuxops.com.        IN  A

;; ANSWER SECTION:
www.mylinuxops.com. 86400   IN  A   192.168.73.111
www.mylinuxops.com. 86400   IN  A   192.168.73.110

;; AUTHORITY SECTION:
mylinuxops.com.     86400   IN  NS  master.mylinuxops.com.

;; ADDITIONAL SECTION:
master.mylinuxops.com.  86400   IN  A   192.168.73.101

;; Query time: 0 msec
;; SERVER: 192.168.73.101#53(192.168.73.101)
;; WHEN: Fri May 17 06:00:35 CST 2019
;; MSG SIZE  rcvd: 116

配置NFS服务

1.创建出需要共享的目录,修改权限

[[email protected] ~]# mkdir /data/test/
[[email protected] ~]# setfacl -R -m u:nfsnobody:rwx /data/test

2.修改配置文件

[[email protected] ~]# vim /etc/exports
/data/test *(rw)

3.在httpd挂载nfs

[[email protected] ~]# showmount -e 192.168.73.120
Export list for 192.168.73.120:
/data/test *
[[email protected] ~]# mount 192.168.73.120:/data/test /data/test

4.在httpd2上挂载nfs

[[email protected] ~]# showmount -e 192.168.73.120
Export list for 192.168.73.120:
/data/test *
[[email protected] ~]# mount 192.168.73.120:/data/test /data/test

5.在/data/test中创建测试页

<?php
$dsn=‘mysql:host=192.168.73.130;dbname=test‘;
$username=‘repluser‘; $passwd=‘111111‘;
$dbh=new PDO($dsn,$username,$passwd);
var_dump($dbh);
phpinfo();
?>

客户端测试

1.测试DNS

[[email protected] ~]# dig www.mylinuxops.com

; <<>> DiG 9.11.5-P4-RedHat-9.11.5-13.P4.fc30 <<>> www.mylinuxops.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37179
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.mylinuxops.com.        IN  A

;; ANSWER SECTION:
www.mylinuxops.com. 86400   IN  A   192.168.73.111
www.mylinuxops.com. 86400   IN  A   192.168.73.110

;; AUTHORITY SECTION:
mylinuxops.com.     86400   IN  NS  master.mylinuxops.com.

;; ADDITIONAL SECTION:
master.mylinuxops.com.  86400   IN  A   192.168.73.101

;; Query time: 0 msec
;; SERVER: 192.168.73.101#53(192.168.73.101)
;; WHEN: Thu May 16 22:54:46 CST 2019
;; MSG SIZE  rcvd: 116

[[email protected] ~]# dig www.mylinuxops.com

; <<>> DiG 9.11.5-P4-RedHat-9.11.5-13.P4.fc30 <<>> www.mylinuxops.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63256
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.mylinuxops.com.        IN  A

;; ANSWER SECTION:
www.mylinuxops.com. 86400   IN  A   192.168.73.110
www.mylinuxops.com. 86400   IN  A   192.168.73.111

;; AUTHORITY SECTION:
mylinuxops.com.     86400   IN  NS  master.mylinuxops.com.

;; ADDITIONAL SECTION:
master.mylinuxops.com.  86400   IN  A   192.168.73.101

;; Query time: 0 msec
;; SERVER: 192.168.73.101#53(192.168.73.101)
;; WHEN: Thu May 16 22:54:47 CST 2019
;; MSG SIZE  rcvd: 116

2.测试站点访问

测试安装wordpress

1.解压wordpress到/data/test

[[email protected] ~]# tar wordpress-5.0.3-zh_CN.tar.gz -C /data/test/

2.创建wordpress所需数据库及账户

[[email protected] ~]# mysql -e "CREATE DATABASE wordpress"
[[email protected] ~]# mysql -e "GRANT ALL ON wordpress.* TO ‘wpuser‘@‘192.168.73.%‘ IDENTIFIED BY ‘111111‘;"

3.修改wordpress配置文件

[[email protected] ~]# cp /data/test/wordpress/wp-config-sample.php /data/test/wordpress/wp-config.php
[[email protected] ~]# vim /data/test/wordpress/wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define(‘DB_NAME‘, ‘wordpress‘);

/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘wpuser‘);

/** MySQL数据库密码 */
define(‘DB_PASSWORD‘, ‘111111‘);

/** MySQL主机 */
define(‘DB_HOST‘, ‘192.168.73.130‘);

4.在客户端测试访问

原文地址:https://blog.51cto.com/11886307/2396029

时间: 2024-11-02 02:21:38

小型LAMP架构搭建的相关文章

LAMP架构搭建+Discuz论坛搭建【weber出品必属精品】

一.     本机简介: 本机系统: CentOS-6.4-x86_64 主机名:oracle.ywb IP地址:192.168.146.129 二.     在Linux环境下安装Apache步骤 首先将准备好的文件通过PSCP发送至Linux的/Root/test/soft目录下 在windows下按住Ctrl+R,打开运行,输入CMD进入DOS命令行.在dos命令行中使用pscp –scp  命令将要上传的文件上传至Linux中. 上传成功后.我们总共要安装四个文件.第一个我们首先解压:a

Linux之LAMP架构搭建配置

Linux之LAMP架构搭建配置 LAMP简介 LAMP定义指Linux(操作系统).ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台. 对于大流量.大并发量的网站系统架构来说,除了硬件上使用高性能的服务器.负载均衡.CDN 等之外,在软件架构上需要重点关注下面几个环节: 使用高性能的操作系统 (OS) . 高性能的网页服务器 (Web Server) .高性能的数据库(Data

采用lamp架构搭建discuz论坛

lamp简介 LAMP指的Linux(操作系统).ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器. Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件 下面给大家讲解一个lamp结构论坛的案例 1.安装所需软件包 [[email protected] ~]# yum install httpd mysq

4-源码方式基于LAMP架构搭建BBS论坛或者博客

目录 一.项目简介 二.环境准备 三.编译安装MySQL 四.编译安装Apache 五.编译安装PHP 六.后续配置 七.启动相关服务 八.源码编译软件经验总结 九.部署web应用 排错1: 排错2: 排错3: 大功告成! 课程目标 使用源码方式基于LAMP架构搭建BBS论坛或者博客 本文成功搭建2个网站,一个个人博客,一个是web界面管理mysql数据库的应用 请耐心阅读,细心操作,你也会成功! 思考:yum工具搭建lamp环境和源码包搭建的区别 rpm版本 安装方便,升级.卸载都很灵活,很难

Web服务器群集之LAMP平台部署(LAMP架构搭建)

Web服务器群集之LAMP平台部署(LAMP架构搭建) 涉及:Linux/Centos7系统 Apache Mysql PHP 一.前言 ? 上一篇文章主要讲述了有关Web与HTTP协议的基础知识,有了这一基础知识理论的奠定,将对我们此次搭建部署LAMP平台的实验有所帮助. ? LAMP架构是非常成熟的企业网站应用模式之一,其指的是协同工作的一整套系统和相关软件,能够提供动态Web站点服务及其应用开发环境.LAMP是一个缩写词--Linux操作系统.Apache网站服务器.MySQL数据库服务器

利用lamp架构搭建Discuz论坛,并实现对数据库的高可用

lamp架构=LAMP指的Linux(操作系统).Apache(HTTP 服务器),MySQL(数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器. #############源码安装php########### tar jxf php-5.6.20.tar.bz2 cd php-5.6.20 解决依赖性: yum install freetype-devel libmcrypt-2.5.8-9.el6.x86_64.rpm net-snmp-d

LAMP架构搭建以及基于LAMP架构的主流论坛和博客搭建过程详解

了解网站架构的朋友都知道,现在很多网站的架构都是采用LAMP(Linux+Apache+Mysql/Mariadb+Php)的,至于LAMP架构本身我们就不做过于深入的探讨了,今天我给大家分享的是关于如何搭建LAMP构架,以及如何基于lamp架构去搭建目前国内比较流行的两大开源论坛(phpwind.discuz)一大开源博客(wordpress),通过这个过程也就能让大家明白我们经常上的论坛以及博客,包括包括我们访问的各个网站到底是如何工作起来的. 注意:为了方便给大家展示实验效果,我们就直接关

LAMP架构搭建Discuz论坛,纯干货!大家都在看!

实验目录: 一.LAMP架构概念 二.LAMP结构的安装与配置 2-1 手工编译安装http服务 2-2 手工编译安装mysql数据库 2-3 手工编译安装PHP工具 三.安装Discuz论坛(开源论坛) 四.小福利 一.LAMP架构概念 LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写: Linux,操作系统 Apache,网页服务器 MariaDB或MySQL,数据库管理系统(或者数据库服务器) PHP.Perl或Python,脚本语言 是目前最为成熟的一-种企业

rsyslog+loganalyzer+mysql+apache+php的lamp架构搭建日志服务器

当服务器遇到问题时,运维工程师都会根据日志分析问题,当黑客入侵服务器时,基本都会删除日志,以免留下蛛丝马迹,由此可见日志对服务器来说多么重要,为此很多公司都会有自己的日志服务器,下面我们来一起学习如何搭建日志服务器和日志分析工具. 1.首先必须得客户机与服务器都安装rsyslog这个软件: [[email protected] ~]# yum -y install rsyslog 2.客户机修改配置文件(1.4为日志服务器) [[email protected] ~]# grep -v "^$&