项目上线

一.nginx的作用

1.做静态页展示的web服务
2.nginx做负载均衡
    四层
    七层
3.反向代理

注意:nginx 不可以直接连接数据库,在nginx1.9.x 之前,不支持四层负载,stream模块.

二.源码安装nginx

前期准备:
先删除所有的服务器的源
[root@db01 ~]# cd yum.repos.d
[root@db01 yum.repos.d]# rm ./*

这里只需要两个服务器源
[root@db01 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
[root@db01 yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 

安装所需的依赖包
[root@db01 yum.repos.d]# yum install -y pcre-devel autoconf openssl-devel

源码安装
1)解压
2)生成 (make file)cmake     ./configure --prefix=/usr/local/nginx
3)编译 make
4)安装 make install

安装过程
1)解压nginx
[root@db01 ~]# tar xf nginx-1.10.3.tar.gz

2)进入nginx目录,并查看
[root@db01 ~]# cd nginx-1.10.3
[root@db01 nginx-1.10.3]# ll
total 672
drwxr-xr-x. 6 1001 1001   4096 May 13 09:04 auto
-rw-r--r--. 1 1001 1001 265299 Jan 31  2017 CHANGES
-rw-r--r--. 1 1001 1001 404694 Jan 31  2017 CHANGES.ru
drwxr-xr-x. 2 1001 1001    168 May 13 09:04 conf
-rwxr-xr-x. 1 1001 1001   2481 Jan 31  2017 configure
drwxr-xr-x. 4 1001 1001     72 May 13 09:04 contrib
drwxr-xr-x. 2 1001 1001     40 May 13 09:04 html
-rw-r--r--. 1 1001 1001   1397 Jan 31  2017 LICENSE
drwxr-xr-x. 2 1001 1001     21 May 13 09:04 man
-rw-r--r--. 1 1001 1001     49 Jan 31  2017 README
drwxr-xr-x. 9 1001 1001     91 May 13 09:04 src

3)创建nginx用户
[root@db01 nginx-1.10.3]# useradd nginx -s /sbin/nologin -M

4)生成make file
[root@db01 nginx-1.10.3]# ./configure  \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx-1.10.3/ \
--with-http_stub_status_module  \
--with-http_ssl_module --with-stream

5)编译 && 安装
[root@db01 nginx-1.10.3]# make && make install
[root@db01 nginx-1.10.3]# echo $?
0表示执行成功

6)做软连接
[root@db01 ~]# ln -s /usr/local/nginx-1.10.3 /usr/local/nginx

[root@db01 ~]# ll /usr/local/nginx/
total 4
drwxr-xr-x. 2 root root 4096 May 13 09:13 conf
drwxr-xr-x. 2 root root   40 May 13 09:13 html
drwxr-xr-x. 2 root root    6 May 13 09:13 logs
drwxr-xr-x. 2 root root   19 May 13 09:13

7)检测nginx语法
[root@db01 ~]# cd /usr/local/nginx/conf/
[root@db01 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.3//conf/nginx.conf test is successful

8)启动nginx
[root@db01 conf]# /usr/local/nginx/sbin/nginx

9)检查nginx的端口
[root@db01 conf]# netstat -lntup|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      61777/nginx: master 

10)重新加载
[root@db01 conf]# /usr/local/nginx/sbin/nginx -t 
[root@db01 conf]# /usr/local/nginx/sbin/nginx  -s reload

11)简化nginx配置文件
[root@db01 conf]# grep -Ev "#|^$" nginx.conf.default  > nginx.conf

12)创建conf.d目录
[root@db01 conf]# mkdir /usr/local/nginx/conf/conf.d

13)编辑虚拟主机
[root@db01 conf.d]# vim www.oldboy.com.conf
server {
    listen       80;
    server_name  www.oldboy.com;
    location / {
        root   html; #站点目录的根目录位置
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}

什么叫站点目录? 前端代码存放的目录

14)创建站点目录
[root@db01 html]# mkdir /code

15)上传代码
以h5_games.zip为例
将h5_games.zip拖入code目录
解压
unzip h5_games.zip

可以将本地连接改为www.oldboy.com
windows+R
drivers
打开etc
打开hosts
添加 10.0.0.51 www.oldboy.com 

16)优化404界面
[root@db01 code]# vim 40x.html
<img style='width:100%;height:100%;' src=https://www.driverzeng.com/zenglaoshi/404_page.png>
[root@db01 code]# mv 40x.html h5_games

[root@db01 conf.d]# vim www.oldboy.com.conf
server {
    listen       80;
    server_name  www.oldboy.com 

;
    location / {
        root   /code/h5_games/;
        index  index.html index.htm;
    }
        error_page 400 403 404 405 /40x.html;
}


17)重新加载nginx [root@db01 code]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx-1.10.3//conf/nginx.conf test is successful [root@db01 code]# /usr/local/nginx/sbin/nginx -s reload

三.nginx部署路飞学城

下载代码
下载到opt下面
[root@db01 ~]# wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip 
[root@db01 ~]# wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip 

部署前端vue

1)下载node
wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz

2)解压
[root@db01 opt]# tar xf node-v8.6.0-linux-x64.tar.gz

3)移动目录
[root@db01 opt]# mv node-v8.6.0-linux-x64 /usr/local/node-8.6.0

4)做软连接
ln -s /usr/local/node-8.6.0 /usr/local/node

5)进入node目录,查看bin目录
[root@db01 opt]# cd /usr/local/node
[root@db01 node]# ll bin/
total 36264
-rwxrwxr-x. 1 500 500 37133148 Sep 27  2017 node
lrwxrwxrwx. 1 500 500       38 Sep 27  2017 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx. 1 500 500       38 Sep 27  2017 npx -> ../lib/node_modules/npm/bin/npx-cli.js

6)添加环境变量
[root@db01 node]# vim /etc/profile.d/node.sh
export PATH="/usr/local/node/bin:$PATH"

7)加载环境变量
[root@db01 node]# source /etc/profile

8)检测node和npm版本
[root@db01 node]# npm -v
5.3.0
[root@db01 node]# node -v
v8.6.0

9)解压vue代码
[root@db01 opt]# unzip 07-luffy_project_01.zip 

10)进入代码目录,安装package.json中的模块
[root@db01 opt]# cd 07-luffy_project_01
[root@db01 07-luffy_project_01]# npm install

11)更改js文件中的IP
 sed -i 's#127.0.0.1#10.0.0.51#g' /opt/07-luffy_project_01/src/restful/api.js

12)生成静态文件目录
npm run build

13)编辑 nginx配置文件,创建一个虚拟主机
[root@db01 dist]# vim /usr/local/nginx/conf/conf.d/www.luffy.com.conf

server {
    listen       80;
    server_name  www.luffy.com;
    location / {
        root   /opt/07-luffy_project_01/dist;
        index  index.html index.htm;
    }
    error_page 400 403 404 405 /40x.html;
}

14)配置hosts解析
10.0.0.51 www.luffy.com

15)重新加载nginx
[root@db01 dist]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.3//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.3//conf/nginx.conf test is successful
[root@db01 dist]# /usr/local/nginx/sbin/nginx -s reload

四.源码安装python3.6环境

1)下载
[root@db01 ~]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

2)解压
[root@db01 ~]# tar xf Python-3.6.4.tgz

3)进入python3目录
[root@db01 ~]# cd Python-3.6.4

4)生成make file
./configure --prefix=/usr/local/python3.6.4 --with-ssl

5)编译 && 安装
[root@db01 Python-3.6.4]# make && make install

6)直接输入python3可以进入python3.6.4
[root@db01 python3.6.4]# vim /etc/profile.d/python.sh 
export PATH="/usr/local/python3.6.4/bin:$PATH"
[root@db01 python3.6.4]# source /etc/profile
[root@db01 ~]# python3

7)编辑python需要安装的库文件
[root@db01 ~]# cd /opt/
[root@db01 opt]# vim requirements.txt
certifi==2018.11.29
chardet==3.0.4
crypto==1.4.1
Django==2.1.4
django-redis==4.10.0
django-rest-framework==0.1.0
djangorestframework==3.9.0
idna==2.8
Naked==0.1.31
pycrypto==2.6.1
pytz==2018.7
PyYAML==3.13
redis==3.0.1
requests==2.21.0
shellescape==3.4.1
urllib3==1.24.1
uWSGI==2.0.17.1

8)安装库文件
[root@db01 opt]# pip3 install -r requirements.txt

9)解压后端代码
[root@db01 opt]# unzip luffy_boy.zip

10)编辑uwsgi文件
[root@db01 opt]# vim /opt/uwsgi.ini 
[uwsgi]

Django-related settings

the base directory (full path)

chdir           = /opt/luffy_boy

Django's wsgi file

module          = boy.wsgi

the virtualenv (full path)

home            = /usr/local/python3.6.4

process-related settings

master

master          = true

maximum number of worker processes

processes       = 100

the socket (use the full path to be safe

socket          = 0.0.0.0:8888

clear environment on exit

vacuum          = true

10)启动uwsgi
[root@db01 opt]# uwsgi --ini /opt/uwsgi.ini &

绝对路径:
/usr/local/python3.6.4/bin/uwsgi --ini /opt/uwsgi.ini &

检测是否启动成功:
打开浏览器,访问:10.0.0.51:8888

 

posted @ 2019-06-05 08:55  Zhuang_Z  阅读(212)  评论(0)    收藏  举报