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 244979152@qq.com.
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!
可以看到之前的操作
現在本軟體的所有功能就都實現了,希望各位能多提供建議與問題,也希望各位同仁能一起分享一下自己對運維自動化的經驗,多對軟體進行開源,謝謝。