网站首页 > 技术教程 正文
一、准备工作
先安装 pcre pcre-devel openssl openssl-devel
二、nginx安装
./configure --user=YEYIBOY --group=YEYIBOY --prefix=/usr/local/nginx1.18 --with-http_stub_status_module --with-http_ssl_module
Make
Make install
/usr/local/nginx1.6.2/sbin/nginx -t 检查语法
三、编辑配置文件
打开 cd /usr/local/nginx/conf/
编辑sudo vim nginx.conf
在http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65;下面增加
Upstream backend {
ip_hash; 使同一主机始终登录同一台机器
Server 192.168.160.154:80 max_fails=3 fail_timeout=30;
Server 192.168.160.155:80 max_fails=3 fail_timeout=30;
}
server {
listen 80;
server_name www.yeyiboy.com yeyiboy.com;
index index.html index.htm;
location / {
proxy_pass http://backend; (外部主机来访问时,通过负载均衡器,采用轮询,平均抛给上面的192.168.160.154 192.168.160.155 主机)
proxy_set_header Host $host; (假设一台机器设置多个服务网站时,为了域名不混乱,应加这行和下行)
proxy_set_header X-Forwarded-For $remote_addr;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
主 vim /usr/local/nginx/extra/upstream01.conf
Upstream blog_real servers {
Server 10.0.0.17:80 weight=5;(权重)
Server 10.0.0.18:80 weight=5;
Server 10.0.0.19:80 weight=5;
可以去掉权重加 ip_hash;
url_hash 用在缓存服务器
}
Server { listen 80;
Server_name blog.etiantian.org;
Local / { proxy_pass http://blog_real_servers; }
}
Cd nginx.conf 添加 include extra/upstream01.conf
备:复制上面内容
Nginx支持的代理方式:proxy_pass fastcgi_pass memcached_pass
Upstream 模块应放在nginx.conf配置里的http{ }标签内
Location设置URI转发 语法: location [ =|~|~*|^~] uri {…….}
[=] 精确匹配
[~] 区分大小写
[^~] 只匹配字符串,不匹配正则表达式
[~*] 不区分大小写
[@] 指定一个命名的location 一般只用于内部重定向请求
http_proxy_module 从一台转发到另一台
proxy_set_header XForwarded-For $remote_addr 让web服务器记录用户IP
proxy_set_header Host $host 查找主机
proxy_next_upstream 健康检查
nginx 四层负载均衡配置 (events与http之间添加图中涂黄部分)
cd /usr/local/nginx1.12
./confgure --prefix=/usr/local/nginx --with-stream
make
make install
vim /usr/local/nginx/conf/nginx.conf
events {
worker_connections 1024; }
stream {
upstream mysite { server 192.168.1.1:8080; }
server { listen 3306; proxy_pass mysite; } }
http {
include mime.types;
default_type application/octet-stream;
Keepalived+nginx配置
Keepalived配置
sudo vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.254/24
192.168.1.253/24
}
}
Nginx配置
Sudo vim /usr/local/nginx/conf/nginx.cong
upstream www.yeyiboy.com{
#ip_hash;
server 192.168.1.135:80 max_fails=3 fail_timeout=30;
server 192.168.1.138:80 max_fails=3 fail_timeout=30;
}
upstream blog.yeyiboy.com{
#ip_hash;
server 192.168.1.135:80 max_fails=3 fail_timeout=30;
server 192.168.1.138:80 max_fails=3 fail_timeout=30;
}
upstream bbs.yeyiboy.com{
#ip_hash;
server 192.168.1.135:80 max_fails=3 fail_timeout=30;
server 192.168.1.138:80 max_fails=3 fail_timeout=30;
}
server {
listen 80;
server_name www.yeyiboy.com yeyiboy.com;
location / {
root html;
index index.html index.htm index.php;
proxy_pass http://www.yeyiboy.com;
}
}
server {
listen 80;
server_name blog.yeyiboy.com;
location / {
root html;
index index.html index.htm index.php;
proxy_pass http://blog.yeyiboy.com;
}
}
server {
listen 80;
server_name bbs.yeyiboy.com;
location / {
root html;
index index.html index.htm index.php;
proxy_pass http://bbs.yeyiboy.com;
}
}
}
猜你喜欢
- 2024-10-14 使用keepalived监控tomcat 达到双机热备
- 2024-10-14 keepalived的安装(keepalived安装配置)
- 2024-10-14 15分钟学会nginx+tomcat+keepalived高可用负载均衡
- 2024-10-14 搭建环境tomcat+nginx+keepalived+zabbix
- 2024-10-14 K8s 通过 keepalive+nginx 实现 nginx-ingress-controller 高可用
- 2024-10-14 流量红利下怎么用双机搭建高可用与负载均衡——(上)
- 2024-10-14 快速入门-Keepalived+Nginx-HA高可用-不啰嗦-直接上-边实践边学
- 2024-10-14 Keepalived + Nginx 实现高可用 Web 负载均衡
- 2024-10-14 Keepalived+Nginx架构配置(keepalived nginx配置)
- 2024-10-14 Nginx双机主备(Keepalived实现)(nginx双机负载均衡配置)
你 发表评论:
欢迎- 最近发表
-
- 阿里P8大佬总结的Nacos入门笔记,从安装到进阶小白也能轻松学会
- Linux环境下,Jmeter压力测试的搭建及报错解决方法
- Java 在Word中合并单元格时删除重复值
- 解压缩软件哪个好用?4款大多数人常用的软件~
- Hadoop高可用集群搭建及API调用(hadoop3高可用)
- lombok注解@Data没有toString和getter、setter问题
- Apache Felix介绍(apache fineract)
- Spring Boot官方推荐的Docker镜像编译方式-分层jar包
- Gradle 使用手册(gradle详细教程)
- 字节二面:为什么SpringBoot的 jar可以直接运行?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)