iTranswarp 部署记录

作者:DeppWang原文地址

目的:使用 iTranswarp 学习 nginx 配置

如果你只想本地启动,直接修改 ip,使用 docker-compose 即可

Google Cloud Platform 配置

本地部署耗资源,服务器部署

腾讯云 clone GitHub 项目太慢,使用 Google Cloud Platform,招商银行国际信用卡注册

Compute Engine 新建「虚拟机实例」 CentOS7

实例配置(防火墙)入站端口

0.0.0.0/0 tcp:13306,16379,443,80

「元数据」添加公钥 id_rsa.pub,使用 SSH 公钥登录,原理请看SSH 原理与运用(一):远程登录

ssh -i ~/.ssh/id_rsa(私钥) your_user_name@ip

ssh -i ~/.ssh/id_rsa_4 [email protected] # 示例

安装 Git、配置别名

sudo yum install git-core
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.unstage 'reset HEAD'
git config --global alias.last 'log -1'
git config --global alias.lg "log --color --graph --pretty=format:'% Cred% h% Creset -% C(yellow)% d% Creset % s % Cgreen(% cr) % C(bold blue)<% an>% Creset' --abbrev-commit"

切换为 ohmyzsh(个人习惯)

sudo yum update && sudo yum -y install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# 切换 zsh 失败时,重新切换
sudo chsh -s /bin/zsh your_user_name
echo $SHELL
  • 可能需要输入用户密码,用户密码为 Google 账号密码
  • 未生效时重启实例,重启 ip 会变!

语言设置为英文(默认就是英文,为何 Git 显示中文)

localectl

安装 DockerDocker 教程

安装 Docker-ComposeDocker-Compose 教程

重启实例,ip 会变!需要重启 docker daemon

sudo service docker start

服务器运行项目

先 fork 项目

$ git clone https://github.com/your-name/itranswarp.git # 使用 HTTPS
$ cd itranswarp
$ cd docker
$ cp .env.example .env
$ vim .env # 修改为服务器公网 ip
$ docker-compose up # 启动
$ docker-compose stop # 停止

修改服务器 hosts,相当于 DNS

vim /etc/hosts

使用 lynx 模拟服务器本地浏览器打开 https://www.local.itranswarp.com/

sudo yum install lynx
lynx https://www.local.itranswarp.com/

远程连接 Redis

# 远程连接
redis-cli -h XXX.XXX.XXX.XXX(ip) -p port -a password
redis-cli -h ip -p 16379 -a JFPRJ

远程连接 Mysql 使用 Navicat Premium

进入容器

docker container exec -it [containerId] /bin/bash # 启动容器实例 bash
or
docker exec -it [containerId] /bin/bash

使用自定义域名

配置域名解析

(例:万网)配置域名解析

A www.xingquan.wang ip
A static.xingquan.wang ip
A source.xingquan.wang ip
A @xingquan.wang ip

申请数字证书

freessl 申请免费数字证书

www.xingquan.wang
static.xingquan.wang
source.xingquan.wang
xingquan.wang

可四个域名同时申请同一个数字证书,也可分开申请

离线申请,使用 KeyManager,最后「导出证书」,解压可得到两个文件:**.crt,**.key。crt 为数字证书,key 为服务器私钥,深入理解请看一个故事讲完 https

修改项目配置文件

clone fork 项目到本地,(切换分支)修改配置。

全局将 local.itranswarp.com 修改为你的域名(如:xingquan.wang)

修改 local.itranswarp.com.crt / local.itranswarp.com.key 为 xingquan.wang.crt、xingquan.wang.key,使用「导出证书」的 crt、key 替换。local-conf 文件夹下可不修改

修改配置后,只重启 docker-compose(容器),配置是否生效?生效

效果

https://www.xingquan.wang

总结

学习到

  • HTTPS、证书
  • nginx 配置

问题:

  • Docker 如何进入容器操作,如查看日志、修改数据库
  • iTranswarp 作为博客,没有订阅地址?

admin 默认密码为 123456

评论默认使用 ,你也可以切换到 来留言。