网站首页 > 技术教程 正文
# 高可用的并发解决方案nginx+keepalived(三)
## 一、Nginx搭建图片服务器
针对任何站点,几乎都要访问图片,而一个网页里面几乎有好些张图片,这时候会占据大量tomcat连接,造成大量并发,我们可以通过Nginx配置直接访问硬盘里的图片,绕开tomcat。
### 1、在 CentOS7 服务器上,创建 /usr/local/images 图片目录,并上传一些图片。
```bash
[root@localhost tomcat]# mkdir /usr/local/images
[root@localhost tomcat]# ll /usr/local/images
总用量 3252
-rw-r--r--. 1 root root 90981 4月 10 18:34 linux-1.png
-rw-r--r--. 1 root root 74607 4月 10 18:36 linux-2.png
-rw-r--r--. 1 root root 200272 4月 10 18:37 linux-3.png
-rw-r--r--. 1 root root 129088 4月 10 18:37 linux-4.png
-rw-r--r--. 1 root root 349338 4月 10 18:38 linux-5.png
-rw-r--r--. 1 root root 235418 4月 10 18:39 linux-6.png
-rw-r--r--. 1 root root 588721 4月 10 18:39 linux-7.png
-rw-r--r--. 1 root root 720943 8月 9 10:38 tomcat-1.png
-rw-r--r--. 1 root root 137273 8月 9 10:39 tomcat-2.png
-rw-r--r--. 1 root root 759789 8月 9 11:06 tomcat-3.png
-rw-r--r--. 1 root root 19229 8月 9 11:07 tomcat-4.png
```
### 2、打开并编辑 nginx 配置文件vim /usr/local/nginx/nginx/conf/nginx.conf
```bash
# 切换目录
[root@localhost nginx]# cd /usr/local/nginx
# 打开 nginx 配置文件
vim /usr/local/nginx/nginx/conf/nginx.conf
# 配置内容如下:
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# Nginx处理HTTP负载均衡
upstream clustertomcat {
server 192.168.43.216:8081 weight=2;
server 192.168.43.216:8082 weight=1;
server 192.168.43.216:8083 weight=1;
}
server {
# nginx 默认监听端口80
listen 80;
server_name localhost;
location /images/ {
root /usr/local;
}
location / {
# 代理路径
proxy_pass http://clustertomcat;
}
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
# ESC + :wq 保存退出
# 切换目录
cd /usr/local/nginx/
# 重新载入 nginx
[root@localhost nginx]# ./nginx/sbin/nginx -s reload
# 或者先停止 nginx 再重新启动 nginx
[root@localhost nginx]# ./nginx/sbin/nginx -s quit
[root@localhost nginx]# ./nginx/sbin/nginx -c /usr/local/nginx/nginx/conf/nginx.conf
```
### 3、访问测试 nginx 图片服务器,浏览器地址栏输入(其中:192.168.43.216 为你的虚拟机 IP 地址):
http://192.168.43.216/images/linux-1.png
## 二、Keepalived+Nginx主备分析
### 1、keepalived + nginx 集群解决单点故障
再牛逼的软件我们也不能保证它一定不挂,为了防止Nginx挂了导致整个服务无法使用的灾难发生,我们这里可以考虑使用Keepalived+Nginx集群实现高可用。
### 2、Keepalived+Nginx主备分析简略图
Keepalived+Nginx主备分析简略图.png
## 三、Nginx+keepalived高可用-Nginx安装
### 1、Nginx+keepalived高可用方案介绍
VIP | IP | 主机名 | 主从 |
192.168.43.211 | 192.168.43.216 | keep216 | master |
192.168.43.205 | keep205 | backup |
### 2、VirtualBox-6.0.6 安装 第二个 CentOS7--2 虚拟机。
https://dzs168.blog.csdn.net/article/details/141631390
### 3、在 CentOS7--2 虚拟机上,安装 Ngnix
https://www.toutiao.com/article/7410289588238959145/
### 4、在 CentOS7--2 虚拟机上,启动 nginx 访问测试。
1)关闭防火墙
```bash
[root@localhost nginx]# systemctl stop firewalld
```
2)启动 nginx
```bash
# 切换目录
cd /usr/local/nginx
# 启动 nginx
[root@localhost nginx]# ./nginx/sbin/nginx
```
3)浏览器地址栏输入:http://192.168.43.205/ 进行访问测试。
nginx-login.png
上一节关联链接请点击:
https://www.toutiao.com/article/7416607689272295936/
猜你喜欢
- 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双机负载均衡配置)
你 发表评论:
欢迎- 08-06linux 和 windows文件格式互相转换
- 08-06谷歌 ChromeOS 已支持 7z、iso、tar 文件格式
- 08-06Linux下比较文件内容的6种方法
- 08-06文件格式及功能汇总
- 08-0610个Linux文件内容查看命令的实用示例
- 08-06Linux-如何区分不同文件类型
- 08-06Zabbix技术分享——监控windows进程资源使用情况
- 08-06Linux系统卡顿?学会ps命令这三招,轻松定位问题进程
- 最近发表
- 标签列表
-
- 下划线是什么 (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)
本文暂时没有评论,来添加一个吧(●'◡'●)