nginx+apache动静分离/负载均衡
【主从】
【Mysql-Master】 log-bin=mysql-bin
server-id = MariaDB [(none)]> grant replication slave on *.* to 'slave'@'192.168.2.158' identified by '123.com'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin. | | | |
+------------------+----------+--------------+------------------+ 【Mysql-slave】 server-id = MariaDB [(none)]> slave stop;
Query OK, rows affected, warning (0.00 sec) MariaDB [(none)]> change master to
-> master_host='192.168.2.157',
-> master_user='slave',
-> master_password='123.com',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=;
Query OK, rows affected (0.09 sec) MariaDB [(none)]> slave start;
Query OK, rows affected (0.00 sec)
主从成功~
【两台服务器站点虚拟主机配置】
# vim /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen
AddType application/x-httpd-php .php
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
Include conf/vhosts.conf
mkdir -p /var/www/html/dz.bxy.net/
mkdir -p /var/www/html/wps.bxy.net/
#vim /etc/httpd/conf/vhosts.conf
<VirtualHost *:>
ServerAdmin admin@amsilence.com
DocumentRoot "/var/www/html/dz.bxy.net/"
ServerName dz.bxy.net
ErrorLog "/etc/httpd/logs/www-error_log"
CustomLog "/etc/httpd/logs/www-access_log" common
</VirtualHost>
NameVirtualHost *:
<VirtualHost *:>
ServerAdmin admin@amsilence.com
DocumentRoot "/var/www/html/wps.bxy.net"
ServerName wps.bxy.net
ErrorLog "/etc/httpd/logs/www-error_log"
CustomLog "/etc/httpd/logs/www-access_log" common
</VirtualHost>
192.168.2.157站点
【Discuz和workpress部署】
# cd /var/www/html/
#wget http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip
#wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
#unzip Discuz_X3.1_SC_UTF8.zip -d Discuz/
[root@localhost Discuz]# mv upload/* .
[root@localhost Discuz]# chmod o+x uc_server/ config/ uc_client/
MariaDB [(none)]> create database DiscuzDB charset=utf8;
MariaDB [(none)]> grant all on DiscuzDB.* to 'discuz'@'%' identified by '123.com';
MariaDB [(none)]> flush privileges
hosts解析:因为要通过域名连接数据库地址,那么我们需要将数据库的IP地址和自定义域名解析
【wordpress网站部署】
#tar zxvf wordpress-4.9.4-zh_CN.tar.gz -C wordpress/
【数据库授权】
MariaDB [(none)]> create database wpsDB charset=utf8;
MariaDB [(none)]> grant all on *.* to 'wpsuser'@'%' identified by '123.com';
MariaDB [(none)]> flush privileges;
host解析:我们将wordpress域名解析到2.157主库ip地址跟后面即可
[root@lamp-master wps.bxy.net]# vim wp-config.php
<?php
/**
* WordPress基础配置文件。
*
* 这个文件被安装程序用于自动生成wp-config.php配置文件,
* 您可以不使用网站,您需要手动复制这个文件,
* 并重命名为“wp-config.php”,然后填入相关信息。
*
* 本文件包含以下配置选项:
*
* * MySQL设置
* * 密钥
* * 数据库表名前缀
* * ABSPATH
*
* @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
*
* @package WordPress
*/ // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpsDB'); /** MySQL数据库用户名 */
define('DB_USER', 'wpsuser'); /** MySQL数据库密码 */
define('DB_PASSWORD', '123.com'); /** MySQL主机 */
define('DB_HOST', 'wps.mysql.net'); /** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8mb4'); /** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', ''); /**#@+
* 身份认证密钥与盐。
*
* 修改为任意独一无二的字串!
* 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/
* WordPress.org密钥生成服务}
* 任何修改都会导致所有cookies失效,所有用户将必须重新登录。
*
* @since 2.6.0
*/
define('AUTH_KEY', 'kXeW~n6gq[_u;k=49+z=Am9a15F@D)|?8~SKt(A0K,^!U/u4yOvb ]6J._LJ!KPg');
define('SECURE_AUTH_KEY', 'ui|@1SGGC!Wpi)lMdBuh^~.ueevR$ar]B_X8#|&&U.z4YGH02RVSK(`8X2hho)Xm');
define('LOGGED_IN_KEY', 'cd)V9bEPLk4|Q=Z<Ri_Sfp*nvg/Ui+BgHXGL./o@AUP!dMRE=PYV7nJ_&ijK*#y~');
define('NONCE_KEY', ':-sd O<^pJvN. ;:SuxaSx5kd%W`.Y.z_xN6Nc@zhz&d_^SM*X4(K@&;aQo2wAko');
define('AUTH_SALT', 'O[@Bx|zqp@7{^NF2Q,N6y4d]9&|+Qy$qB6zknzm4tkiOqa4Si5;)/lst@&;!r8%;');
define('SECURE_AUTH_SALT', '~ r8gh?MF$I-)I~9kCC0>p(|nx7vF34<^ZN~AS~lb1Tzx-0SEvf3V1vi0+kQS#>_');
define('LOGGED_IN_SALT', '-CgDBdxb$N9Kw:MI+>c5WUxW,W141KP-6/tDV!I5s]m/H:#ltw(dP?0Ar]0cz]Yw');
define('NONCE_SALT', 'ze9RdLoKcC-Bsl%<n6VjzDVz#Gu(h&t ^UkuqIpAz<$kN.7Cm|4p|{!Cyg[lOia;'); /**#@-*/ /**
* WordPress数据表前缀。
*
* 如果您有在同一数据库内安装多个WordPress的需求,请为每个WordPress设置
* 不同的数据表前缀。前缀名只能为数字、字母加下划线。
*/
$table_prefix = 'wp_'; /**
* 开发者专用:WordPress调试模式。
*
* 将这个值改为true,WordPress将显示所有用于开发的提示。
* 强烈建议插件开发者在开发环境中启用WP_DEBUG。
*
* 要获取其他能用于调试的信息,请访问Codex。
*
* @link https://codex.wordpress.org/Debugging_in_WordPress
*/
define('WP_DEBUG', false); /**
* zh_CN本地化设置:启用ICP备案号显示
*
* 可在设置→常规中修改。
* 如需禁用,请移除或注释掉本行。
*/
define('WP_ZH_CN_ICP_NUM', true); /* 好了!请不要再继续编辑。请保存本文件。使用愉快! */ /** WordPress目录的绝对路径。 */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/'); /** 设置WordPress变量和包含文件。 */
require_once(ABSPATH . 'wp-settings.php');
到此为止,2.157服务器上的两个网站已经全部发布完成,接下来,将该站点上的内容全部同步到2.158上,为后续的负载均衡做准备
rsync -aP --delete /var/www/html/dz.bxy.net/ root@192.168.2.158:/var/www/html/dz.bxy.net/
rsync -aP --delete /var/www/html/wps.bxy.net/ root@192.168.2.158:/var/www/html/wps.bxy.net/
同理2.158也需要做本地hosts域名解析
两条命令搞定,2.158只需要将httpp虚机主机搭建起来,配置好与之相同的虚拟主机即可,然后将2.157部署的好网站源码同步过去即可,不需要重新解压~
【Nginx前端负载均衡+动静分离】
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
include vhosts/*.conf;
}
[root@dz nginx]# mkdir -p /etc/nginx/vhosts/
[root@dz nginx]# egrep -v "#|^$" /etc/nginx/vhosts/upstream.conf
upstream httpd_webapp{
server 192.168.2.157;
server 192.168.2.158;
}
[root@dz nginx]# egrep -v "#|^$" /etc/nginx/vhosts/wps.conf
server {
listen ;
server_name wps.bxy.net;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://httpd_webapp;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /var/www/html/wps.bxy.net;
expires 3d;
}
}
[root@dz nginx]# egrep -v "#|^$" /etc/nginx/vhosts/dz.conf
server {
listen ;
server_name dz.bxy.net;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://httpd_webapp;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /var/www/html/dz.bxy.net;
expires 3d;
}
}
nginx+apache动静分离/负载均衡的更多相关文章
- Nginx网络架构实战学习笔记(三):nginx gzip压缩提升网站速度、expires缓存提升网站负载、反向代理实现nginx+apache动静分离、nginx实现负载均衡
文章目录 nginx gzip压缩提升网站速度 expires缓存提升网站负载 反向代理实现nginx+apache动静分离 nginx实现负载均衡 nginx gzip压缩提升网站速度 网页内容的压 ...
- 15 nginx反向代理实现nginx+apache动静分离
一:nginx反向代理实现nginx+apache动静分离-------------概念--------------------------- nginx反向代理服务器+负载均衡 用nginx做反向代 ...
- Nginx+Apache动静分离
Nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术.动静分离技术其实是采用代理的方式,在server{}段中加入带正则匹配的location来指定匹配项 针对PHP的动 ...
- Nginx动静分离负载均衡
前期准备 使用Debian环境.安装Nginx(默认安装),一个web项目,安装tomcat(默认安装)等. Nginx.conf配置 # 定义Nginx运行的用户 和 用户组 如果对应服务器暴露在外 ...
- [nginx] - 使用nginx实现反向代理,动静分离,负载均衡,session共享
反向代理概念 先说正向代理,比如要访问youtube,但是不能直接访问,只能先找个FQ软件,通过FQ软件才能访问youtube. FQ软件就叫做正向代理.所谓的反向代理,指的是用户要访问youtube ...
- Nginx 笔记与总结(15)nginx 实现反向代理 ( nginx + apache 动静分离)
在 nginx 中,proxy 用来实现反向代理,upstream 用来实现负载均衡. 例如有两台服务器,nginx 服务器作为代理服务器,执行 .html 文件,apache 服务器上执行 .php ...
- 使用nginx实现动静分离的负载均衡集群
一.概述: LB负载均衡集群分两类: LVS (四层)和 nginx或haproxy (七层) 客户端通过访问分发器的VIP来访问网站 |现在应用更复杂,比如现在网站页面有: .php .html . ...
- nginx反向代理,负载均衡,动静分离,rewrite地址重写介绍
一.rewrite地址重写 地址转发后客户端浏览器地址栏中的地址显示是不变的,而地址重写后地址栏中的地址会变成正确的地址. 在一次地址转发过程中只会产生一次网络请求,而一次地址重写产生两次请求. 地址 ...
- Nginx+Tomcat+Redis实现负载均衡、资源分离、session共享
Nginx+Tomcat+Redis实现负载均衡.资源分离.session共享 CentOS安装Nginx http://centoscn.com/CentosServer/www/2013/0910 ...
随机推荐
- bzoj3277-串
Code #include<cstdio> #include<iostream> #include<cmath> #include<cstring> # ...
- Java拓展接口-default关键词
Java接口在使用过程中有两点规定: 1.接口中只能有定义方法名.方法返回类型,不能有方法的实现. 2.实现接口的类,必须实现接口中所有的方法. 例如下面的例子: //定义接口 public inte ...
- Django之缓存、信号和图片验证码
一. 缓存 1. 介绍 缓存通俗来说:就是把数据先保存在某个地方,下次再读取的时候不用再去原位置读取,让访问速度更快. 缓存机制图解 2.Django中提供了6种缓存方式 1. 开发调试 2. 内存 ...
- Android 6.0以上动态获取权限
首先在清单文件中注册 然后在MainActivity.java中将权限封装到一个String数组中 static final String[] PERMISSION = new String[]{ M ...
- bzoj 2816: [ZJOI2012]网络 (LCT 建多棵树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2816 题面: http://www.lydsy.com/JudgeOnline/upload ...
- 在Ubuntu上使用离线方式快速安装K8S v1.11.1
在Ubuntu上使用离线方式快速安装K8S v1.11.1 0.安装包文件下载 https://pan.baidu.com/s/1nmC94Uh-lIl0slLFeA1-qw v1.11.1 文件大小 ...
- POJ--3349 Snowflake Snow Snowflakes(数字hash)
链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...
- 第四章:条件语句(if)和循环结构(while)
1.流程控制 含义与作用 Python程序执行,一定按照某种规律在执行 a.宏观一定是自上而下(逻辑上方代码一定比逻辑下方代码先执行):顺序结构b.遇到需要条件判断选择不同执行路线的执行方式:分支结构 ...
- mysql5.7 修改root密码无法登陆原因
升级的mysql5.7修改完root账户密码后仍然无法登陆,查阅资料可能和user表的plugin 字段为空有关. 1.首先将my.ini中加入在[mysqld]节点上加skip-grant-tabl ...
- vue-cli3.0 gui(一)
vue-cli3.0 gui 安装: npm i core-js -g:用于JavaScript的模块化标准库. npm i -g @vue/cli:vue的脚手架工具 运行: vue ui:运行vu ...