项目上线

我们在上线项目之前我们需要先进行服务器的购买,可以选择阿里云的服务器,有余裕的小伙伴还可以申请一个域名,再此不一一赘述,只讲上线部分。

连接服务器

我们使用xshell去连接我们的服务器,选择阿里云服务器的直接去阿里的控制台查看自己的服务器ip即可

更新软件包以及常用工具包

1
2
3
yum update -y
yum -y groupinstall "Development tools"
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel

安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1)前往用户根目录
cd ~

2)下载mysql57
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

3)安装mysql57
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server

4)启动mysql57并查看启动状态
systemctl start mysqld.service
systemctl status mysqld.service

5)查看默认密码并登录
grep "password" /var/log/mysqld.log
mysql -uroot -p

6)修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

安装Redis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
1)前往用户根目录
cd ~

2)下载redis-5.0.5
wget http://download.redis.io/releases/redis-5.0.5.tar.gz

3)解压安装包
tar -xf redis-5.0.5.tar.gz

4)进入目标文件
cd redis-5.0.5

5)编译环境
make&&make install

6)复制环境到指定路径完成安装
cp -r ~/redis-5.0.5 /usr/local/redis

7)配置redis可以后台启动:修改下方内容
vim /usr/local/redis/redis.conf

daemonize yes

8)建立软连接
ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server
>: ln -s /usr/local/redis/src/redis-cli /usr/bin/redis-cli

9)后台运行redis
cd /usr/local/redis
redis-server ./redis.conf &

10)测试redis环境
redis-cli

11)关闭redis服务
pkill -f redis -9

安装python3.6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1)前往用户根目录
cd ~

2)下载 或 上传 Python3.6.7
# 服务器终端
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz

3)解压安装包
tar -xf Python-3.6.7.tar.xz

4)进入目标文件
cd Python-3.6.7

5)配置安装路径:/usr/local/python3
./configure --prefix=/usr/local/python3

6)编译并安装
make && make install

7)建立软连接:终端命令 python3,pip3
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3

配置阿里源(阿里云服务器不用配置)

1
2
3
4
5
6
7
8
9
10
11
12
1)创建pip配置路径
mkdir ~/.pip

2)进入目录编辑配置文件:填入下方内容
cd ~/.pip && vim pip.conf

[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com

安装uwsgi(虚拟环境还需要安装一次)

1
2
3
4
5
1)在真实环境下安装
pip3 install uwsgi

2)建立软连接
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

安装虚拟环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1)安装依赖
pip3 install virtualenv
pip3 install virtualenvwrapper

2)建立虚拟环境软连接
ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv

3)配置虚拟环境:填入下方内容
vim ~/.bash_profile

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/python3/bin/virtualenvwrapper.sh

4)更新配置文件内容
source ~/.bash_profile

5)虚拟环境默认根目录:~/.virtualenvs

安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1)前往用户根目录
cd ~

2)下载nginx1.13.7
wget http://nginx.org/download/nginx-1.13.7.tar.gz

3)解压安装包
tar -xf nginx-1.13.7.tar.gz

4)进入目标文件
cd nginx-1.13.7

5)配置安装路径:/usr/local/nginx
./configure --prefix=/usr/local/nginx

6)编译并安装
make && sudo make install

7)建立软连接:终端命令 nginx
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

9)测试Nginx环境,服务器运行nginx,本地访问服务器ip
nginx启动命令:nginx即可

Nginx常用命令

1
2
3
4
5
6
7
8
9
10
11
12
1)启动
nginx

2)关闭nginx
nginx -s stop

3)重启nginx
nginx -s reload

4)查看端口,强行关闭
ps -aux|grep nginx
kill <pid:进程编号>

前端项目上线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
1.首先我们进入我们的前端vue项目,将settings.js中的base_url修改成服务器的地址
export default {
base_url: 'xx.107.250.120:8000',
}

2.然后执行命令
npm run build

3.然后你会发现我们在根目录下生成了一个dist文件夹,我们将这个文件夹压缩上传到服务器,没有安装lrzsz的需要安装否则无法上传
yum install lrzsz

4.我们解压这个文件夹
unzip dist.zip

5.去nginx进行配置
cd /usr/local/nginx/conf
mv nginx.conf nginx.conf.bak
vim nginx.conf

6.填入下述内容
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name 127.0.0.1; # 改为自己的域名,没域名修改为127.0.0.1:80
charset utf-8;
location / {
root /home/html; # html访问路径
index index.html; # html文件名称
try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题
}
}
}

7.重启nginx
nginx -s reload