centos6部署django+mysql+vue

2021-02-28  本文已影响0人  望月成三人

CentOS6使用yum安装服务报错

Loaded plugins: fastestmirror, security
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
sed -i.old -e 's/^mirrorlist/#mirrorlist/g' -e 's/^#baseurl=http:\/\/mirror.centos.org\/centos\/$releasever\//baseurl=http:\/\/vault.centos.org\/centos\/6\//g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all

安装xz

 yum install xz

安装python3

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
cd /usr/bin
mv python python.bak
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar -xvJf Python-3.6.3.tar.xz
# 当然,如果用其他格式的,比如
# wget  https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
# tar  zxvf ....python
cd Python3.6.3
./configure prefix=/usr/local/python3
make && make install
rm /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
sudo vi /usr/bin/yum
#将第一行指定的python版本改为python2
#!/usr/bin/python 改为 #!/usr/bin/python2
wget --no-check-certificate https://files.pythonhosted.org/packages/b7/2d/ad02de84a4c9fd3b1958dc9fb72764de1aa2605a9d7e943837be6ad82337/pip-21.0.1.tar.gz

tar -zxvf pip-xxx.tar.gz 
cd pip-xxx 
python3 setup.py build 
python3 setup.py install

ln /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 install PyMySQL
pip3 django

安装myql

wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm

[root@racknerd-4dbd89 home]# yum repolist enabled | grep mysql.
mysql-connectors-community MySQL Connectors Community                        185
mysql-tools-community      MySQL Tools Community                             123
mysql57-community          MySQL 5.7 Community Server                        484
[root@racknerd-4dbd89 home]#

service mysqld start
grep 'temporary password' /var/log/mysqld.log

update mysql.user set authentication_string=password('~11111) where user='root';
flush privileges;
show databases;
use mysql;
show tables;
select Host, User,authentication_string9 from user;
 update user set Host='%' where User='root';  
# 说明: % 代表任意的客户端,可替换成具体IP地址。
最后刷新一下:flush privileges;
vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

/etc/init.d/iptables restart

下载配置项目

安装项目依赖文件

pip install pipreqs
pipreqs --use-local --encoding=utf8 --force .

pip install django-cors-headers

mysql -uroot -p
create database if not exists mydb default character set utf8 collate utf8_general_ci;
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8000
ile "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 67, in check_sqlite_version
    raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

def check_sqlite_version():
    if Database.sqlite_version_info < (3, 8, 3):
        raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)


def check_sqlite_version():
    if Database.sqlite_version_info < (3, 7, 17):
        raise ImproperlyConfigured('SQLite 3.7.17 or later is required (found %s).' % Database.sqlite_version)

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8000 -j ACCEPT
# 重启
service iptables restart 
# 后台启动django服务,输出日志到日志文件中,内容为标准输出和标准错误
MYDATE=`date +%Y%m%d`
ALL_LOGFILE=/data/wwwroot/TestPaltForm/log/log_$MYDATE

nohup python3 manage.py runserver 0.0.0.0:8000 > ${ALL_LOGFILE} 2>&1 &
netstat -lnp | grep "8000"
kill 5014 #查找到进程后,再用结束进程

部署vue

node pm2 环境配置

sudo wget https://nodejs.org/dist/latest-v8.x/node-v8.17.0-linux-x64.tar.xz
//解压到当前目录
sudo tar -xvf node-v8.17.0.tar.xz
// 执行是否安装成功
cd node-v8.17.0/bin/ && ls #
# 有node 和 npm
[root@racknerd-4dbd89 bin]# ./node
-bash: .... libstdc++.so.6
# 执行安装即可
yum whatprovides libstdc++.so.6
ln -s /home/node-v8.17.0-linux-x64/bin/node /usr/local/bin/node
ln -s /home/node-v8.17.0-linux-x64/bin/np /usr/local/bin/node
运行node -v,npm -v查看版本,正确则node npm环境无误

安装全局pm2

npm install pm2 -g
# 创建软连接
ln -s /home/node-v8.17.0-linux-x64/bin/pm2 /usr/local/bin/pm2

vue项目配置

打包

编写node启动脚本

// app.js
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();

app.use(express.static(path.resolve(__dirname, './dist')))

app.get('*', function(req, res) {
    const html = fs.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf-8')
    res.send(html)
})

app.listen(8002);

生成package.json文件

// package.json
{
  "name": "back_manage",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.3"
  }
}

文件上传

服务启动

登陆到你的服务端,cd到项目文件夹,使用pm2 start app.js就成功启动服务了

image.png
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8002 -j ACCEPT
# 重启
service iptables restart 
image.png

参考

上一篇下一篇

猜你喜欢

热点阅读