设为首页 收藏本站
查看: 1344|回复: 0

[经验分享] 运维自动化之ansible playbook结合docker安装smokeping

[复制链接]

尚未签到

发表于 2018-5-30 10:51:36 | 显示全部楼层 |阅读模式
  本次介绍ansible的paly book结合docker进行虚拟机里安装2.6.8版本smokeping(apache版本是2.4.7)。

  docker版本
09:26:53 # docker version
Client version: 0.11.1
Client API version: 1.11
Go version (client): go1.2.1
Git commit (client): fb99f99/0.11.1
Server version: 0.11.1
Server API version: 1.11
Git commit (server): fb99f99/0.11.1
Go version (server): go1.2.1
Last stable version: 1.1.2, please update docker  ansible版本

09:28:13 # ansible --version
ansible 1.4.3  1、查看docker已有镜像
09:25:55 # docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              3.0                 6cee55276528        9 weeks ago         369.8 MB
centos5             3.0                 e08d23b09189        9 weeks ago         840.9 MB
centos6             3.0                 e94a3b24a19b        9 weeks ago         415.9 MB  可以看到有3个镜像,1个是ubuntu,1个centos5,1个centos6.我这里打算使用centos6来弄。
  2、加载新容器
09:31:01 # time  docker inspect $(docker run -d -p 22 -p 80:80 --name="smokeping" centos6:3.0 /usr/sbin/sshd -D)|grep -i address|awk -F '"' '{print $4}'
172.17.0.5
real0m4.737s
user0m0.038s
sys0m0.054s  可以看到4秒就加载新容器完成,并且镜像为centos6系统,容器名为smokeping,开启了ssh服务,并且暴漏了22与80端口。
  下面在从后端看看本机都运行了哪些容器
09:31:29 # docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                                       NAMES
56b70c31a07e        centos6:3.0         /usr/sbin/sshd -D   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 0.0.0.0:49156->22/tcp   smokeping           
846efb9e4d7a        ubuntu:3.0          /usr/sbin/sshd -D   12 days ago          Up 4 days           0.0.0.0:49167->22/tcp                       ubuntu-test1        
b9a9e6f2caed        centos6:3.0         /usr/sbin/sshd -D   3 weeks ago          Up 4 days           0.0.0.0:49166->22/tcp                       zabbix-server      
978fff134b18        centos6:3.0         /usr/sbin/sshd -D   4 weeks ago          Up 4 days           0.0.0.0:49165->22/tcp                       centos6-test5  下面是ansible安装smokeping的部分
  3、ansible安装smokeping的信息

09:34:06 # cat smokeping_install/vars/main.yml
smokeping_dir: /usr/local/smokeping
smokeping_version: 2.6.8
smokeping_user: admin
smokeping_passwd: '()TF%penst*&MedHU'  可以看到smokeping安装目录是/usr/local/smokeping,安装版本是2.6.8,登陆的账户是admin,登陆密码是()TF%penst*&MedHU
  4、下面是安装smokeping的playbook结构
09:36:25 # tree smokeping_*
smokeping_delete
├── files
│   └── delete_smokeping.sh
├── handlers
├── meta
│   └── main.yml
├── tasks
│   ├── copy.yml
│   ├── delete.yml
│   └── main.yml
├── templates
└── vars
    ├── main.xml
    ├── main.yml
    └── vars
        └── main.yml
smokeping_install
├── files
│   ├── rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
│   └── smokeping.tar.gz
├── handlers
├── meta
│   └── main.yml
├── tasks
│   ├── copy.yml
│   ├── delete.yml
│   ├── install.yml
│   └── main.yml
├── templates
│   ├── config
│   └── smokeping.conf
└── vars
    └── main.yml
13 directories, 18 files  5、playbook安装smokeping的内容是
09:37:27 # cat smokeping_install.yml
---
- hosts: "`host`"
  remote_user: "`user`"
  gather_facts: True
  roles:
    - common
    - pcre_install
    - apache_install
    - smokeping_install  6、playbook删除smokeping的内容是
09:38:01 # cat smokeping_delete.yml
---
- hosts: "`host`"
  remote_user: "`user`"
  gather_facts: True
  roles:
    - apache_delete
    - pcre_delete
    - smokeping_delete  下面是安装与测试过程
  7、把docker新容器smokeping的ip加入到ansible的hosts里
echo "172.17.0.5">>/etc/ansible/hosts  8、安装smokeping
09:39:10 # time ansible-playbook smokeping_install.yml --extra-vars "host=172.17.0.5 user=root" -k
SSH password:
PLAY [172.17.0.5] *************************************************************
GATHERING FACTS ***************************************************************
ok: [172.17.0.5]
TASK: [common | Install initializtion require software] ***********************
changed: [172.17.0.5]
TASK: [pcre_install | Copy Pcre Software To Redhat Client] ********************
changed: [172.17.0.5]
TASK: [pcre_install | Uncompression Pcre Software In Redhat Client] ***********
changed: [172.17.0.5]
TASK: [pcre_install | Delete Pcre Software In Redhat Client] ******************
changed: [172.17.0.5]
TASK: [apache_install | Copy Apache Software To Redhat Client] ****************
changed: [172.17.0.5] => (item=httpd-2.4.7.tar.gz)
changed: [172.17.0.5] => (item=libiconv.tar.gz)
TASK: [apache_install | Create Apache User In Redhat Client] ******************
changed: [172.17.0.5]
TASK: [apache_install | Uncompression Apache Software To Redhat Client] *******
changed: [172.17.0.5]
TASK: [apache_install | Copy Apache Config To Redhat Client] ******************
changed: [172.17.0.5]
TASK: [apache_install | Copy Apache Vhost Config To Redhat Client] ************
changed: [172.17.0.5]
TASK: [apache_install | Copy Apache Start Service Script  To Redhat Client] ***
changed: [172.17.0.5]
TASK: [apache_install | Create Lib Install Dir] *******************************
ok: [172.17.0.5]
TASK: [apache_install | Check Apache Iconv In Redhat Client] ******************
changed: [172.17.0.5]
TASK: [apache_install | Install Apache Iconv In Redhat Client] ****************
changed: [172.17.0.5]
TASK: [apache_install | Check Lib In Config In Redhat Client] *****************
failed: [172.17.0.5] => {"changed": true, "cmd": "grep -c /usr/local/lib/ /etc/ld.so.conf ", "delta": "0:00:00.006524", "end": "2014-08-11 09:40:48.822372", "item": "", "rc": 1, "start": "2014-08-11 09:40:48.815848"}
stdout: 0
...ignoring
TASK: [apache_install | Install Apache Iconv In Redhat Client] ****************
changed: [172.17.0.5]
TASK: [apache_install | Create Apache Dir] ************************************
changed: [172.17.0.5] => (item=/data/webroot/apache)
changed: [172.17.0.5] => (item=/data/webroot/apache/logs)
changed: [172.17.0.5] => (item=/data/webroot/apache/vhost)
TASK: [apache_install | Install Check Script In Redhat Client] ****************
changed: [172.17.0.5]
TASK: [apache_install | Create Index Html To Redhat Client] *******************
changed: [172.17.0.5]
TASK: [apache_install | Start Apache Service In Redhat Client] ****************
changed: [172.17.0.5]
TASK: [apache_install | Add Boot Start Apache Service In Redhat Client] *******
changed: [172.17.0.5]
TASK: [apache_install | Delete Apache compression Software In Redhat Client] ***
changed: [172.17.0.5]
TASK: [smokeping_install | Create Smokeping Install Dir] **********************
changed: [172.17.0.5]
TASK: [smokeping_install | Copy Smokeping Software To Redhat Client] **********
changed: [172.17.0.5] => (item=rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm)
changed: [172.17.0.5] => (item=smokeping.tar.gz)
TASK: [smokeping_install | Install Epel Yum Repo] *****************************
changed: [172.17.0.5]
TASK: [smokeping_install | Install Require Software] **************************
changed: [172.17.0.5]
TASK: [smokeping_install | Uncompression  Smokeping] **************************
changed: [172.17.0.5]
TASK: [smokeping_install | Copy Smokeping Config To Redhat Client] ************
changed: [172.17.0.5]
TASK: [smokeping_install | Copy Smokeping Httpd Config To Redhat Client] ******
changed: [172.17.0.5]
TASK: [smokeping_install | Check Boot Start In Redhat Client] *****************
failed: [172.17.0.5] => {"changed": true, "cmd": "grep -c '/usr/local/smokeping/bin/smokeping --logfile=/var/log/smokeping.log 2>&1 &' /etc/rc.local ", "delta": "0:00:00.007325", "end": "2014-08-11 09:46:03.045378", "item": "", "rc": 1, "start": "2014-08-11 09:46:03.038053"}
stdout: 0
...ignoring
TASK: [smokeping_install | Add Boot Start In Redhat Client] *******************
changed: [172.17.0.5]
TASK: [smokeping_install | Modify Smokeping Dir Permission In Redhat Client] ***
changed: [172.17.0.5]
TASK: [smokeping_install | Start Smokeping Service In Redhat Client] **********
changed: [172.17.0.5]
TASK: [smokeping_install | Restart Apache Service In Redhat Client] ***********
changed: [172.17.0.5]
TASK: [smokeping_install | Delete Installed File] *****************************
changed: [172.17.0.5]
PLAY RECAP ********************************************************************
172.17.0.5                 : ok=35   changed=33   unreachable=0    failed=0   

real6m52.934s
user0m15.104s
sys0m1.632s  花费6分52秒完成,花费时间多的主要是yum安装基础库与使用epel安装smokeping依赖库。
  9、安装后测试
DSC0000.jpg

  查看smokeping
DSC0001.jpg

  由于我做了安全认证,需要输入账户与密码,这个账户与密码就上文第3步的账户与密码
DSC0002.jpg

  然后默认的其他网络监控(包括1、2、3线电信、移动、联通、铁通与教育网的节点监控已经做好)
DSC0003.jpg

  如果有其他的监控需要自己来添加即可。
  10、删除
09:46:08 # time ansible-playbook smokeping_delete.yml --extra-vars "host=172.17.0.5 user=root" -k
SSH password:
PLAY [172.17.0.5] *************************************************************
GATHERING FACTS ***************************************************************
ok: [172.17.0.5]
TASK: [apache_delete | Stop Httpd Service In RedHat Client] *******************
changed: [172.17.0.5]
TASK: [apache_delete | Delete Boot Start In RedHat Client] ********************
changed: [172.17.0.5]
TASK: [apache_delete | Delete Apache Dir In RedHat Client] ********************
changed: [172.17.0.5]
TASK: [apache_delete | Delete Apache Service Script In RedHat Client] *********
changed: [172.17.0.5]
TASK: [apache_delete | Delete Apache User] ************************************
changed: [172.17.0.5]
TASK: [pcre_delete | Delete Pcre] *********************************************
changed: [172.17.0.5]
TASK: [smokeping_delete | Stop Smokeping Service In Redhat Client] ************
changed: [172.17.0.5]
TASK: [smokeping_delete | Delete Smokeping Dir In Redhat Client] **************
changed: [172.17.0.5]
TASK: [smokeping_delete | Delete Boot Start In Redhat Client] *****************
changed: [172.17.0.5]
PLAY RECAP ********************************************************************
172.17.0.5                 : ok=10   changed=9    unreachable=0    failed=0   

real0m9.326s
user0m2.914s
sys0m0.446s  11、删除后测试
09:59:45 # ssh 172.17.0.5
root@172.17.0.5's password:
root@56b70c31a07e:~
09:59:57 # ifconfig
eth0      Link encap:Ethernet  HWaddr A6:80:57:2D:D3:F1  
          inet addr:172.17.0.5  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::a480:57ff:fe2d:d3f1/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:84520 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86385 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:69075188 (65.8 MiB)  TX bytes:9400662 (8.9 MiB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:168 (168.0 b)  TX bytes:168 (168.0 b)
root@56b70c31a07e:~
09:59:59 # ps -ef|grep httpd
root      1017  1002  0 10:00 pts/0    00:00:00 grep httpd
root@56b70c31a07e:~
10:00:04 # ps -ef|grep smokeping
root      1019  1002  0 10:00 pts/0    00:00:00 grep smokeping
root@56b70c31a07e:~
10:00:07 # ll /usr/local/
total 40
drwxr-xr-x 2 root root 4096 Sep 23  2011 bin
drwxr-xr-x 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x 2 root root 4096 Sep 23  2011 games
drwxr-xr-x 2 root root 4096 Sep 23  2011 include
drwxr-xr-x 2 root root 4096 Aug 11 09:40 lib
drwxr-xr-x 2 root root 4096 Sep 23  2011 lib64
drwxr-xr-x 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x 5 root root 4096 Sep 23  2011 share
drwxr-xr-x 2 root root 4096 Sep 23  2011 src
root@56b70c31a07e:~
10:00:11 # cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local  如果大家想使用我的例子,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/smokeping_install),然后放到/etc/ansible目录里,下面是内容
DSC0004.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-482989-1-1.html 上篇帖子: RHEL7 四步安装 DOCKER 下篇帖子: Docker container link
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表