快速搭建服务器依赖环境

1. 安装docker、docker-compose

sudo yum -y install docker
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

2. 构建mysql、redis、rabbitmq容器[docker-compose.yml]

version: '3'
services:
  redis:
    image: redis
    container_name: redis
    restart: always
    ports:
      - 6379:6379
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 1000M
    volumes:
      - ./redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - /etc/localtime:/etc/localtime:ro
      - ./redis/data:/data
    command: redis-server /usr/local/etc/redis/redis.conf
  rabbitmq:
    image: rabbitmq:management
    container_name: rabbitmq
    restart: always
    ports:
      - 5672:5672
      - 15672:15672
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 1000M
    volumes:
      - /etc/localtime:/etc/localtime:ro
    environment:
      RABBITMQ_DEFAULT_USER: admin
      RABBITMQ_DEFAULT_PASS: admin
  mysql:
    image: mysql:5.7.23
    container_name: mysql
    restart: always
    ports:
      - 3306:3306
    volumes:
      - ./mysql/3306:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    environment:
      MYSQL_ROOT_PASSWORD: root
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max_allowed_packet=128M --max_connections=6000 --lower_case_table_names=1 --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3. 安装nginx

wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

 

tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
make
make install
cd ..
rm -rf nginx-1.12.0
rm -rf nginx-1.12.0.tar.gz

4. 配置环境变量

 

vi /etc/profile

最下面添加,并保存
 

export PATH="$PATH:/usr/local/nginx/sbin"

更新环境变量

source /etc/profile

5. 修改nginx配置

默认路径 -》/usr/local/nginx/conf/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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
include /home/xxx/global/nginx/*.conf;
}

扩展配置文件:

http配置模版:

server{
  client_max_body_size 100m;
  listen 80;
#  server_name www.mycompany.com;
  root /usr/share/nginx/html;
  index index.html index.htm;
  keepalive_timeout 1800s;
  send_timeout 1800s;
  proxy_connect_timeout 1800s;/Users/simpo/Documents/workspace/config/ssl.conf
  proxy_send_timeout 1800s;
  proxy_read_timeout 1800s;
#文件上传
  location ^~ /api/upload {
    proxy_pass http://sc-upload:69/upload;
  }
#上传显示
  location  /uploads {
    alias /uploads;
    break;
  }
#前端访问
  location ^~ /admin {
    try_files $uri $uri/ /admin/index.html;
  }
#后端 api服务配置
  location ^~ /api/sys {
    proxy_pass http://sys:68/sys;
  }

  location ^~ /api/demo {
    proxy_pass http://demo:67/demo;
  }

#  location ^~ /api/ {
#    proxy_pass http://sc-zuul/;
#  }
}

ssl 配置模版:

server{
        client_max_body_size 100m;
        listen              443 ssl;
        proxy_ssl_session_reuse off;
#        server_name         soc.youline.cn;
        ssl_certificate     ./conf.d/cert/xxx.pem;
        ssl_certificate_key ./conf.d/cert/xxx.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        root /usr/share/nginx/html;
        index index.html index.htm;
        location ^~ /api/demo {
                proxy_pass http://demo:67/demo; 
        }
        location ^~ /api/sys {
                proxy_pass http://sys:68/sys;        
        }
        #文件上传
        location ^~ /api/upload {
                proxy_pass http://sc-upload:69/upload;
        }
        #上传显示
        location  /uploads {
                alias /uploads;
                break;
        }
        #前端访问静态文件
        location ^~ /admin { 
                try_files $uri $uri/ /admin/index.html;
        }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多懂一些

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值