From 41111d80437ebd6e777ce024f4cbc3542d830af9 Mon Sep 17 00:00:00 2001 From: linhaojun Date: Sun, 25 Sep 2022 23:37:46 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=9A=84=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 项目部署文档.md | 408 +++++++++++++++++++++--------------------- 1 file changed, 205 insertions(+), 203 deletions(-) diff --git a/项目部署文档.md b/项目部署文档.md index 50df906..efcd00b 100644 --- a/项目部署文档.md +++ b/项目部署文档.md @@ -52,7 +52,7 @@ ## 3.安装mysql -### 3.1 无挂载模式 +### 方式1: 无挂载模式 > 这种方式直接运行mysql之后,所有关于mysql的内容都在容器中,后续如果需要修改mysql的内容,需要手动进入容器内进行操作。且在宿主机上无备份,一旦容器被删除,数据也会被删除。 @@ -61,7 +61,7 @@ docker pull mysql //下载MySQL镜像 docker run --name mysql --restart=always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=密码 -d mysql //启动MySQL ``` -### 3.2 数据卷挂载模式 +### 方式2: 数据卷挂载模式 > 和**无挂载模式相对**,通过数据卷挂载的方式运行容器,将容器内的部分重要文件映射到宿主机上。直接操作宿主机对应的映射文件就能和容器内作同步,方便操作的同时还能保证容器内的数据在宿主机上有一个备份。 > @@ -98,33 +98,33 @@ mkdir -p /home/elasticsearch/data/ mkdir -p /home/elasticsearch/config/ ``` -### 6.1 编写配置文件 +1. 编写配置文件 -```shell -echo 'http.host: 0.0.0.0 -http.cors.enabled: true -http.cors.allow-origin: "*" '>>/home/elasticsearch/config/elasticsearch.yml -``` + ```shell + echo 'http.host: 0.0.0.0 + http.cors.enabled: true + http.cors.allow-origin: "*" '>>/home/elasticsearch/config/elasticsearch.yml + ``` -### 6.2 修改文件夹权限 +2. 修改文件夹权限 -```shell -chmod -R 777 /home/elasticsearch/ -ls -l # 查看文件权限 -``` + ```shell + chmod -R 777 /home/elasticsearch/ + ls -l # 查看文件权限 + ``` -### 6.3 启动elasticseach镜像 +3. 启动elasticseach镜像 -```shell -docker run --name elasticsearch -p 9200:9200 \ - -p 9300:9300 \ - -e "discovery.type=single-node" \ - -e ES_JAVA_OPTS="-Xms64m -Xmx128m" \ - -v /home/elasticsearch/config/elasticsearch.yml:/usr/shellare/elasticsearch/config/elasticsearch.yml \ - -v /home/elasticsearch/data:/usr/shellare/elasticsearch/data \ - -v /home/elasticsearch/plugins:/usr/shellare/elasticsearch/plugins \ - -d elasticsearch:7.9.2 -``` + ```shell + docker run --name elasticsearch -p 9200:9200 \ + -p 9300:9300 \ + -e "discovery.type=single-node" \ + -e ES_JAVA_OPTS="-Xms64m -Xmx128m" \ + -v /home/elasticsearch/config/elasticsearch.yml:/usr/shellare/elasticsearch/config/elasticsearch.yml \ + -v /home/elasticsearch/data:/usr/shellare/elasticsearch/data \ + -v /home/elasticsearch/plugins:/usr/shellare/elasticsearch/plugins \ + -d elasticsearch:7.9.2 + ``` 接下来我们就是拿浏览器访问啦。 @@ -353,198 +353,200 @@ docker run --name aurora-springboot-0.0.1.jar -d -p 8080:8080 aurora-springboot 7. 将打包好的后台代码重命名为admin, 并传输到服务器的/usr/local/vue下面 -## 11.安装并启动nginx(没有开启https) - -tip: 在这之前,需要到域名提供商那里配置好域名,个人认为没有必要开启https,http完全够,并且省事儿。当然,如果想开启https的话,后面也有相应的教程。 +## 11.安装并启动nginx -### 11.1 拉取nginx镜像 - -```shell -docker pull nginx -``` - -### 11.2 在/usr/local/nginx下创建nginx.conf文件,格式如下 - -```shell -events { - worker_connections 1024; -} - -http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - - client_max_body_size 50m; - client_body_buffer_size 10m; - client_header_timeout 1m; - client_body_timeout 1m; - - gzip on; - gzip_min_length 1k; - gzip_buffers 4 16k; - gzip_comp_level 4; - gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; - gzip_vary on; - -server { - listen 80; - server_name 前台域名; - - location / { - root /usr/local/vue/blog; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - location ^~ /api/ { - proxy_pass http://你的ip:8080/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - } - -server { - listen 80; - server_name 后台子域名; - - location / { - root /usr/local/vue/admin; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - location ^~ /api/ { - proxy_pass http://你的ip:8080/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - } - } -``` +### 方式1: http -### 11.3 启动nginx +1. 拉取nginx镜像 -```shell -docker run --name nginx --restart=always -p 80:80 -d -v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/vue:/usr/local/vue nginx -``` - -**** - -## 12.安装并启动nginx(开启https) - -### 12.1 修改配置文件 - -> 要配置https,只需要对上面的配置文件`nginx.conf`的内容作如下修改即可。 - -```bash -events { - worker_connections 1024; -} + ```shell + docker pull nginx + ``` -http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - - client_max_body_size 50m; - client_body_buffer_size 10m; - client_header_timeout 1m; - client_body_timeout 1m; - - gzip on; - gzip_min_length 1k; - gzip_buffers 4 16k; - gzip_comp_level 4; - gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; - gzip_vary on; - -server { - - listen 443 ssl; - server_name 你的前台域名(如:www.baidu.com); - - ssl on; - ssl_certificate ssl证书文件位置; - ssl_certificate_key ssl证书文件位置; - ssl_session_timeout 5m; - ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; - ssl_protocols TLSv1 TLSv1.1 TLSv1.2; - ssl_prefer_server_ciphers on; - - location / { - root /usr/local/vue/blog; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - location ^~ /api/ { - proxy_pass http://你的服务器公网IP:8080/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } +2. 在/usr/local/nginx下创建nginx.conf文件,格式如下 + ```shell + events { + worker_connections 1024; + } + + http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + + client_max_body_size 50m; + client_body_buffer_size 10m; + client_header_timeout 1m; + client_body_timeout 1m; + + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + gzip_comp_level 4; + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; + gzip_vary on; + + server { + listen 80; + server_name 前台域名; + + location / { + root /usr/local/vue/blog; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location ^~ /api/ { + proxy_pass http://你的ip:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + } + + server { + listen 80; + server_name 后台子域名; + + location / { + root /usr/local/vue/admin; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location ^~ /api/ { + proxy_pass http://你的ip:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + } } + ``` -server { +3. 启动nginx - listen 443 ssl; - server_name 你的后台域名(如admin.baidu.com); + ```shell + docker run --name nginx --restart=always -p 80:80 -d -v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/vue:/usr/local/vue nginx + ``` - ssl on; - ssl_certificate ssl证书文件位置; - ssl_certificate_key ssl文件位置; - ssl_session_timeout 5m; - ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; - ssl_protocols TLSv1 TLSv1.1 TLSv1.2; - ssl_prefer_server_ciphers on; +### 方式2: https - location / { - root /usr/local/vue/admin; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - location ^~ /api/ { - proxy_pass http://你的服务器公网IP:8080/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - } +1. 拉取nginx镜像 + ```shell + docker pull nginx + ``` +2. 修改配置文件 -server { - listen 80; - server_name 前台域名; - - rewrite ^(.*)$ https://$host$1 permanent; - - } - -server { - listen 80; - server_name 后台域名; - - rewrite ^(.*)$ https://$host$1 permanent; - - } -} -``` + ```shell + events { + worker_connections 1024; + } + + http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + + client_max_body_size 50m; + client_body_buffer_size 10m; + client_header_timeout 1m; + client_body_timeout 1m; + + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + gzip_comp_level 4; + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; + gzip_vary on; + + server { + + listen 443 ssl; + server_name 你的前台域名(如:www.baidu.com); + + ssl on; + ssl_certificate ssl证书文件位置; + ssl_certificate_key ssl证书文件位置; + ssl_session_timeout 5m; + ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_prefer_server_ciphers on; + + location / { + root /usr/local/vue/blog; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location ^~ /api/ { + proxy_pass http://你的服务器公网IP:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + } + + server { + + listen 443 ssl; + server_name 你的后台域名(如admin.baidu.com); + + ssl on; + ssl_certificate ssl证书文件位置; + ssl_certificate_key ssl文件位置; + ssl_session_timeout 5m; + ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_prefer_server_ciphers on; + + location / { + root /usr/local/vue/admin; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location ^~ /api/ { + proxy_pass http://你的服务器公网IP:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + } + + + + server { + listen 80; + server_name 前台域名; + + rewrite ^(.*)$ https://$host$1 permanent; + + } + + server { + listen 80; + server_name 后台域名; + + rewrite ^(.*)$ https://$host$1 permanent; + + } + } + ``` -### 12.2 重新运行nginx +3. 启动nginx -> 由于开启https需要启用443端口,所以在前面(非https)的基础上,下面的运行命令新增了数据卷挂载的方式并打开了443端口。 + ```shell + docker run --name nginx --restart=always -p 443:443 -p 80:80 -d -v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/cert:/etc/nginx/cert -v /usr/local/vue:/usr/local/vue --privileged=true nginx + ``` -```bash -docker run --name nginx --restart=always -p 443:443 -p 80:80 -d -v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/cert:/etc/nginx/cert -v /usr/local/vue:/usr/local/vue --privileged=true nginx -``` +