基本配置:
python环境:python3.6.5
系统:Mac 10.14.2
已安装了docker(Mac docker安装教程网址:http://www.runoob.com/docker/macos-docker-install.html)
本机已经安装了mysql5.7
配置mysql
sudo vim /etc/mysql.cnf
修改mysql.cnf完后的配置如下
[mysqld]
[client]
default-character-set=utf8mb4
[mysqld]
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-character-set-client-handshake = true
[mysql]
default-character-set=utf8mb4
一、前端(FasterWeb)部署
1、安装Homebrew,通过brew命令安装node:brew install node
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install node
直接执行以下命令,将镜像地址改为淘宝的npm镜像地址:
npm configsetregistry https://registry.npm.taobao.org
npm configsetregistry https://registry.npm.taobao.org
2、根目录新建文件夹(任意取名这里目录为)/docker/app,拉取代码:
1.进入到/docker/app:
cd /docker/app
2.git下载代码():
git clone git@github.com:yinquanwang/FasterWeb.git
3、修改/docker/app/FasterWeb/config/index.js配置,可以用pycharm打开修改,如图:
4、修改/docker/app/FasterWeb/src/restful/api.js配置:可以用pycharm打开修改,如图
5、修改default.conf配置文件 server_name的ip, 注意为当前docker服务宿主机的ip地址!!!
6、进入FastWeb根目录执行:npm install# 安装依赖,npm run build # 生成生产环境包
cd /docker/app/FastWeb
npm install
npm run build
7、docker build -t fasterweb:latest . # 构建docker镜像
cd /docker/app/FastWeb
docker build -t fasterweb:latest .
8、 后台运行docker容器(自启动)
docker run -d --name fasterweb -p 8082:8082 --restart always fasterweb:latest
9、open url: http://localhost:8082/#/fastrunner/index
二、后端(FastRunner)部署
1、进入之前新建的目录/docker/app,然后拉取后端代码:
1.进入到/docker/app:
cd /docker/app
2.git下载代码():
git clone git@github.com:yinquanwang/FasterRunner.git
2、修改settings.py DATABASES 字典相关配置
3、 配置mysql允许远程链接:默认情况下,mysql帐号不允许从远程登陆,只能在localhost登录。(3.1和3.2任选其一)
3.1、改表法:在localhost登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,将”localhost”改成”%”
#mysql -u root -proot
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
3.2、授权法:例如: 你想myuser使用mypassword(密码)从任何主机连接到mysql服务器的话。
mysql>GRANT ALL PRIVILEGES ON . TO ‘myuser’@’%’IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
#mysql -u root -proot
mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES
4、连接数据库, 新建FasterRunner库
#mysql -u root -proot
mysql>create database FasterRunner;
5、 构建docker镜像
cd /docker/app/FasterRunner
docke build -t fasterrunner:latest .
6、后台运行docker容器(自启动)
docker run -d --name fastrunner -p 8000:8000 --restart always fasterrunner:latest
7、进入容器内部
docker exec -it fastrunner /bin/sh
8、应用数据库表
# make migrations for fastuser、fastrunner
python manage.py makemigrations fastrunner fastuser
# migrate for database
python manage.py migrate fastrunner
python manage.py migrate fastuser
9、打开:http://localhost:8082/#/fastrunner/index