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;
}
}