章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • python

  • shell

    • 进程pid判断脚本
    • 日志切割脚本
    • 设置跳板机脚本
    • 编写启动、停止、重启的脚本
    • mysql数据库备份的三种方式
    • jenkins编译服务脚本
    • app编译脚本
    • 常用shell脚本
    • 字符串的截取拼接
    • shell基础
    • centos7主机安全检测脚本和初始化脚本
    • 应用服务重启脚本
    • shell重启python程序脚本
    • rancher的证书制作脚本
    • shell常用脚本集合
    • mysql常用的脚本集合
    • shell批量部署安装包并启动
    • 批量添加定时任务
    • mysql备份企业示例
    • shell脚本创建出色用户体验的6种技巧
    • 多系统一键部署zabbix6脚本(已验证)
    • 批量拿取多台服务器的日志文件
    • shell脚本模块集合
  • go

  • 编程
  • shell
章工运维
2024-09-10

shell批量部署安装包并启动

脚本如下

#!/bin/bash

# 定义目标服务器
servers=("192.168.0.100" "192.168.0.105")

# 定义文件和目录
file="pomp.tar.gz"
#remote_dir="/"
install_dir="/pomp"

# 循环遍历每个服务器
for server in "${servers[@]}"; do
    echo "正在处理服务器: $server"

    # 1. 发布文件到服务器
    scp "$file" "root@$server:$install_dir"
    if [ $? -ne 0 ]; then
        echo "错误: 无法将文件发送到 $server"
        continue
    fi

    # 2. 解压文件并设置权限
    ssh "root@$server" << EOF
        cd $install_dir
        tar --strip-components=1 -xzvf $file
        rm -f $file
        if [ $? -ne 0 ]; then
            echo "错误: 无法在 $server 上解压文件"
            exit 1
        fi

        chown -R la_pomp_01:la_pomp_01 $install_dir
        if [ $? -ne 0 ]; then
            echo "错误: 无法在 $server 上设置目录权限"
            exit 1
        fi

        # 3. 启动服务
        sh $install_dir/new-flume/bin/run.sh
        if [ $? -ne 0 ]; then
            echo "错误: 无法在 $server 上启动服务"
            exit 1
        fi

        echo "在 $server 上成功完成所有操作"
EOF

    if [ $? -ne 0 ]; then
        echo "在处理 $server 时发生错误"
    else
        echo "成功处理服务器: $server"
    fi
done

echo "脚本执行完毕"
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
微信 支付宝
上次更新: 2024/09/10, 15:32:43

← mysql常用的脚本集合 批量添加定时任务→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式