# cool-ai 的生产环境部署
本次案例使用的是阿里云的 ECS 云主机,使用域名 "alidev.lidong.xin" 及"*.alidev.lidong.xin"
Cool-AI 官方文档 (opens new window)
# 服务器环境初始化配置
# 配置免密登录
判断本地是否存在密钥
cat ~/.ssh/id_rsa.pub
如提示文件不存在或显示内容为空,说明本地尚未生成密钥或密钥有问题。
使用 ssh-keygen
命令生成密钥
将本地公钥配置到远程服务器
ssh-copy-id root@alidev.lidong.xin
登录测试
ssh root@alidev.lidong.xin
# 安装宝塔面板
宝塔面板官方地址 http://www.bt.cn (opens new window)
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
得到类似下面的结果,找个安全的地方记录下来。
==================================================================
Congratulations! Installed successfully!
==================================================================
外网面板地址: http://39.99.235.55:8888/8e35b5e7
内网面板地址: http://172.26.213.112:8888/8e35b5e7
username: 2lzrmtte
password: ee60a5f6
If you cannot access the panel,
release the following panel port [8888] in the security group
若无法访问面板,请检查防火墙/安全组是否有放行面板[8888]端口
==================================================================
# 安装 Docker
安装 Docker Compose
https://docs.docker.com/compose/install/
https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)
https://github.com/docker/compose/releases/download/1.26.2/docker-compose-Linux-x86_64
scp ./docker-compose-Linux-x86_64 root@alidev.lidong.xin:/usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
配了个中转镜像,可以使用以下命令安装Docker Compose
v1.26.2
sudo curl -L "https://cdn.jsdelivr.net/gh/GCSLaoLi/mirrors/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
# 升级 GIT
yum remove git -y
yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install git224 -y
# 自动化部署
服务端 webhook
echo "-------------------------任务开始-----------------------------"
echo "$(date +'%Y-%m-%d %H:%M:%S')|$1开始调用接口"
cd docker-compose.yml所在目录
pwd
docker-compose -f "docker-compose.yml" up -d --build
echo "$(date +'%Y-%m-%d %H:%M:%S')|$1调用接口执行完毕"
echo "-------------------------任务结束-----------------------------"
项目 package.json,配置常用命令及脚本。
"scripts": {
"vue:deploy": "cd ./vue && ./deploy.sh",
"production:deploy": "./deploy.sh"
},
./deploy.sh
#!/usr/bin/env sh
# 确保脚本抛出遇到的错误
set -e
#回显一下当前目录
cd ./
pwd
echo "$(date +'%Y-%m-%d %H:%M:%S')|开始到生产环境部署"
res=$(curl webhook地址)
echo ‘---------------------’
echo $res
if [ "$res" == '{"code": 1}' ];then
echo "$(date +'%Y-%m-%d %H:%M:%S')|生产环境部署请求已接受."
else
echo "$(date +'%Y-%m-%d %H:%M:%S')|部署请求未收到正常回应,请检查配置!"
fi
cd -
# swarm 集群
实例网段:172.26.0.0/16
需放行端口
The following ports must be available. On some systems, these ports are open by default.
TCP port 2377 for cluster management communications
TCP and UDP port 7946 for communication among nodes
UDP port 4789 for overlay network traffic
管理节点执行
docker swarm init --advertise-addr 172.26.213.112
得到类似结果
Swarm initialized: current node (csml4y09rjncbrphmgckqa7nr) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-43xr8it7aynfi73j2q2fics7mhczlk34hzkfunidgvf7jp8d3p-eumg00ibt7lsh4s8ltk9aulv9 172.26.213.112:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.