自动化运维工具之:dcli 批量管理数据库主机

网友投稿 1222 2022-10-06

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

自动化运维工具之:dcli 批量管理数据库主机

原文作者:范计杰, 北京科讯华通科技发展有限公司 数据库高级工程师

dcli 为exadata上管理cell的工具,但具有通用性,可以用来在大量机器上并行执行命令、角本、复制文件,是一个python角本,依赖包较少(我的测试机只需python默认安装即可),受管主机不需要python,现在我们修改dcli,根据个人需求进行定制,来管理oracle主机。

一、根据个人需求,修改dcli

1、为了安全,修改默认ssh key位置,并创建ssh key

mkdir -p /home/oracle/scifmation/tools/.schmod 700 /home/oracle/scifmation/tools/.sssh-kengen  -t dsa  -f /home/oracle/scifmation/tools/.s/dsa[oracle@exa1db02 (orcl2)tools]$ ls -ladrwx------ 2 oracle oinstall  4096 Mar 21 10:22 .s

dcli修改,实际行号可能有不同

line 120:SSHSUBDIR="/home/oracle/scifmation/tools/.s"SSHDSAFILE="dsa.pub"line 885:    parser.add_option("-s",                     help="string of options passed through to ssh",                     action="store", type="string", dest="sshOptions",default="-i home/oracle/scifmation/tools/.s/dsa")

2、修改默认ssh 登录用户

line 872:    parser.add_option("-l", default="oracle",                     help="user to login as on remote cells (default: oracle) ",                     action="store", type="string", dest="userID")

3、增加命令过滤,限制rm,shutdown,stop,halt,alias,尽量减少误操作

line 172:def buildCommand( args, verbose ):    """    Build a command string to be sent to all hosts.    Command arguments can be used to build the command to    be sent to hosts.    """    command = ""    command2= 'echo not allow execute this command!'    if args:        for word in args:            command += " " + word;    if command.find("rm ")>=0:        return command2    elif command.find("shutdown")>=0:        return command2    elif command.find("stop")>=0:        return command2    elif command.find("halt")>=0:        return command2    elif command.find("alias")>=0:        return command2    return command

4、在管理主机上创建修改后的角本

vi /home/oracle/scifmation/tools/mclichmod +x /home/oracle/scifmation/tools/mcli[oracle@exa1db02 (orcl2)tools]$ mcliError: No command specified.usage: dcli2c [options] [command]options:  --version            show program's version number and exit  -c CELLS             comma-separated list of cells  -d DESTFILE          destination directory or file  -f FILE              files to be copied  -g GROUPFILE         file containing list of cells  -h, --help           show help message and exit  -k                   push ssh key to cell's authorized_keys file  -l USERID            user to login as on remote cells (default: oracle)  --maxlines=MAXLINES  limit output lines from a cell when in parallel                       execution over multiple cells (default: 100000)  -n                   abbreviate non-error output  -r REGEXP            abbreviate output lines matching a regular expression  -s SSHOPTIONS        string of options passed through to ssh  --scp=SCPOPTIONS     string of options passed through to scp if different                       from sshoptions  --serial             serialize execution over the cells  -t                   list target cells  --unkey              drop keys from target cells' authorized_keys file  -v                   print extra messages to stdout  --vmstat=VMSTATOPS   vmstat command options  -x EXECFILE          file to be copied and executed

二、增加被管主机

1、设置ssh免密码登录

[oracle@exa1db02 (orcl2)tools]$ mcli -c 192.168.1.19 -kThe authenticity of host '192.168.1.19 (192.168.1.19)' can't be established.RSA key fingerprint is f1:f6:e0:be:7f:97:bd:3c:99:20:88:1e:3a:63:2b:6f.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.1.19' (RSA) to the list of known hosts.oracle@192.168.1.19's password: 192.168.1.19: ssh key added

2、创建被管主组文件

[oracle@exa1db02 (orcl2)tools]$vi yy    (add 被管主机ip or hostname)192.168.1.19192.168.1.20192.168.1.13192.168.1.14192.168.1.15192.168.1.16192.168.1.17192.168.1.18

三、开始测试吧

--查看主机名

[oracle@exa1db02 (orcl2)tools]$ mcli -g zw "hostname"192.168.1.19: testa1192.168.1.20: testa2192.168.1.13: testb1192.168.1.14: testb2192.168.1.15: testc1192.168.1.16: testc2192.168.1.17: testd1192.168.1.18: testd2

--停止oem agent

[oracle@exa1db02 (orcl2)tools]$ mcli -g zw "export AGENT_HOME=/oracle/em_agent/core/12.1.0.4.0;\$AGENT_HOME/bin/emctl stop agent"192.168.1.19: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.19: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.19: Stopping agent ..... stopped.192.168.1.20: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.20: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.20: Stopping agent ..... stopped.192.168.1.13: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.13: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.13: Agent is Not Running192.168.1.14: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.14: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.14: Stopping agent ..... stopped.192.168.1.15: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.15: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.15: Stopping agent ..... stopped.192.168.1.16: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.16: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.16: Stopping agent ..... stopped.192.168.1.17: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.17: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.17: Stopping agent ..... stopped.192.168.1.18: Oracle Enterprise Manager Cloud Control 12c Release 4192.168.1.18: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.192.168.1.18: Stopping agent ..... stopped.

--查看oem运行状态

[oracle@exa1db02 (orcl2)tools]$ mcli -g zw "export AGENT_HOME=/oracle/em_agent/core/12.1.0.4.0;\$AGENT_HOME/bin/emctl status agent|grep Running"192.168.1.19: Agent is Not Running192.168.1.20: Agent is Not Running192.168.1.13: Agent is Not Running192.168.1.14: Agent is Not Running192.168.1.15: Agent is Not Running192.168.1.16: Agent is Not Running192.168.1.17: Agent is Not Running192.168.1.18: Agent is Not Running

--复制文件到受管主机

[oracle@exa1db02 (orcl2)tools]$ mcli -g zw -f /home/oracle/scifmation/tools/zw  -d /home/oracle/scifmation

上一篇:为什么要做一个数据库运维管理系统
下一篇:突发重大事故,我们是这样处理的 | 平凡的世界,不平凡的运维(一)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~