Pārlūkot izejas kodu

重新梳理手动安装文档

James Iter 8 gadi atpakaļ
vecāks
revīzija
6c464d2c58
3 mainītis faili ar 117 papildinājumiem un 0 dzēšanām
  1. 76 0
      docs/install.md
  2. 18 0
      misc/sync_hosts_file.sh
  3. 23 0
      misc/sync_ssh_key_pair.sh

+ 76 - 0
docs/install.md

@@ -6,6 +6,12 @@
 - [声明全局变量](#声明全局变量)
 - [安装必要软件](#安装必要软件)
 - [开启 NTP 同步](#开启-ntp-同步)
+- [配置 `/etc/hosts` 文件](#配置-etchosts-文件)
+- [服务器间实现SSH-KEY互通(为热迁移做铺垫)](#服务器间实现ssh-key互通为热迁移做铺垫)
+    - [生成空密码 RSA 密钥对](#生成空密码-rsa-密钥对)
+    - [生成与密钥对适配的 `~/.ssh/authorized_keys` 文件](#生成与密钥对适配的-sshauthorized-keys-文件)
+    - [复制 `~/.ssh` 目录到集群中的其它计算节点上](#复制-ssh-目录到集群中的其它计算节点上)
+- [同步 `/etc/hosts` 文件](#同步-etchosts-文件)
 - [清理环境](#清理环境)
 - [部署 MariaDB](#部署-mariadb)
 - [部署 Redis](#部署-redis)
@@ -18,6 +24,7 @@
 - [修改配置文件](#修改配置文件)
 - [启动服务](#启动服务)
 - [部署 Nginx](#部署-nginx)
+- [测试 JimV-C 是否安装成功](#测试-jimv-c-是否安装成功)
 
 
 ## 声明全局变量
@@ -28,6 +35,8 @@ export JIMVC_REPOSITORY_URL='https://raw.githubusercontent.com/jamesiter/JimV-C'
 export EDITION='master'
 export NGINX_JIMV_URL=${JIMVC_REPOSITORY_URL}'/'${EDITION}'/misc/nginx_jimv.conf'
 export GENERATE_PASSWORD_SCRIPT_TMP_PATH='/tmp/gen_pswd.sh'
+export SYNC_SSH_KEY_PAIR_SCRIPT_PATH='/usr/sbin/sync_ssh_key_pair.sh'
+export SYNC_HOSTS_FILE_SCRIPT_PATH='/usr/sbin/sync_hosts_file.sh'
 export SMTP_HOST=''
 export SMTP_USER=''
 export SMTP_PASSWORD=''
@@ -44,6 +53,7 @@ export SECRET_KEY=`${GENERATE_PASSWORD_SCRIPT_TMP_PATH} 128`
 rm -f ${GENERATE_PASSWORD_SCRIPT_TMP_PATH}
 ```
 
+
 ## 安装必要软件
 
 ``` bash
@@ -52,6 +62,7 @@ pip install --upgrade pip -i ${PYPI}
 pip install virtualenv -i ${PYPI}
 ```
 
+
 ## 开启 NTP 同步
 
 ``` bash
@@ -60,6 +71,57 @@ timedatectl set-ntp true
 timedatectl status
 ```
 
+
+## 配置 `/etc/hosts` 文件
+
+``` text
+127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
+::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
+192.168.2.253    jimvc.jimv.io
+192.168.2.221    10k01.jimv.io
+192.168.2.222    10k02.jimv.io
+192.168.2.223    10k03.jimv.io
+192.168.2.224    10k04.jimv.io
+```
+
+
+## 服务器间实现SSH-KEY互通(为热迁移做铺垫)
+
+### 生成空密码 RSA 密钥对
+
+``` bash
+# 生成空密码的SSH使用的密钥对
+# 一路回车
+ssh-keygen
+```
+
+### 生成与密钥对适配的 `~/.ssh/authorized_keys` 文件
+
+``` bash
+# 接下来将会把包含 authorized_keys 文件的 ~/.ssh 目录复制到其它计算节点上
+ssh-copy-id localhost
+```
+
+### 复制 `~/.ssh` 目录到集群中的其它计算节点上
+
+``` bash
+curl ${JIMVC_REPOSITORY_URL}'/'${EDITION}'/misc/sync_ssh_key_pair.sh' -o ${SYNC_SSH_KEY_PAIR_SCRIPT_PATH}
+chmod +x ${SYNC_SSH_KEY_PAIR_SCRIPT_PATH}
+${SYNC_SSH_KEY_PAIR_SCRIPT_PATH}
+```
+
+
+## 同步 `/etc/hosts` 文件
+
+> `注意:` 每次有新的节点加入进来,都需要同步一次该文件
+
+``` bash
+curl ${JIMVC_REPOSITORY_URL}'/'${EDITION}'/misc/sync_hosts_file.sh' -o ${SYNC_HOSTS_FILE_SCRIPT_PATH}
+chmod +x ${SYNC_HOSTS_FILE_SCRIPT_PATH}
+${SYNC_HOSTS_FILE_SCRIPT_PATH}
+```
+
+
 ## 清理环境
 
 ``` bash
@@ -73,6 +135,7 @@ sed -i 's@SELINUX=enforcing@SELINUX=disabled@g' /etc/selinux/config
 setenforce 0
 ```
 
+
 ## 部署 MariaDB
 
 ``` bash
@@ -111,6 +174,7 @@ EOF
 mysql -u root -p${RDB_ROOT_PSWD} -e 'show databases'
 ```
 
+
 ## 部署 Redis
 
 ``` bash
@@ -130,24 +194,28 @@ systemctl enable redis.service
 systemctl start redis.service
 ```
 
+
 ## 创建 Web 用户
 
 ```bash
 useradd -m www
 ```
 
+
 ## 创建站点发布目录
 
 ```bash
 su - www -c "mkdir ~/sites"
 ```
 
+
 ## 克隆 JimV-C 项目
 
 ```bash
 su - www -c "git clone https://github.com/jamesiter/JimV-C.git ~/sites/JimV-C"
 ```
 
+
 ## 安装所需库
 
 ```bash
@@ -164,6 +232,7 @@ su - www -c "echo '. ~/venv/bin/activate' >> .bashrc"
 su - www -c "pip install -r ~/sites/JimV-C/requirements.txt -i ${PYPI}"
 ```
 
+
 ## 适配 www 用户权限
 
 ``` bash
@@ -174,6 +243,7 @@ mkdir -p /run/jimv
 chown www.www /run/jimv
 ```
 
+
 ## 初始化JimV MySQL数据库
 
 ```bash
@@ -185,6 +255,7 @@ su - www -c "mysql -u jimv -p${RDB_JIMV_PSWD} < ~/sites/JimV-C/misc/init.sql"
 mysql -u jimv -p${RDB_JIMV_PSWD} -e 'show databases'
 ```
 
+
 ## 修改配置文件
 
 配置文件的默认读取路径:`/etc/jimvc.conf`
@@ -231,6 +302,7 @@ sed -i "s/\"smtp_password\".*$/\"smtp_password\": \"${SMTP_PASSWORD}\",/" /etc/j
 /home/www/sites/JimV-C/startup.sh
 ```
 
+
 ## 部署 Nginx
 
 ``` bash
@@ -249,3 +321,7 @@ systemctl enable nginx.service
 systemctl start nginx.service
 ```
 
+
+## 测试 JimV-C 是否安装成功
+
+> 通过浏览器打开 JimV-C 地址。如果展现出初始化页面,则表示安装成功。

+ 18 - 0
misc/sync_hosts_file.sh

@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+#
+# JimV-C
+#
+# Copyright (C) 2017 JimV <james.iter.cn@gmail.com>
+#
+# Author: James Iter <james.iter.cn@gmail.com>
+#
+#  Sync the /etc/hosts file.
+#
+
+DHOSTS=`egrep -v '^$|localhost|jimvc' /etc/hosts | awk '{ print $1; }'`
+
+for dhost in ${DHOSTS}
+do
+    scp /etc/hosts ${dhost}:/etc/hosts
+done
+

+ 23 - 0
misc/sync_ssh_key_pair.sh

@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+#
+# JimV-C
+#
+# Copyright (C) 2017 JimV <james.iter.cn@gmail.com>
+#
+# Author: James Iter <james.iter.cn@gmail.com>
+#
+#  Sync the key pair of ssh.
+#
+
+# 关闭 SSH 服务器端 Key 校验
+sed -i 's@.*StrictHostKeyChecking.*@StrictHostKeyChecking no@' /etc/ssh/ssh_config
+
+DHOSTS=`egrep -v '^$|localhost|jimvc' /etc/hosts | awk '{ print $1; }'`
+
+for dhost in ${DHOSTS}
+do
+    scp -r ~/.ssh ${dhost}:~/
+    # 关闭 SSH 服务器端 Key 校验
+    ssh ${dhost} "sed -i 's@.*StrictHostKeyChecking.*@StrictHostKeyChecking no@' /etc/ssh/ssh_config"
+done
+