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

Posted 科讯华通

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化运维工具之:dcli 批量管理数据库主机相关的知识,希望对你有一定的参考价值。


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


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

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

    

 
   
   
 
  1. mkdir -p /home/oracle/scifmation/tools/.s

  2. chmod 700 /home/oracle/scifmation/tools/.s

  3. ssh-kengen  -t dsa  -f /home/oracle/scifmation/tools/.s/dsa


  4. [oracle@exa1db02 (orcl2)tools]$ ls -la

  5. drwx------ 2 oracle oinstall  4096 Mar 21 10:22 .s

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

 
   
   
 
  1. line 120:

  2. SSHSUBDIR="/home/oracle/scifmation/tools/.s"

  3. SSHDSAFILE="dsa.pub"


  4. line 885:

  5.    parser.add_option("-s",

  6.                     help="string of options passed through to ssh",

  7.                     action="store", type="string", dest="sshOptions",default="-i /home/oracle/scifmation/tools/.s/dsa")

  8.                


    2、修改默认ssh 登录用户

 
   
   
 
  1. line 872:

  2.    parser.add_option("-l", default="oracle",

  3.                     help="user to login as on remote cells (default: oracle) ",

  4.                     action="store", type="string", dest="userID")


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

 
   
   
 
  1. line 172:

  2. def buildCommand( args, verbose ):

  3.    """

  4.    Build a command string to be sent to all hosts.


  5.    Command arguments can be used to build the command to

  6.    be sent to hosts.

  7.    """

  8.    command = ""

  9.    command2= 'echo not allow execute this command!'

  10.    if args:

  11.        for word in args:

  12.            command += " " + word;

  13.    if command.find("rm ")>=0:

  14.        return command2

  15.    elif command.find("shutdown")>=0:

  16.        return command2

  17.    elif command.find("stop")>=0:

  18.        return command2

  19.    elif command.find("halt")>=0:

  20.        return command2

  21.    elif command.find("alias")>=0:

  22.        return command2

  23.    return command

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

 
   
   
 
  1. vi /home/oracle/scifmation/tools/mcli

  2. chmod +x /home/oracle/scifmation/tools/mcli


  3. [oracle@exa1db02 (orcl2)tools]$ mcli

  4. Error: No command specified.

  5. usage: dcli2c [options] [command]


  6. options:

  7.  --version            show program's version number and exit

  8.  -c CELLS             comma-separated list of cells

  9.  -d DESTFILE          destination directory or file

  10.  -f FILE              files to be copied

  11.  -g GROUPFILE         file containing list of cells

  12.  -h, --help           show help message and exit

  13.  -k                   push ssh key to cell's authorized_keys file

  14.  -l USERID            user to login as on remote cells (default: oracle)

  15.  --maxlines=MAXLINES  limit output lines from a cell when in parallel

  16.                       execution over multiple cells (default: 100000)

  17.  -n                   abbreviate non-error output

  18.  -r REGEXP            abbreviate output lines matching a regular expression

  19.  -s SSHOPTIONS        string of options passed through to ssh

  20.  --scp=SCPOPTIONS     string of options passed through to scp if different

  21.                       from sshoptions

  22.  --serial             serialize execution over the cells

  23.  -t                   list target cells

  24.  --unkey              drop keys from target cells' authorized_keys file

  25.  -v                   print extra messages to stdout

  26.  --vmstat=VMSTATOPS   vmstat command options

  27.  -x EXECFILE          file to be copied and executed



二、增加被管主机

    1、设置ssh免密码登录

    

 
   
   
 
  1. [oracle@exa1db02 (orcl2)tools]$ mcli -c 192.168.1.19 -k

  2. The authenticity of host '192.168.1.19 (192.168.1.19)' can't be established.

  3. RSA key fingerprint is f1:f6:e0:be:7f:97:bd:3c:99:20:88:1e:3a:63:2b:6f.

  4. Are you sure you want to continue connecting (yes/no)? yes

  5. Warning: Permanently added '192.168.1.19' (RSA) to the list of known hosts.

  6. oracle@192.168.1.19's password:

  7. 192.168.1.19: ssh key added

    2、创建被管主组文件

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

  2. 192.168.1.19

  3. 192.168.1.20

  4. 192.168.1.13

  5. 192.168.1.14

  6. 192.168.1.15

  7. 192.168.1.16

  8. 192.168.1.17

  9. 192.168.1.18


三、开始测试吧

--查看主机名

 
   
   
 
  1. [oracle@exa1db02 (orcl2)tools]$ mcli -g zw "hostname"

  2. 192.168.1.19: testa1

  3. 192.168.1.20: testa2

  4. 192.168.1.13: testb1

  5. 192.168.1.14: testb2

  6. 192.168.1.15: testc1

  7. 192.168.1.16: testc2

  8. 192.168.1.17: testd1

  9. 192.168.1.18: testd2

--停止oem agent

 
   
   
 
  1. [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"

  2. 192.168.1.19: Oracle Enterprise Manager Cloud Control 12c Release 4

  3. 192.168.1.19: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  4. 192.168.1.19: Stopping agent ..... stopped.

  5. 192.168.1.20: Oracle Enterprise Manager Cloud Control 12c Release 4

  6. 192.168.1.20: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  7. 192.168.1.20: Stopping agent ..... stopped.

  8. 192.168.1.13: Oracle Enterprise Manager Cloud Control 12c Release 4

  9. 192.168.1.13: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  10. 192.168.1.13: Agent is Not Running

  11. 192.168.1.14: Oracle Enterprise Manager Cloud Control 12c Release 4

  12. 192.168.1.14: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  13. 192.168.1.14: Stopping agent ..... stopped.

  14. 192.168.1.15: Oracle Enterprise Manager Cloud Control 12c Release 4

  15. 192.168.1.15: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  16. 192.168.1.15: Stopping agent ..... stopped.

  17. 192.168.1.16: Oracle Enterprise Manager Cloud Control 12c Release 4

  18. 192.168.1.16: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  19. 192.168.1.16: Stopping agent ..... stopped.

  20. 192.168.1.17: Oracle Enterprise Manager Cloud Control 12c Release 4

  21. 192.168.1.17: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  22. 192.168.1.17: Stopping agent ..... stopped.

  23. 192.168.1.18: Oracle Enterprise Manager Cloud Control 12c Release 4

  24. 192.168.1.18: Copyright (c) 1996, 2014 Oracle Corporation.  All rights reserved.

  25. 192.168.1.18: Stopping agent ..... stopped.

--查看oem运行状态

 
   
   
 
  1. [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"

  2. 192.168.1.19: Agent is Not Running

  3. 192.168.1.20: Agent is Not Running

  4. 192.168.1.13: Agent is Not Running

  5. 192.168.1.14: Agent is Not Running

  6. 192.168.1.15: Agent is Not Running

  7. 192.168.1.16: Agent is Not Running

  8. 192.168.1.17: Agent is Not Running

  9. 192.168.1.18: Agent is Not Running

--复制文件到受管主机

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


以上是关于自动化运维工具之:dcli 批量管理数据库主机的主要内容,如果未能解决你的问题,请参考以下文章

运维自动化之 - ansible 批量主机管理

大型企业中如何批量管理千万台服务器之ansible自动化运维工具详解 [⭐建议收藏⭐]

大型企业中如何批量管理千万台服务器之ansible自动化运维工具详解 [⭐建议收藏⭐]

自动化运维工具之ansible

Ansible自动化运维工具阐述及配置实现

[实战]python开发自动化运维工具--批量操作主机