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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| # === # 生成 ssh-key # ===
# Mac 用户直接打开终端输入命令 # Win 用户安装 Github Desktop 离线包后, 打开桌面的 git shell 程序, 在里面输入下面的命令 # # 1. 在本机生成 ssh key 公钥私钥 # 注意 下面的 mykey 随便换一个你喜欢的名字, 这是一个标注, 方便你看的 ssh-keygen -C mykey # 会提示你生成的文件的地址, 并且让你输入密码, 你不要输入密码, 直接回车 # # 这样你就得到了一对 ssh-key, 这是用于登录服务器用的 # 默认你会得到两个文件 # id_rsa 是私钥 自己保存 不要给别人看 # id_rsa.pub 是公钥, 是要到处使用的
# === # 重建服务器并且配置 ssh-key # === # # 去 vultr 的管理界面 # 先删除(Destory)现有的服务器 # 新建服务器的时候, 把刚才才生成的 id_rsa.pub 文件(用 atom/pycharm 可以打开)里面的内容加入到 ssh-key 步骤中 # 这样你就可以不用密码, 自动登录服务器了(windows 用户请看「windows上用bitvise软件使用sshkey登录.pdf」这个文件)
# 如果你不想重建服务器, 配置 ssh-key 的方法如下 # 在服务器把本机生成的 public key 添加到 /root/.ssh/authorized_keys 文件中 # 1 用 root 用户登录到服务器, 创建 .ssh 目录 cd /root mkdir .ssh # 2 编辑 authorized_keys 文件, 把刚才生成的 id_rsa.pub 文件里面的内容粘贴进去并保存退出 # 注意, 这里可以粘贴多个 key, 一行一个 nano .ssh/authorized_keys
# 在本机上可用git bash尝试 # ssh root@ipaddress||domain # 注意 Are you sure you want to continue connecting (yes/no)? # 要回答 yes
# 本机使用Bitvise, 点击Client key manager # import, 点击all文件,找到id_rsa私钥,导入后关闭 # initial method: publickey 选择刚刚生成的文件 # 登录成功
# === # 服务器初始化配置, 复制这些命令粘贴到服务器终端中执行 # === # # 安装 配置 打开 ufw 防火墙 apt-get install ufw ufw allow 22 ufw allow 80 ufw allow 443 ufw default deny incoming ufw default allow outgoing ufw status verbose ufw enable
# 安装必备软件 apt-get install git python3 python3-pip python3-setuptools supervisor mongodb redis-server zsh # 安装 oh-my-zsh 配置(方便你使用命令行的配置) wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh # 安装 gunicorn pip3 install gunicorn pymongo
# === # 服务器中文编码问题 # === # # 编辑下面的文件, 不要拼错 nano /etc/environment # 加入下面的内容, 保存退出 LC_CTYPE="en_US.UTF-8" LC_ALL="en_US.UTF-8"
=== gunicorn wsgi --bind 0.0.0.0:2000 ===
#!/usr/bin/env python3 这是把代码部署到 apache gunicorn nginx 后面的套路
➜ ~ cat /etc/supervisor/conf.d/xx.conf supervisor监护程序,重启、崩溃后自动重启 [program:todo] command=/usr/local/bin/gunicorn wsgi --bind 0.0.0.0:2000 --pid /tmp/todo.pid directory=/root/web13 autostart=true
可以使用 supervisorctl restart todo
|