前端部署文档.md 5.3 KB
Newer Older
D
dailidong 已提交
1 2
# 前端部署文档

G
gongzijian 已提交
3 4 5 6 7 8 9 10 11
- ##### 1. 开发环境搭建

- ##### 2. 自动化部署

- ##### 3. 手动部署

- ##### 4. Liunx下使用node启动并且守护进程


G
gongzijian 已提交
12 13
### 1.开发环境搭建
   
G
gongzijian 已提交
14
- #### node安装
D
dailidong 已提交
15 16
Node包下载 (注意版本 8.9.4) `https://nodejs.org/download/release/v8.9.4/` 

G
gongzijian 已提交
17
- #### 前端项目构建
D
dailidong 已提交
18
用命令行模式 `cd`  进入 `escheduler-ui`项目目录并执行 `npm install` 拉取项目依赖包
D
dailidong 已提交
19 20 21 22 23 24 25

> 如果 `npm install` 速度非常慢 

> 可以转淘宝镜像命令行输入 `npm install -g cnpm --registry=https://registry.npm.taobao.org`

> 运行 `cnpm install` 

G
gongzijian 已提交
26 27


D
dailidong 已提交
28 29 30 31 32
> #####  !!!这里特别注意 项目如果在拉取依赖包的过程中报 " node-sass error " 错误,请在执行完后再次执行以下命令
```
npm install node-sass --unsafe-perm //单独安装node-sass依赖
```

D
dailidong 已提交
33
在项目`escheduler-ui`根目录`.env`添加代理的端口地址
D
dailidong 已提交
34
```
D
dailidong 已提交
35
# 前端代理的接口地址(例)
D
dailidong 已提交
36 37
API_BASE = http://192.168.220.204:12345

D
dailidong 已提交
38
# 如果您需要用ip访问项目可以把 "#" 号去掉(例)
D
dailidong 已提交
39 40 41 42 43 44 45 46
#DEV_HOST = 192.168.6.132
```
运行
- `npm start` 项目开发环境 (启动后访问地址 http://localhost:8888/#/)

- `npm run build` 项目打包 (打包后根目录会创建一个名为dist文件夹,用于发布线上Nginx)


G
gongzijian 已提交
47

G
gongzijian 已提交
48
### 2.自动化部署
G
gongzijian 已提交
49

G
gongzijian 已提交
50
在项目`escheduler-ui`根目录编辑安装文件`vi install(线上环境).sh`
G
gongzijian 已提交
51

G
gongzijian 已提交
52
更改前端访问端口和后端代理接口地址
G
gongzijian 已提交
53 54

```
G
gongzijian 已提交
55 56
# 配置前端访问端口
esc_proxy="8888"
G
gongzijian 已提交
57

G
gongzijian 已提交
58 59
# 配置代理后端接口
esc_proxy_port="http://192.168.220.154:12345"
G
gongzijian 已提交
60 61
```

G
gongzijian 已提交
62
前端自动部署基于`yum`操作,部署之前请先安装更新`yum
G
gongzijian 已提交
63

G
gongzijian 已提交
64 65 66
在项目`escheduler-ui`根目录执行`./install(线上环境).sh` 


G
gongzijian 已提交
67 68 69


### 3.手动部署
D
dailidong 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

安装epel源 `yum install epel-release -y`

安装Nginx `yum install nginx -y`

#### 命令

- 启用 `systemctl enable nginx`

- 重启 `systemctl restart nginx`

- 状态 `systemctl status nginx`


> ####  创建静态页面存放目录
```
mkdir /data2_4T/escheduler_front/escheduler/server
```
> ####  配置文件地址
```
G
gongzijian 已提交
90
/etc/nginx/conf.d/escheduler.conf
D
dailidong 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
```
> ####  配置信息
```
server {
    listen       8888;# 访问端口
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /data2_4T/escheduler_front/escheduler/server; # 静态文件目录
        index  index.html index.html;
    }
    location /escheduler {
        proxy_pass http://192.168.220.181:12345; # 接口地址
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header x_real_ipP $remote_addr;
        proxy_set_header remote_addr $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_connect_timeout 4s;
        proxy_read_timeout 30s;
        proxy_send_timeout 12s;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
```
> ####  重启Nginx服务
```
systemctl restart nginx
```


G
gongzijian 已提交
132
#### 前端项目发布
D
dailidong 已提交
133 134 135 136 137 138 139 140

前端在开发环境(dev)中运行 `npm run build` 命令,生成打包文件(dist)包

再拷贝到服务器 `/data2_4T/escheduler_front/escheduler/server`(服务器静态页面存放目录)

访问地址 `http://localhost:8888/#/` 


G
gongzijian 已提交
141 142 143 144 145 146 147

### 4.Liunx下使用node启动并且守护进程

安装pm2 `npm install -g pm2`

在项目`escheduler-ui`根目录执行 `pm2 start npm -- run dev` 启动项目

G
gongzijian 已提交
148 149 150 151 152 153 154 155 156 157
#### 命令

- 启用 `pm2 start npm -- run dev`

- 停止 `pm2 stop npm`

- 删除 `pm2 delete npm`

- 状态 `pm2 list`

G
gongzijian 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170
```

[root@localhost escheduler-ui]# pm2 start npm -- run dev
[PM2] Applying action restartProcessId on app [npm](ids: 0)
[PM2] [npm](0) ✓
[PM2] Process successfully started
┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬─────┬──────────┬──────┬──────────┐
│ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ cpu │ mem      │ user │ watching │
├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼─────┼──────────┼──────┼──────────┤
│ npm      │ 0  │ N/A     │ fork │ 6168 │ online │ 31      │ 0s     │ 0%  │ 5.6 MB   │ root │ disabled │
└──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴─────┴──────────┴──────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

G
gongzijian 已提交
171 172 173 174
```


## 问题
D
dailidong 已提交
175 176 177 178 179 180
####  1. 上传文件大小限制
编辑配置文件 `vi /etc/nginx/nginx.conf`
```
# 更改上传大小
client_max_body_size 1024m
```