php+mysql+shell运维监控系统,监控起来很方便,但在运维管理方便还是不能实现,所以最近打算使用python语言编写一套的运维管理系统,可以使用单台或多台机器同时管理与部署等功能,实现类似func、triaquae等管理软件功能。 之前开发了
本软件是参考了triaquae软件的思路(对方软件地址为http://triaquae2.sinaapp.com/),参考对方软件的组方面的部分代码,经过与原作者Alex Li的协商,允许我使用对方部分代码与思路,所以我把此软件进行开源,分享给大家。
下面开始安装与应用测试
一、软件的安装
软件可以到https://github.com/dl528888/auto_op/里面进行下载
1、先解压软件
- root@squid:/tmp# tar zxvf auto_op.tar.gz
- auto/
- auto/auto_op.py
- auto/setup.py
- auto/install.txt
安装前软件的结构
- root@squid:/tmp# tree auto
- auto
- |-- auto_op-software-install-and-function-document.docx #中文的安装文档
- |-- auto_op.py #程序包
- |-- install.txt #软件介绍与安装说明
- `-- setup.py #部署环境与安装
- 0 directories, 4 files
2、进入目录查看安装文档install.txt
- root@squid:/tmp# cd auto/
- root@squid:/tmp/auto# ll
- total 44
- drwxr-xr-x 2 root root 4096 Mar 20 23:44 ./
- drwxrwxrwt 8 root root 4096 Mar 21 09:56 ../
- -rw-r--r-- 1 root root 24774 Mar 20 23:33 auto_op.py
- -rw-r--r-- 1 root root 494 Mar 20 23:44 install.txt
- -rw-r--r-- 1 root root 3346 Mar 20 22:53 setup.py
- root@squid:/tmp/auto# cat install.txt
- Version 1.0
- Introduction
- This software is manage many servers.I refer to TriAquae.TriAquae's author is Alex Li.You can let all your Linux servers(or single server) doing the same job in the same time,such as send a file,run a script,modify file,excute command and etc.
- Install
- 1. tar zxvf auto_op.tar.gz
- 2. cd auto
- 3. python setup.py build --prefix=/installdir/
- 4. python setup.py install
- 5. /installdir/auto_op.py
- Support
- If you have some problem , you can send mailto [email protected].
3、根据安装文档安装,先指定安装目录
- root@squid:/tmp/auto# python setup.py build --prefix=/usr/local/auto_op
- Start to check pre-installation environment...................................
- direcotry not exsit,creating successful........
- If no error printed out , you can run 'python setup.py install' to install the program
4、然后再进行安装
- root@squid:/tmp/auto# python setup.py install
- Extract files to working directory...
- Complete ok
- Now you can run /usr/local/auto_op/auto_op.py start manage your network.
5、进入安装目录运行软件
- root@squid:/tmp/auto# cd /usr/local/auto_op/
- root@squid:/usr/local/auto_op# ll
- total 36
- drwxr-xr-x 2 root root 4096 Mar 21 10:02 ./
- drwxr-xr-x 12 root root 4096 Mar 21 10:02 ../
- -rw-r--r-- 1 root root 24783 Mar 21 10:02 auto_op.py
- root@squid:/usr/local/auto_op# chmod 755 auto_op.py
- root@squid:/usr/local/auto_op# ll
- total 36
- drwxr-xr-x 2 root root 4096 Mar 21 10:02 ./
- drwxr-xr-x 12 root root 4096 Mar 21 10:02 ../
- -rwxr-xr-x 1 root root 24783 Mar 21 10:02 auto_op.py*
- root@squid:/usr/local/auto_op# ./auto_op.py
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Add new group
- 2. Rename group name
- 3. Delete group
- 4. List group member
- 5. List host in the group
- 6. Add new server to group
- 7. Delete server from group
- 8. Command excution on group servers
- 9. Command excution on one server
- 10. Upload or download on group servers
- 11. Upload or download on one server
- 12. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
可以看到有很多选项,下面是介绍
- 1. Add new group #添加新组
- 2. Rename group name #对组重命名
- 3. Delete group #删除组
- 4. List group member #列出已有的组名称与成员数量
- 5. List host in the group #列出组内的主机ip
- 6. Add new server to group #增加新主机到组里
- 7. Delete server from group #删除组里的主机
- 8. Command excution on group servers #在组内的所有主机统一执行命令
- 9. Command excution on one server #对组内的某个主机执行命令
- 10. Upload or download on group servers #对组内的所有主机进行上传与下载文件
- 11. Upload or download on one server #对组内的某个主机进行上传与下载文件
- 12. Quit #退出
安装后的软件结构
- root@squid:/tmp# tree /usr/local/auto_op/
- /usr/local/auto_op/
- |-- auto_op.py #程序包
- |-- logs #日志目录
- | `-- operation.log #操作日志
- `-- server_list #组目录
- `-- test #组
- 2 directories, 3 files
二、测试
1、选择1进行创建新组
- please input you choice:1 #选择1创建新组
- please input new group name:test #组名为test
- Created group test successful.
- Do you want to add new server to Group test [ Y / N ]:y #选择添加新主机到test组里
- Input new server IP or Hostname:192.168.101.235 #新主机的ip
- Input newser's port:22 #新主机的端口
- Input newser's username:root #新主机的用户名
- Input newser's password:123456 #新主机的秘密
- New server 192.168.101.235 added successfully.
2、在新创建个one组,然后进行重命名组操作
- please input you choice:1 #选项1是创建新组
- please input new group name:one #新组名为one
- Created group one successful.
- Do you want to add new server to Group one [ Y / N ]:n #不添加主机到组里
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Add new group
- 2. Rename group name
- 3. Delete group
- 4. List group member
- 5. List host in the group
- 6. Add new server to group
- 7. Delete server from group
- 8. Command excution on group servers
- 9. Command excution on one server
- 10. Upload or download on group servers
- 11. Upload or download on one server
- 12. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
- please input you choice:2 #选项2是对组重命名
- ---------------
- Which group name do you want to change?:one #重命名组为one
- New name:first #重命名为first
- group name of one changed to first
3、选择4查看本机所有组的状态
- please input you choice:4
- now there is group is
- test[1]
- first[0]
可以看到test组有1个成员,first没有成员
4、删除first组
- please input you choice:3 #选项3是删除组
- please inupt you want to del group name:first #输入要删除的组名
- first
- Are you sure you want to delete groupfirst [ Y / N ]: y #确认是否删除
- Deleted group first
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Add new group
- 2. Rename group name
- 3. Delete group
- 4. List group member
- 5. List host in the group
- 6. Add new server to group
- 7. Delete server from group
- 8. Command excution on group servers
- 9. Command excution on one server
- 10. Upload or download on group servers
- 11. Upload or download on one server
- 12. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
- please input you choice:4 #在查看一下当前的所有组
- now there is group is
- test[1]
5、选择5查看test组里所有的主机
- please input you choice:5 #选项5查看组内的主机
- Input Group name which the server is in:test #输入查看的组名
- ------------------------Server List----------------------------
- 192.168.101.235 #test组内的主机
6、选项6增加新主机到组里
- please input you choice:6 #选项6添加新主机到组
- Input Group name which the server is in:test #选项添加新主机的组
- ------------------------Server List----------------------------
- 192.168.101.235 #组内的所有主机
- groupfile is /usr/local/auto_op/server_list/test
- Input new server IP or Hostname:192.168.101.236 #新主机的ip
- Input newser's port:22 #新主机的端口
- Input newser's username:root #新主机的用户
- Input newser's password:123456 #新主机的密码
- New server 192.168.101.236 added successfully.
- Keep on adding new server?:[ Y / N ]y #是否继续添加新主机
- Input new server IP or Hostname:1.1.1.1
- Input newser's port:22
- Input newser's username:root
- Input newser's password:123456
- New server 1.1.1.1 added successfully.
- Keep on adding new server?:[ Y / N ]n
7、选择7删除主机从组里
- please input you choice:7
- Input Group name which the server is in:test
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
- 1.1.1.1
- Notice: All matched IP adresses will be deleted,becare
- Input the server IP which you want to delete:1.1.1.1
- 1.1.1.1
- matched rows: 1
- Do you want to delete all the matched rows?(y/n)y
- IP 1.1.1.1 has been deleted from group test
- Notice: All matched IP adresses will be deleted,becare
- Input the server IP which you want to delete:you command is CTRL+C go back
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Add new group
- 2. Rename group name
- 3. Delete group
- 4. List group member
- 5. List host in the group
- 6. Add new server to group
- 7. Delete server from group
- 8. Command excution on group servers
- 9. Command excution on one server
- 10. Upload or download on group servers
- 11. Upload or download on one server
- 12. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
- please input you choice:5
- Input Group name which the server is in:test
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
8、选项8对组内所有主机同时执行命令
- please input you choice:8 #选择8对组内所有主机执行命令
- now there is group is #列出当前所有的组
- test[2]
- please input you choice group:test #输入项执行命令的组
- You choice test group
- please input you want to select command,Ctrl + C to quit:hostname #输入执行的命令
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:21:51
- exec result is
- linux-cbb3 #执行的结果
- 192.168.101.235 exec command ['hostname'] OK!
- end time is 2013-03-21 10:21:51
- -------------------------------
- -------------------------------
- start to connect ip 192.168.101.236 port 22 username root at time 2013-03-21 10:21:51
- exec result is
- squid
- 192.168.101.236 exec command ['hostname'] OK!
- end time is 2013-03-21 10:21:52
- -------------------------------
- please input you want to select command,Ctrl + C to quit:
9、选项9对组内的某个主机执行命令
- please input you choice:9 #选择9
- now there is group is
- test[2]
- Input Group name which the server is in:test #选择test组
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
- Please input you want to execute the command of the host name:192.168.101.235 #选择主机
- please input you want to select command,Ctrl + C to quit:uptime #输入命令
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:23:50
- exec result is
- 10:25pm up 152 days 18:02, 1 user, load average: 0.07, 0.02, 0.00
- 192.168.101.235 exec command ['uptime'] OK!
- end time is 2013-03-21 10:23:51
- -------------------------------
- please input you want to select command,Ctrl + C to quit:
10、选项10是对组内进行文件的上传与下载
- please input you choice:10
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Upload file to remote group servers
- 2. Download file to remote group server
- 3. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
可以看到选项10里有3个选项
1、把本地的文件上传到组内所有主机里
2、从组内的所有主机下载文件到本机
3、退出
我们先进行1项,把本地的文件上传到组内所有主机里
- please input you choice:1
- now there is group is
- test[2]
- please input you choice group:test
- You choice test group
- please input you want to upload localpath file name,Ctrl + C to quit:/tmp/log #上传本机的文件
- please input you want to upload remotepath file name,Ctrl + C to quit:/tmp/test-upload-file-to-group.log #上传到组内主机的文件名
- Are you sure upload file from /tmp/log to /tmp/test-upload-file-to-group.log in the test group y
- ------------------------------- #确认是否传输
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:28:46
- 192.168.101.235 exec put /tmp/log to /tmp/test-upload-file-to-group.log OK!
- end time is 2013-03-21 10:28:47
- -------------------------------
- -------------------------------
- start to connect ip 192.168.101.236 port 22 username root at time 2013-03-21 10:28:47
- 192.168.101.236 exec put /tmp/log to /tmp/test-upload-file-to-group.log OK!
- end time is 2013-03-21 10:28:47
- -------------------------------
查询的话就是
- please input you choice:8
- now there is group is
- test[2]
- please input you choice group:test
- You choice test group
- please input you want to select command,Ctrl + C to quit:ls -l /tmp/test-upload-file-to-group.log
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:30:42
- exec result is
- -rw-r--r-- 1 root root 21 Mar 21 22:30 /tmp/test-upload-file-to-group.log
- 192.168.101.235 exec command ['ls -l /tmp/test-upload-file-to-group.log'] OK!
- end time is 2013-03-21 10:30:42
- -------------------------------
- -------------------------------
- start to connect ip 192.168.101.236 port 22 username root at time 2013-03-21 10:30:42
- exec result is
- -rw-r--r-- 1 root root 21 Mar 21 10:28 /tmp/test-upload-file-to-group.log
- 192.168.101.236 exec command ['ls -l /tmp/test-upload-file-to-group.log'] OK!
- end time is 2013-03-21 10:30:43
- -------------------------------
下面进行选项2,从组内的所有主机下载文件到本机
- please input you choice:10
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Upload file to remote group servers
- 2. Download file to remote group server
- 3. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
- please input you choice:2
- now there is group is
- test[2]
- please input you choice group:test
- You choice test group
- please input you want to download localpath file name,Ctrl + C to quit:/tmp/test-download-to-group.log
- please input you want to download remotepath file name,Ctrl + C to quit:/tmp/test-upload-file-to-group.log
- Are you sure download file from /tmp/test-download-to-group.log to /tmp/test-upload-file-to-group.log in the test group y
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:32:13
- 192.168.101.235 exec get /tmp/test-upload-file-to-group.log from /tmp/test-download-to-group.log_192.168.101.235 OK!
- end time is 2013-03-21 10:32:13
- -------------------------------
- -------------------------------
- start to connect ip 192.168.101.236 port 22 username root at time 2013-03-21 10:32:13
- 192.168.101.236 exec get /tmp/test-upload-file-to-group.log from /tmp/test-download-to-group.log_192.168.101.236 OK!
- end time is 2013-03-21 10:32:14
我这回是把之前上传的/tmp/test-upload-file-to-group.log文件给现在到本地,命名为/tmp/test-download-to-group.log,由于是不同主机把文件传给本机,所以我在文件名后面加上了他们的ip好区分。
下面是查看的结果
- please input you choice:8
- now there is group is
- test[2]
- please input you choice group:test
- You choice test group
- please input you want to select command,Ctrl + C to quit:ls -l /tmp/test-download-to-group.log*
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:34:22
- exec result is
- 192.168.101.235 exec command ['ls -l /tmp/test-download-to-group.log*'] OK!
- end time is 2013-03-21 10:34:22
- -------------------------------
- -------------------------------
- start to connect ip 192.168.101.236 port 22 username root at time 2013-03-21 10:34:22
- exec result is
- -rw-r--r-- 1 root root 21 Mar 21 10:32 /tmp/test-download-to-group.log_192.168.101.235
- -rw-r--r-- 1 root root 21 Mar 21 10:32 /tmp/test-download-to-group.log_192.168.101.236
- 192.168.101.236 exec command ['ls -l /tmp/test-download-to-group.log*'] OK!
- end time is 2013-03-21 10:34:23
- -------------------------------
可以看到主机192.168.101.236已经获得了/tmp/test-download-to-group.log_192.168.101.235与/tmp/test-download-to-group.log_192.168.101.236的2个文件
11、选项11是进行组内某主机的上传与下载,也就是单台主机的
- please input you choice:11
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Upload file to remote one server
- 2. Download file to remote one server
- 3. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
里面也有3个选项
1、从本机上传文件给远程主机
2、从远程主机下载文件给本机
3、退出
现在进行选项1,从本机上传文件给远程主机
- please input you choice:1
- now there is group is
- test[2]
- Input Group name which the server is in:test
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
- Please input you want to execute the command of the host name:192.168.101.235
- please input you want to upload localpath file name,Ctrl + C to quit:/tmp/test-download-to-group.log_192.168.101.236
- please input you want to upload remotepath file name,Ctrl + C to quit:/tmp/test-upload-to-host.log
- Are you sure upload file from /tmp/test-download-to-group.log_192.168.101.236 to /tmp/test-upload-to-host.log in the 192.168.101.235 host y
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:38:44
- 192.168.101.235 exec put /tmp/test-download-to-group.log_192.168.101.236 to /tmp/test-upload-to-host.log OK!
- end time is 2013-03-21 10:38:44
- -------------------------------
然后查询
- please input you choice:9
- now there is group is
- test[2]
- Input Group name which the server is in:test
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
- Please input you want to execute the command of the host name:192.168.101.235
- please input you want to select command,Ctrl + C to quit:ls -l /tmp/test-upload-to-host.log
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:39:59
- exec result is
- -rw-r--r-- 1 root root 21 Mar 21 22:40 /tmp/test-upload-to-host.log
- 192.168.101.235 exec command ['ls -l /tmp/test-upload-to-host.log'] OK!
- end time is 2013-03-21 10:40:00
- -------------------------------
可以看到文件已经上传到192.168.101.235主机了
现在进行选项2,从远程主机下载文件给本机
- please input you choice:11
- ------------------------------------Memu list-----------------------------------------------------------
- 1. Upload file to remote one server
- 2. Download file to remote one server
- 3. Quit
- --------------------------------Input number of you want to exec command---------------------------------
- Author is DengLei
- please input you choice:2
- now there is group is
- test[2]
- Input Group name which the server is in:test
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
- Please input you want to execute the command of the host name:192.168.101.235
- please input you want to download localpath file name,Ctrl + C to quit:/tmp/test-download-to-host.log
- please input you want to download remotepath file name,Ctrl + C to quit:/tmp/test-upload-to-host.log
- Are you sure download file from /tmp/test-download-to-host.log to /tmp/test-upload-to-host.log in the 192.168.101.235 host y
- -------------------------------
- start to connect ip 192.168.101.235 port 22 username root at time 2013-03-21 10:41:04
- 192.168.101.235 exec get /tmp/test-upload-to-host.log from /tmp/test-download-to-host.log_192.168.101.235 OK!
- end time is 2013-03-21 10:41:04
- -------------------------------
进行查看
- please input you choice:9
- now there is group is
- test[2]
- Input Group name which the server is in:test
- ------------------------Server List----------------------------
- 192.168.101.235
- 192.168.101.236
- Please input you want to execute the command of the host name:192.168.101.236
- please input you want to select command,Ctrl + C to quit:ls -l /tmp/test-download-to-host.log_192.168.101.235
- -------------------------------
- start to connect ip 192.168.101.236 port 22 username root at time 2013-03-21 10:41:45
- exec result is
- -rw-r--r-- 1 root root 21 Mar 21 10:41 /tmp/test-download-to-host.log_192.168.101.235
- 192.168.101.236 exec command ['ls -l /tmp/test-download-to-host.log_192.168.101.235'] OK!
- end time is 2013-03-21 10:41:46
- -------------------------------
也传输成功
12、操作日志查看
所有的操作都有存放到日志里,方便查看
- root@squid:/tmp# cd /usr/local/auto_op/
- root@squid:/usr/local/auto_op# ll
- total 44
- drwxr-xr-x 4 root root 4096 Mar 21 10:03 ./
- drwxr-xr-x 12 root root 4096 Mar 21 10:02 ../
- -rwxr-xr-x 1 root root 24783 Mar 21 10:02 auto_op.py*
- drwxr-xr-x 2 root root 4096 Mar 21 10:09 logs/
- drwxr-xr-x 2 root root 4096 Mar 21 10:19 server_list/
- root@squid:/usr/local/auto_op# cd logs/
- root@squid:/usr/local/auto_op/logs# ll
- total 16
- drwxr-xr-x 2 root root 4096 Mar 21 10:09 ./
- drwxr-xr-x 4 root root 4096 Mar 21 10:03 ../
- -rw-r--r-- 1 root root 5415 Mar 21 10:41 operation.log
- root@squid:/usr/local/auto_op/logs# tail -f operation.log
- 2013-03-21 10:36:40 show group test server list['192.168.101.235', '192.168.101.236']
- 2013-03-21 10:38:44 192.168.101.235 exec put /tmp/test-download-to-group.log_192.168.101.236 to /tmp/test-upload-to-host.log OK!
- 2013-03-21 10:39:08 show group test server list['192.168.101.235', '192.168.101.236']
- 2013-03-21 10:39:25 192.168.101.235 exec command ['ls -l /tmp/test-download-to-group.log_192.168.101.236'] OK!
- 2013-03-21 10:39:50 show group test server list['192.168.101.235', '192.168.101.236']
- 2013-03-21 10:40:00 192.168.101.235 exec command ['ls -l /tmp/test-upload-to-host.log'] OK!
- 2013-03-21 10:40:38 show group test server list['192.168.101.235', '192.168.101.236']
- 2013-03-21 10:41:04 192.168.101.235 exec get /tmp/test-upload-to-host.log from /tmp/test-download-to-host.log_192.168.101.235 OK!
- 2013-03-21 10:41:24 show group test server list['192.168.101.235', '192.168.101.236']
- 2013-03-21 10:41:46 192.168.101.236 exec command ['ls -l /tmp/test-download-to-host.log_192.168.101.235'] OK!
可以看到之前的操作
现在本软件的所有功能就都实现了,希望各位能多提供建议与问题,也希望各位同仁能一起分享一下自己对运维自动化的经验,多对软件进行开源,谢谢。