评论

收藏

[Linux] 应用系统分布式构建运维

服务系统 服务系统 发布于:2021-11-16 10:15 | 阅读数:253 | 评论:0

DSC0000.png
图1 应用系统分布式构建运维

一、分布式系统
​1.分布式系统概念
     分布式系统(distributedsystem)是建立在网络之上的软件系统。正是因为软件的特性,所以分布式系统具有高度的内聚性和透明性。
2.分布式系统特征
1)​分布性:分布式系统由多台计算机组成,它们在地域上是分散的,可以散步在一个单位、一个城市、一个国家,甚至全球范围。
2)自治性:各个节点都包含自身的处理机和内存,各自具有独立的处理数据功能。
3)并行性:一个大的任务可以划分为若干子任务、分别在不同的主机上执行。
4)全局性:存在一个单一的、全局的进程通信机制,使得任何一个进程都能与其他通信。
3.分布式系统的优点
​1)资源共享:若干不同的节点通过通信网络彼此互连,一个节点上的用户可以使用其他节点上的资源。
2)加快计算速度:一个特定的任务可以划分为若干并行处理的子任务,则可把这些子任务分散到不同的节点上,使它们同时在这些节点上运行,从而加快计算速度。
3)可靠性高:如果其中某个节点失效,其余的节点可以继续运行,整个系统不会因为一个或几个节点的故障而全体崩溃。
4)通信方便、快捷​:分布式系统中各个节点通过一个通信网络互连在一起。​
4.分布式系统的类别
​1)分布式计算:将一项庞大的任务分割成许多较小任务的技术,当计算任务扩大时,只须添加更多计算节点即可。如大数据处理数据流入,如Apache Hadoop。
2)分布式文件系统:分布式数据存储,即在一组机器中存储和访问大量数据。如上千个节点运行在HDFS下。
3)分布式消息:消息传递系统为整个系统内的消息/事件的存储和传播提供了一个中心位置,允许将应用程序逻辑直接从其他系统中分离出来。
4)分布式数据库系统:通常使用较小的计算机系统,每台计算机可单独存放在一个地方。
5.分布式数据库系统​
     分布式数据库系统通常使用较小的计算机系统,每台计算机可单独存放在一个地方。许多位于不同地点的计算机通过网络互相连接,共同组成一个完整的、全局的逻辑上集中、物理上分布的大型数据库。
1)分布式数据库系统的工作机制
        ​一个分布式数据库在逻辑上是一个统一的整体,在物理上则是分别存储在不同的物理节点上。一个应用程序通过网络的连接,可以访问分布在不同地理位置的数据库中。它的分布性表现在数据库中的数据不是存储在同一场地,更确切地讲,就是不存储在同一计算机的存储设备上。分布式数据库系统部署图如下:


DSC0001.png
图2:分布式数据库系统部署

2)分布式数据库系统的特点

  • ​独立透明性
  • 集中节点结合
  • 复制透明性
  • 易于扩展性
  • 适应用性
  • 可靠性和可用性
  • 充分性
  • 扩展性​
二、主从数据库
1、主从数据库的基本概念
      ​主从数据库把数据库架构分为主数据库和从数据库。从数据库是主数据库的备份,这是提高信息安全的手段。主从数据库服务器不在一个地理位置上,当发生意外时数据库可以保存。
         以MySQL为例,MySQL主从复制是指数据可以从一个MySQL数据库服务器主节点复制到一个或多个从节点。MySQL主从复制涉及到3个线程,一个运行在主节点(log dump thread),其余两个(I/O ​thread、SQL thread)运行在从节点。主从数据库架构图如下:
DSC0002.png
图3: 主从数据库架构图

2.主从数据库的优点
1)方便做数据的热备份
2)架构的扩展更容易
3)读写分离
3.常见的主从形式
1)一主一从
2)一从多主
3)多主一从
4)双主复制
5)级联复制
三、实战案例——部署主从数据库
1、案例目标
1)了解数据库服务的安装
2)了解主从数据库集群的配置架构
2、案例分析
1)CentOS操作系统的单节点规划
表1  节点规划

DSC0003.png
2)基础环境
DSC0004.png
图4  虚拟两台MySQL主机

3、案例实施
#主数据库节点[root@nfs-server ~]# hostnamectl set-hostname mysql1[root@nfs-server ~]# logout[root@mysql1 ~]# [root@mysql1 ~]# setenforce 0[root@mysql1 ~]# systemctl stop firewalld[root@mysql1 ~]#[root@mysql1 ~]# vi /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1     localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.100.15  mysql1192.168.100.16  mysql2#安装数据库服务[root@mysql1 ~]# yum install -y mariadb mariadb-server[root@mysql1 ~]# systemctl start mariadb[root@mysql1 ~]# systemctl enable mariadb#初始化数据库          [root@mysql1 ~]# 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 currentpassword for the root user.  If you've just installed MariaDB, andyou 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):   # 默认按回车键ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)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 MariaDBroot user without the proper authorisation.Set root password? [Y/n] y     #设置数据库root用户登录**New password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y    #是否清除匿名用户? ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures 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 canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y   #是否删除test数据库? - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill 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 MariaDBinstallation should now be secure.Thanks for using MariaDB!#配置mysql1主节点[root@mysql1 ~]# vi /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socksymbolic-links=0#添加下面内容log_bin=mysql-binbinlog_ignore_db=mysqlserver_id=15[root@mysql1 ~]# systemctl restart mariadb[root@mysql1 ~]# mysql -uroot -p000000Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 2Server version: 5.5.68-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> #在mysql1节点中授权在任何客户端机器上可以以root用户登录到数据库;#然后在主节点上创建一个user用户连接节点mysql2,并赋予从节点同步主节点数据库的权限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)MariaDB [(none)]> create database test;  #主节点创建数据库Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> use test;Database changedMariaDB [test]> create table company(id int not null primary key,name varchar(50),addr varchar(255));Query OK, 0 rows affected (0.01 sec)MariaDB [test]> insert into company values(1,"alibaba","china");  Query OK, 1 row affected (0.01 sec)MariaDB [test]> select * from company;+----+---------+-------+| id | name  | addr  |+----+---------+-------+|  1 | alibaba | china |+----+---------+-------+#配置从数据库节点[root@nfs-server ~]# hostnamectl set-hostname mysql2[root@nfs-server ~]# lougout[root@mysql2 ~]# [root@mysql2 ~]# setenforce 0[root@mysql2 ~]# systemctl stop firewalld[root@mysql2 ~]# vi /etc/hosts::1     localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.100.15 mysql1192.168.100.16 mysql2[root@mysql2 ~]# yum install -y mariadb mariadb-server[root@mysql2 ~]# systemctl start mariadb[root@mysql2 ~]# systemctl enable mariadb            [root@mysql2 ~]# 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 currentpassword for the root user.  If you've just installed MariaDB, andyou 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 MariaDBroot user without the proper authorisation.Set root password? [Y/n] yNew password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures 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 canaccess.  This is also intended only for testing, and should be removedbefore 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 farwill 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 MariaDBinstallation should now be secure.Thanks for using MariaDB![root@mysql2 ~]# vi /etc/my.cnf  #配置数据库主节点log_bin=mysql-bin  #记录操作日志binlog_ignore_db=mysql  #不同步系统数据库server_id=16     #节点id[root@mysql2 ~]# systemctl restart mariadb[root@mysql2 ~]# mysql -uroot  -p000000Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 2Server version: 5.5.68-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> #从节点mysql2上登录mariadb数据库,配置从节点连接主机节点的连接信息MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000';Query OK, 0 rows affected (0.02 sec)MariaDB [(none)]> start slave;  #开启从节点服务Query OK, 0 rows affected (0.01 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: 0Master_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: 151 row in set (0.00 sec)MariaDB [(none)]> show databases;   #从节点验证复制功能+--------------------+| Database       |+--------------------+| information_schema || mysql        || performance_schema || test         |+--------------------+4 rows in set (0.00 sec)MariaDB [(none)]> use test;MariaDB [test]> show tables;+----------------+| Tables_in_test |+----------------+| company    |+----------------+MariaDB [test]> select * from company;+----+---------+-------+| id | name  | addr  |+----+---------+-------+|  1 | alibaba | china |+----+---------+-------+
四、Nginx服务
1、Nginx基本概念
      ​Nginx(enginex)是一个高性能的HTTP和反向代理Web服务器,同时也提供了IMAP、POP3、SMTP服务。
2、Nginx主要用途
​       在连接高并发的情况下,Nginx是Apache服务不错的替代品。Nginx在美国是做虚拟主机生产商经常选择的软件平台之一。它能支持高达50,000个并发连接数的响应,Nginx为用户选择了epoll and kqueue作为开发模型。
1)服务器:
2)代码
3)代理服务器
3、Nginx特点
​1)跨平台
2)配置简
3)非阻塞、高并发连接事
4)事件驱动
4、Nginx服务架构
         ​Nginx服务器使用 master/worker多进程模式。主进程(Master process)启动后,会接收和处理外部信号;主进程启动后,通过fork( )函数产生一个或多个子进程(workprocess),每个子进程会进行进程初始化、模块调用以及对事件的接收和处理等工作。下图为Nginx服务架构图。
DSC0005.png
图5:  Nginx服务架构图

五、实战案例——部署Nginx服务
1、案例目标
1)了解Nginx服务的架构与使用
2)了解Nginx服务的编译安装与配置
2、案例分析
IP: 192.168.100.17       主机名:nginx       节点: Nginx节点
3、案例实施
[root@nginx ~]# setenforce 0[root@nginx ~]# systemctl stop firewalld[root@nginx ~]# systemctl disable firewalld[root@nginx ~]# yum install gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel -y [root@nginx ~]# groupadd -g 1001 nginx[root@nginx ~]# useradd -u 900 nginx -g nginx -s /sbin/nologin[root@nginx ~]# tail -l /etc/passwdsystemd-network:x:192:192:systemd Network Management:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:999:998:User for polkitd:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinchrony:x:998:996::/var/lib/chrony:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinnginx:x:900:1001::/home/nginx:/sbin/nologin[root@nginx src]# pwd/usr/local/src[root@nginx src]# ll总用量 960-rw-r--r--. 1 root root 981687 11月 14 14:07 nginx-1.12.2.tar.gz[root@nginx src]# tar -zxvf nginx-1.12.2.tar.gz [root@nginx src]# cd nginx-1.12.2[root@nginx 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 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 -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@nginx nginx-1.12.2]# nginx[root@nginx nginx-1.12.2]# netstat -ntplActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address       Foreign Address     State     PID/Program name  tcp    0    0 0.0.0.0:111       0.0.0.0:*         LISTEN    570/rpcbind     tcp    0    0 0.0.0.0:80        0.0.0.0:*         LISTEN    10386/nginx: master [root@nginx nginx-1.12.2]# lsof -i:80COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEnginx   10386  root  6u  IPv4  30485    0t0  TCP *:http (LISTEN)nginx   10387 nginx  6u  IPv4  30485    0t0  TCP *:http (LISTEN)
DSC0006.jpg 图6  nginx测试页面

六、实战案例——安装PHP环境
1、案例目标
1)了解PHP环境的使用场景
2)掌握PHP环境的编译安装与配置。
2、规划节点
DSC0007.png
3、案例实施
[root@php ~]# yum install gcc gcc-c++ libxml2-devel libcurl-devel openssl-devel bzip2-devel -y[root@php ~]# cd /usr/local/src/[root@php src]# rz  [root@php src]# ll总用量 1304-rw-r--r--. 1 root root 1335178 11月 14 14:06 libmcrypt-2.5.8.tar.gz[root@php src]# tar -zxvf libmcrypt-2.5.8.tar.gz  [root@php src]# cd libmcrypt-2.5.8/[root@php libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt && make && make install root@php src]#  rz [root@php src]# ll-rw-r--r--. 1 root root  1335178 11月 14 14:06 libmcrypt-2.5.8.tar.gz-rw-r--r--. 1 root root 19258986 11月 14 14:08 php-5.6.27.tar.gz[root@php src]# tar  -zxvf php-5.6.27.tar.gz [root@php src]# 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......................................Installing shared extensions:   /usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/Installing PHP CLI binary:    /usr/local/php5.6/bin/Installing PHP CLI man page:    /usr/local/php5.6/php/man/man1/Installing PHP FPM binary:    /usr/local/php5.6/sbin/Installing PHP FPM config:    /usr/local/php5.6/etc/Installing PHP FPM man page:    /usr/local/php5.6/php/man/man8/Installing PHP FPM status page:   /usr/local/php5.6/php/php/fpm/Installing PHP CGI binary:    /usr/local/php5.6/bin/Installing PHP CGI man page:    /usr/local/php5.6/php/man/man1/Installing build environment:   /usr/local/php5.6/lib/php/build/Installing header files:       /usr/local/php5.6/include/php/Installing helper programs:     /usr/local/php5.6/bin/  program: phpize  program: php-configInstalling man pages:       /usr/local/php5.6/php/man/man1/  page: phpize.1  page: php-config.1Installing PEAR environment:    /usr/local/php5.6/lib/php/[PEAR] Archive_Tar  - installed: 1.4.0[PEAR] Console_Getopt - installed: 1.4.1[PEAR] Structures_Graph- installed: 1.1.1[PEAR] XML_Util     - installed: 1.3.0[PEAR] PEAR       - installed: 1.10.1Wrote PEAR system config file at: /usr/local/php5.6/etc/pear.confYou may want to add: /usr/local/php5.6/lib/php to your php.ini include_path/usr/local/src/php-5.6.27/build/shtool install -c ext/phar/phar.phar /usr/local/php5.6/binln -s -f phar.phar /usr/local/php5.6/bin/pharInstalling PDO headers:       /usr/local/php5.6/include/php/ext/pdo/[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 -l /etc/passwddbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:999:998:User for polkitd:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinchrony:x:998:996::/var/lib/chrony:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologintss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologinnginx: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 [root@php php-5.6.27]# chkconfig --add php-fpm[root@php php-5.6.27]# chkconfig php-fpm on[root@php php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf#配置文件php-fpm.comf[root@php php-5.6.27]# vi /usr/local/php5.6/etc/php-fpm.confpid = run/php-fpm.pidser = nginxgroup = nginxlisten = 192.168.100.10:9000pm = dynamicpm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 35[root@php php-5.6.27]# service php-fpm startStarting php-fpm  done  #启动php服务[root@php php-5.6.27]# netstat  -ntplActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address       Foreign Address     State     PID/Program name  tcp    0    0 192.168.100.10:9000   0.0.0.0:*         LISTEN    16160/php-fpm: mast tcp    0    0 0.0.0.0:111       0.0.0.0:*         LISTEN    694/rpcbind     tcp    0    0 0.0.0.0:22        0.0.0.0:*         LISTEN    1073/sshd       tcp    0    0 127.0.0.1:25      0.0.0.0:*         LISTEN    1503/master     tcp6     0    0 :::111          :::*          LISTEN    694/rpcbind     tcp6     0    0 :::22           :::*          LISTEN    1073/sshd       tcp6     0    0 ::1:25          :::*          LISTEN    1503/master   [root@php ~]# lsof -i:9000COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEphp-fpm 1023  root  7u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)php-fpm 1027 nginx  0u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)php-fpm 1028 nginx  0u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)php-fpm 1029 nginx  0u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)php-fpm 1030 nginx  0u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)php-fpm 1031 nginx  0u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)php-fpm 1545 nginx  0u  IPv4  20279    0t0  TCP php:cslistener (LISTEN)
七、实战案例——分布式部署LNMP+WordPress
1、案例目标
    了解分布式部署WordPress的架构;掌握分布式部署WordPress应用配置与操作。
2、案例分析
DSC0008.png
​操作系统:CentOS Linux release 7.9.2009
数据库系统:mysql  Ver 15.1 Distrib 5.5.68-MariaDB
Web服务器软件: nginx/1.12.2
PHP版本:PHP/5.6.27​
DSC0009.png
3、案例实施
1)配置Nginx支持php[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf............... location / {      root   /www;      index  index.php  index.html index.htm;    }...................... location ~ \.php$ {      root       /www;      fastcgi_pass   192.168.100.10:9000;      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  SCRIPT_FILENAME  $document_root$fastcgi_script_name;...........................2)创建目录[root@nginx ~]# mkdir /www[root@nginx ~]# chown nginx:nginx /www/[root@php ~]# mkdir /www[root@php ~]# chown nginx:nginx /www/3)部署WordPresssroot@nginx ~]# rz [root@nginx ~]# ll-rw-r--r--. 1 root root 9210722 11月 14 14:06 wordpress-4.7.3-zh_CN.zip[root@nginx www]# unzip-bash: unzip: 未找到命令[root@nginx www]# yum install unzip[root@nginx ~]# unzip wordpress-4.7.3-zh_CN.zip [root@nginx ~]# mv wordpress/* /www/[root@nginx ~]# cp /www/wp-config-sample.php  /www/wp-config.php[root@nginx ~]# vi /www/wp-config.php ........................................./** WordPress数据库的名称 */define('DB_NAME', 'wordpress');/** MySQL数据库用户名 */define('DB_USER', 'root');/** MySQL数据库密码 */define('DB_PASSWORD', '000000');/** MySQL主机 */define('DB_HOST', '192.168.100.15');/** 创建数据表时默认的文字编码 */define('DB_CHARSET', 'utf8');............................#将该配置文件复制至php节点的/www目录下[root@nginx ~]# scp  /www/wp-config.php root@192.168.100.10:/www/The authenticity of host '192.168.100.10 (192.168.100.10)' can't be established.ECDSA key fingerprint is SHA256:PfKqCC7xD/f7wowIiWVPt+HVFgYtp9SdCdF4kCnqTWA.ECDSA key fingerprint is MD5:f3:fb:03:66:ec:30:0a:8a:32:3e:e1:99:06:fb:e7:ed.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.100.10' (ECDSA) to the list of known hosts.root@192.168.100.10's password: wp-config.php                   100% 2910  769.4KB/s   00:00   [root@php /]# ll /www/-rw-r--r--. 1 root root 2910 11月 14 17:08 wp-config.php[root@mysql1 ~]# mysql -uroot -p000000MariaDB [(none)]> create database wordpress;Query OK, 1 row affected (0.01 sec)[root@nginx ~]# nginx -s  reload
DSC00010.jpg
DSC00011.jpg DSC00012.jpg
DSC00013.png


关注下面的标签,发现更多相似文章