本次案例很特别,来到新公司之后接手了一个项目。作为开发99%情况下都不需要过多考虑基础设施的安装配置,比如Nginx、keepalived、mysql等基础设施安装配置,故而通过以下几篇日记来记录项目上线所面临的挑战:

  (一) Nginx部署 和 内外网络配置

  (二) keepalived实现VIP和nginx可用性检查

  (三) Mysql高可用主从配置

1、安装环境:centos7 Nginx 1.16.1
2、主机: 192.168.30.7 从机:192.168.30.8

 

(一) Nginx部署 和 内外网络配置

1、安装Nginx 具体安装shell脚本 nginx_install.sh 


 

#!/bin/bash

echo 'begin install nginx'

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

tar -zxvf nginx-1.16.1.tar.gz

cd nginx-1.16.1

mkdir -p /var/application/nginx

./configure --prefix=/usr/local/nginx

make && make install

echo 'end install nginx'

 注意点:

(1)需要将nginx-1.16.1.tar.gz 和 nginx_install.sh放在一个目录

(2)prefix=/usr/local/nginx 为自定义nginx的安装目录,可以自由指定

(3)/var/application/nginx存放nginx日志目录,可以自由指定

 

2、网络拓扑 和 nginx.conf 配置 


 网络拓扑图如下:

开发运维日记 (一) Nginx部署和内外网配置

 nginx.conf 配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                      'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';

    access_log  /var/application/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # nginx ip: 192.168.30.7/8
    # vip: 192.168.30.77

    upstream myservice {
        server 192.168.30.7:8080;
        server 192.168.30.8:8080;
    }

    # 对外
    server {
            listen 80;
            listen [::]:80 default_server;

            #root /var/www/html;

            # Add index.php to the list if you are using PHP
            # index index.html index.htm index.nginx-debian.html;

			location / {
				root   html;
				index  index.html index.htm;
			}

            location /path/api/ {
                proxy_pass http://myservice;
                proxy_read_timeout 300;
                proxy_connect_timeout 300;

                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            }

            location /path/ui/g-web/ {
                proxy_pass http://myservice;
                proxy_read_timeout 300;
                proxy_connect_timeout 300;

                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            }
            # 静态资源映射
            location /static/resource {
                alias /usr/app/static/resource/;
            }

            # 内网deny 
            location /path/api/inner {
                   deny all;
            }
            
            location /path/inner {
                   deny all;
            }
            
            location /path/ui {
                   deny all;
            }
    }

    # 对内
    server {
            listen 8000;
            listen [::]:8000;

            #root /var/www/html;

            # Add index.php to the list if you are using PHP
            #index index.html index.htm index.nginx-debian.html;


            location /path/ {
                proxy_pass http://myservice;
                proxy_read_timeout 300;
                proxy_connect_timeout 300;

                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            }
    }

}
View Code

相关文章:

  • 2021-07-12
  • 2022-12-23
  • 2021-11-11
  • 2021-11-26
  • 2022-01-02
  • 2021-09-17
  • 2022-12-23
  • 2021-11-10
猜你喜欢
  • 2021-11-20
  • 2021-11-15
  • 2022-01-16
  • 2022-02-08
  • 2021-12-05
  • 2022-01-08
相关资源
相似解决方案