0%

linux&&nginx架构

linux

linux指令

/是最高级目录,目录树的根节点

~是/root,为目录树根节点的子节点之一

cd .. 返回上级

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
ls / -a 

ls / -l

ls / -al



cat

cat -A test.sh

head

tail

tac

touch



mkdir

rmdir
1
vim index.js
  • 按 i 进入编辑模式

  • 按 esc 结束

  • 按 :wq, 或 shift+zz 退出vim

  • 按 :set nu 显示行号

  • 按 :set nonu 取消显示行号

查看进程

1
ps -ef

找PID

  • kill -1, 正常终止
  • kill -9, 强制终止
1
kill -1 PID
1
kill -9 PID

SSH上传/下载文件

  • -P port 指定端口号,可以省略,用默认的

  • -r 全传选中的文件夹

  • username@servername

    1
    root@8.130.25.41
1
2
3
4
5
6
7
# 上传文件夹到远程服务器
scp -P port -r /local/dir username@servername:/remote/dir
# scp -r ./ root@8.130.25.41:/home

# 从远程服务器下载文件夹
scp -P port -r username@servername:/remote/dir /local/dir
# scp -r root@8.130.25.41:/home ./

FTP上传/下载文件

FileZilla

创建并运行shell:

  1. touch newShell.sh

  2. vi newShell.sh

  3. 单击键盘i,开始编辑

  4. 编辑完成后,单击esc

  5. 保存并退出

    输入:wq

  6. 使之可执行

    chmod 755 newShell.sh

  7. 执行

    ./newShell.sh

iic-test-ssp /home/iic/ssp/run.sh:

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
APP_NAME=/home/iic/ssp/iic-ssp-mgr-1.0.0.RELEASE.war
#执行命令有误时,提示使用说明参数
usage() {
echo "Usage: bash.sh [start|stop|restart|status]"
exit 1 #exit结束进程,return函数返回
}

#检查程序是否已经在运行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' ` #ps -ef | grep java
if [ -z "${pid}" ]; then #[[ -z $str1 ]] 判断字符串是否为空,单中括号可能导致出错
return 1
else
return 0
fi #fi与if成对出现,作为if语句的结尾
}

#启动服务
start(){
is_exist
if [ $? -eq "0" ]; then #$? 显示最后命令的退出状态
echo "${APP_NAME} is already running. pid=${pid} ."
else
java -XX:+UseG1GC -jar $APP_NAME --spring.profiles.active=test --file.authId=6a534f8a516f429e9e940467b348fe61 --stat.fake=false &
fi
}

#停止服务
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
}
#输出服务运行状态
status(){
is_exist
if [ $? -eq "0" ]; then #if和then应该分两行,合在一行要加;
echo "${APP_NAME} is running. Pid is ${pid}"
else
echo "${APP_NAME} is NOT running."
fi
}

#重启服务
restart(){
stop
start
}

#根据输入参数,选择执行对应的方法,不输入则执行使用说明
case "$1" in
"start") #每一模式必须以右括号结束
start
;; #匹配发现取值符合某一模式后,其间所有命令开始执行直至 ;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac #case esac

upload-nginx-file.sh:

scp: secure copy

1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/expect
set timeout 10
set user root
set pass Gdsinsing888_nginx
set destDir /home/deploy/static
set ip 114.67.178.8
set filen [lrange /home/svn/iic/filecenter/iic-file-web/target/iic-file-web-1.0.0.RELEASE.war 0 0]

spawn scp ${filen} ${user}@${ip}:${destDir}
expect "${user}@${ip}'s password:"
send "${pass}\r"
interact

杂记

Private Clouds: 租房子住

Public Clouds: 住宾馆

On-Premises: 自己买房子住

测试环境:京东私有云 第一家 不稳定

  • Private Clouds

  • 为了一个客户单独使用而构建的

  • 经济性:机房、设备、运行维护费用

  • 安全性:数据由内部网络获取,第三方很难获取

正式环境:京东公有云 广州 成熟 稳定

  • Public Clouds

  • 资源是在服务商的场所内部署。用户通过Internet互联网来获取这些资源的使用。

  • 经济性:购买服务的费用

  • 安全性:通过运营商网络访问,可以通过算法对数据加密

cd /home/iic

d ssp

ls

  • run.sh 可执行文件
  • logs
  • .war 服务部署包
  • checkJavaPid.sh 检查进程id

cat run.sh 运行脚本,启动服务

目前重启需要先checkJavaPid找到进程,再kill

每个服务写restart, stop

难点:

  1. 用脚本查到进程id
  2. kill -9 pid

05-19:

目标:

  1. 用一台机的shell去启动另一台机的shell

  2. 保证同步shell 实现,不可以异步

05-20:

进展:

  1. 成功实现用 iic-test-api 远程控制 iic-test-ssp, 可以在iic-test-api 运行 iic-test-ssp上的脚本

    • 要设置ssh免密码登录

    • 先在 iic-tes-api 上,

      1
      ssh-keygen -t rsa
    • 保存密钥后,将passphrase设为空

    • 将生成的id_rsa.pub文件拷贝到远程服务器的 ~/.ssh 目录下,此时需要远程服务器的 root 密码

      • scp /root/.ssh/id_rsa.pub root@172.23.19.16:~/.ssh
        
        1
        2
        3
        4
        5
        6
        7
        8
        9

        + 注意:xshell中输入密码时虽然看似没反应,其实键盘正常工作!

        + 问题:为何使用的是对外的浮动IP,而不是对内的私有云内网IP?

        + 在远程服务器:append更新authorized_keys文件

        ```shell
        cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
      • 注意:cat除了看文件,还能文件间传输数据

    • 此时可以不输密码,访问远程服务器:

      1
      ssh root@172.23.19.16

      并可以执行命令或shell:

      1
      2
      ssh root@172.23.19.16 "cd /test1;./newdir.sh"
      ssh root@172.23.19.16 "cd /test1;ls"

05-24:

服务名 SSH Server Source files Exec command
test-api test-api target/iic-appapi-webapi-1.0.0.RELEASE.war nohup bash /home/iic/api/run.sh restart
test-file test-static target/iic-file-web-1.0.0.RELEASE.war nohup bash /home/iic/static/run.sh restart
test-idr test-idr target/iic-analyze-web-1.0.0.RELEASE.war nohup bash /home/iic/idr/run.sh restart
test-msg test-msg target/iic-msg-webapi-1.0.0.RELEASE.war nohup bash /home/iic/msg/run.sh restart
test-safety test-safety target/iic-safety-service-1.0.0.RELEASE.war nohup bash /home/iic/safety/run.sh restart
test-ssp test-ssp target/iic-ssp-mgr-1.0.0.RELEASE.war nohup bash /home/iic/ssp/run.sh restart
test-stat test-msg target/iic-stat-web-1.0.0.RELEASE.jar nohup bash /home/iic/stat/run.sh restart

05-25:

测试环境思路:

  1. 维持现状

svn编译成功后,从

1
/var/lib/jenkins/workspace/test-api/target/iic-appapi-webapi-1.0.0.RELEASE.war

推到了

1
/home/iic/api/iic-appapi-webapi-1.0.0.RELEASE.war

正式环境思路:

  1. svn将某服务(例如ssp)编译后,统一推包到nginx机,并执行nginx机上的对应的run-ssp.sh restart
  2. run-ssp.sh restart中:
    • 从nginx机推包到对应的ssp机
    • 启动对应的ssp机上的run.sh restart

开始测试:

  1. 先将svn与各test机建立免密连接
  2. 在svn机上写run-ssp.sh restart来推包并启动ssp机上的run.sh restart

test-ssp.sh

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
#!/bin/bash

start(){
upload
ssh root@172.23.19.16 "nohup bash /home/iic/ssp/run.sh restart"
}

stop(){
ssh root@172.23.19.16 "nohup bash /home/iic/ssp/run.sh stop"
}

restart(){
start
stop
}

upload(){
scp /var/lib/jenkins/workspace/test-ssp/target/iic-ssp-mgr-1.0.0.RELEASE.war root@172.23.19.16:/home/iic/ssp
}

#根据输入参数,选择执行对应的方法,不输入则执行使用说明
case "$1" in
"start") #每一模式必须以右括号结束
start
;; #匹配发现取值符合某一模式后,其间所有命令开始执行直至 ;;
"stop")
stop
;;
"restart")
restart
;;
esac

nginx架构

nginx:

  • 热部署
  • 全天候
  • 反向代理
  • 负载均衡

https://juejin.cn/post/6844904144235413512

nginx 转发 <- 公网ip

内网:每一个服务都有独立的账号、密码

  • api
  • idr
  • ssp
  • static 文件中心
  • safety 安全中心

部署:登录、上传.war、run

专门的部署机:

  • upload
  • run 参数,想run哪一台
  • stop
  • restart

远程登录

需要先输入账号密码 登录部署机, 再输入账号密码去操纵对应服务

备份: 将旧版本ssp备份到部署机 以便快速恢复系统

外界访问 用 浮动ip

内部访问 用 私有云ip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# same origin
http://example.com/app1/index.html # merely directory difference
http://example.com/app2/index.html

http://Example.com:80 # merely case difference
http://example.com

# different origins
http://example.com/app1 # different protocols
https://example.com/app2

http://example.com # different hosts
http://www.example.com
http://myapp.example.com

http://example.com # different ports
http://example.com:8080


测试 部署

测试:Jenkins

部署: 京东云

Jenkins连svn,获取源代码,再部署到linux服务器;起桥梁的作用

Jenkins:

  • 免费开源的持续集成工具
  • continuous integration