首页 文章 精选 留言 我的

精选列表

搜索[运维自动化],共10004篇文章
优秀的个人博客,低调大师

运维自动化之Saltstack使用详解

概要 saltstack是基于Python开发的C/S架构的一款批量管理工具,底层采用动态的连接总线(ZeroMQ消息队列pub/sub方式通信),使用ssl证书签发的方式进行认证管理,使其可以用于编配, 远程执行, 配置管理等等。部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯。号称世界上最快的消息队列ZeroMQ使得saltstack非常快速的管理大量服务器,采用RSA Key方式确认身份,传输采用AES加密,安全性也非常有保障。 Saltstack使用Python开发,是一个非常简单易用和轻量级的管理工具。由Master和Minion构成,通过ZeroMQ进行通信。 SaltStack基于Python语言实现,结合轻量级消息队列(ZeroMQ)与Python第三方模块(Pyzmq、PyCrypto、Pyjinjia2、python-msgpack和PyYAML等)构建。有如下特性: (1)、部署简单、方便; (2)、支持大部分UNIX/Linux及Windows环境; (3)、主从集中化管理; (4)、配置简单、功能强大、扩展性强; (5)、主控端(master)和被控端(minion)基于证书认证,安全可靠; (6)、支持API及自定义模块,可通过Python轻松扩展。 Saltstack的master端监听4505与4506端口,4505为salt的消息发布系统,4506为salt客户端与服务端通信的端口;salt客户端程序不监听端口,客户端启动后,会主动连接master端注册,然后一直保持该TCP连接,master通过这条TCP连接对客户端控制,如果连接断开,master对客户端就无能为力了。当然,客户端若检查到断开后会定期的一直连接master端的。 核心功能 1、使命令发送到远程系统是并行的而不是串行的 2、使用安全加密的协议 3、使用最小最快的网络载荷 4、提供简单的编程接口 架构 saltstack是基于C/S服务模式,在该架构中,服务器端叫做Master,客户端叫做Minion。传统的C/S模式我们这样理解,客户端发送请求给服务器端,服务器端接受到来自客户端的请求并处理完成后再返回客户端。 在saltstack架构中,不仅有传统的C/S服务模式,而且有消息队列中的发布与订阅(pub/sub)服务模式。目前我们一般用其C/S架构做批量管理。 1)Master:控制中心,salt命令运行和资源状态管理 2)Minion:需要管理的客户端机器,会主动去连接Mater端,并从Master端得到资源状态 3)信息,同步资源管理信息 4)States:配置管理的指令集 5)Modules:在命令行中和配置文件中使用的指令模块,可以在命令行中运行 6)Grains:minion端的变量,静态的 7)Pillar:minion端的变量,动态的比较私密的变量,可以通过配置文件实现同步minions定义 8)highstate:为minion端下发永久添加状态,从sls配置文件读取.即同步状态配置 9)salt_schedule:会自动保持客户端配置 Saltstack安装 安装方式有四种,下面通过一个案例简单介绍在CentOS6.8上进行SaltStack部署。 (1)yum方式安装(采用saltstack源)推荐这种方式,简单粗暴。注意没有配置saltstack源的,请先配置saltstack源。 Version 7: rpm --importhttps://repo.saltstack.com/yum/redhat/7/x86_64/latest/SALTSTACK-GPG-KEY.pub Version 6: rpm --import https://repo.saltstack.com/yum/redhat/6/x86_64/latest/SALTSTACK-GPG-KEY.pub Save the following file to/etc/yum.repos.d/saltstack.repo: Version 7 and 6: [saltstack-repo] name=SaltStackrepoforRHEL/CentOS$releasever baseurl=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest enabled=1 gpgcheck=1 gpgkey=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/SALTSTACK-GPG-KEY.pub 安装好saltstack源后,用yum命令来检查是否添加到源列表。 yumrepolistMaster端安装: yum -y install salt-master Minon端安装: yum -y install salt-minion 配置并启动Saltstack Salt的配置非常简单。默认的master配置就可以在大多数情况下运行。仅仅需要更改的是minion,在minion配置文件中设置master的地址。 The configuration fileswill be installed to/etc/saltand are named after the respective components,/etc/salt/master, and/etc/salt/minion. MASTER配置 默认Salt master监听所有网卡接口(0.0.0.0)的4505和4506端口. 如果需要指定监听IP, 通过/etc/salt/master配置文件中的"interface"指令进行如下修改: -#interface:0.0.0.0 +interface:10.0.0.1#此处是server端监听的地址。 auto_accept:True#此处是自动接受客户端发送过来的key,如果服务器很多的话,需要开启该功能。 MINION配置 尽管Salt Minion有许多配置选项,但配置Minion还是非常简单的. 默认的配置Minion会尝试连接DNS名为"salt"的master,如果minion解析到的地址正确,就无需再做配置. 如果DNS名为"salt"并不能解析到本地正确的Master地址,需要通过如下方法修改/etc/salt/minion配置文件中的"master"指令: -#master:salt +master:10.0.0.1#这里改成你的master服务器地址 id:web01#建议这里修改成主机名,便于master端分辨 #在配置文件末尾加入下面内容,每隔5分钟自动同步master配置,效果等同于在客户端执行salt-callstate.highstate或在server端执行salt'*'state.highstate schedule: highstate: function:state.highstate minutes:5 更新完配置后,需要重启Salt minion以使配置生效. 运行Saltstack 1.前台启动master(如果要以daemon方式启动,请指定-d参数<salt-master-d>): salt-master 2.前台启动minion(如果要以daemon方式启动,请指定-d参数<salt-minion-d>): salt-minion 运行有问题? 排除Salt故障最简单的方法是在前台运行master和minion,同时把loglevel设为``debug`` salt-master--log-level=debug 以普通(非root)用户运行: 想要使用其他用户身份运行Salt,参见:conf_master:`user`参数在master配置文件中。 Additionally, ownership, and permissions need to be set suchthat the desired user can read from and write to the following directories (andtheir subdirectories, where applicable): /etc/salt /var/cache/salt /var/log/salt /var/run/salt 更多关于如何使用非特权用户运行salt的信息可以在这里找到。 salt-key证书管理: master端证书存放路径:/etc/salt/pki/master/minions 注意:如果细心的话,你会发现小写字母针对的单一对象,大写都是针对全体。比如 -l显示单一key,-L显示所有key;-a 接受指定key,而-A 就是接受所有key。 saltstack认证原理: 1)、minion在第一次启动时,会在/etc/salt/pki/minion/(该路径在/etc/salt/minion里面设置)下自动生成minion.pem(private key)和 minion.pub(public key),然后将 minion.pub发送给master。 2)、master在接收到minion的publickey后,通过salt-key命令accept minion public key,这样在master的/etc/salt/pki/master/minions下的将会存放以minion id命名的 public key,然后master就能对minion发送指令了。 salt-key-L#查询所有接收到的证书 salt-key-a<证书名>#接收单个证书 salt-key-A#接受所有证书 salt-key-d<证书名>#删除单个证书 salt-key-D#删除所有证书 Salt在Master和Minion之间的通讯采用AES加密. 这就确保了发送给minions的命令不会被篡改, Master和Minion之间的通讯认证通过信任的已接受的key进行管理. 在发送给Minion之前,需要确保minion的key已经被Master所接受. 运行``salt-key``命令将列出Salt Master已知的所有keys. [root@master~]#salt-key-L UnacceptedKeys: alpha bravo charlie delta AcceptedKeys: [root@master~]#salt-key–A-y [root@master~]#salt-key-L UnacceptedKeys: AcceptedKeys: alpha bravo charlie delta 发送test.ping指令 [root@moban~]#salt'*'test.ping moban2: True moban1: True 限于篇幅太长,请大家移步这里进行下载查看,谢谢! 下载地址:http://down.51cto.com/data/2306388 本文转自 linuxzkq 51CTO博客,原文链接:http://blog.51cto.com/linuxzkq/1925299

优秀的个人博客,低调大师

运维自动化之ansible playbook结合docker安装smokeping

本次介绍ansible的paly book结合docker进行虚拟机里安装2.6.8版本smokeping(apache版本是2.4.7)。 docker版本 1 2 3 4 5 6 7 8 9 10 09:26:53 #dockerversion Clientversion:0.11.1 ClientAPIversion:1.11 Goversion(client):go1.2.1 Gitcommit(client):fb99f99 /0 .11.1 Serverversion:0.11.1 ServerAPIversion:1.11 Gitcommit(server):fb99f99 /0 .11.1 Goversion(server):go1.2.1 Laststableversion:1.1.2,pleaseupdatedocker ansible版本 1 2 09:28:13 #ansible--version ansible1.4.3 1、查看docker已有镜像 1 2 3 4 5 09:25:55 #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE ubuntu3.06cee552765289weeksago369.8MB centos53.0e08d23b091899weeksago840.9MB centos63.0e94a3b24a19b9weeksago415.9MB 可以看到有3个镜像,1个是ubuntu,1个centos5,1个centos6.我这里打算使用centos6来弄。 2、加载新容器 1 2 3 4 5 6 09:31:01 #timedockerinspect$(dockerrun-d-p22-p80:80--name="smokeping"centos6:3.0/usr/sbin/sshd-D)|grep-iaddress|awk-F'"''{print$4}' 172.17.0.5 real 0m4.737s user 0m0.038s sys 0m0.054s 可以看到4秒就加载新容器完成,并且镜像为centos6系统,容器名为smokeping,开启了ssh服务,并且暴漏了22与80端口。 下面在从后端看看本机都运行了哪些容器 1 2 3 4 5 6 09:31:29 #dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 56b70c31a07ecentos6:3.0 /usr/sbin/sshd -DAboutaminuteagoUpAboutaminute0.0.0.0:80->80 /tcp ,0.0.0.0:49156->22 /tcp smokeping 846efb9e4d7aubuntu:3.0 /usr/sbin/sshd -D12daysagoUp4days0.0.0.0:49167->22 /tcp ubuntu-test1 b9a9e6f2caedcentos6:3.0 /usr/sbin/sshd -D3weeksagoUp4days0.0.0.0:49166->22 /tcp zabbix-server 978fff134b18centos6:3.0 /usr/sbin/sshd -D4weeksagoUp4days0.0.0.0:49165->22 /tcp centos6-test5 下面是ansible安装smokeping的部分 3、ansible安装smokeping的信息 1 2 3 4 5 09:34:06 #catsmokeping_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结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 09:36:25 #treesmokeping_* 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 13directories,18files 5、playbook安装smokeping的内容是 1 2 3 4 5 6 7 8 9 10 09:37:27 #catsmokeping_install.yml --- -hosts: "`host`" remote_user: "`user`" gather_facts:True roles: -common -pcre_install -apache_install -smokeping_install 6、playbook删除smokeping的内容是 1 2 3 4 5 6 7 8 9 09:38:01 #catsmokeping_delete.yml --- -hosts: "`host`" remote_user: "`user`" gather_facts:True roles: -apache_delete -pcre_delete -smokeping_delete 下面是安装与测试过程 7、把docker新容器smokeping的ip加入到ansible的hosts里 1 echo "172.17.0.5" >> /etc/ansible/hosts 8、安装smokeping 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 09:39:10 #timeansible-playbooksmokeping_install.yml--extra-vars"host=172.17.0.5user=root"-k SSHpassword: PLAY[172.17.0.5]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.5] TASK:[common|Installinitializtionrequiresoftware]*********************** changed:[172.17.0.5] TASK:[pcre_install|CopyPcreSoftwareToRedhatClient]******************** changed:[172.17.0.5] TASK:[pcre_install|UncompressionPcreSoftwareInRedhatClient]*********** changed:[172.17.0.5] TASK:[pcre_install|DeletePcreSoftwareInRedhatClient]****************** changed:[172.17.0.5] TASK:[apache_install|CopyApacheSoftwareToRedhatClient]**************** changed:[172.17.0.5]=>(item=httpd-2.4.7. tar .gz) changed:[172.17.0.5]=>(item=libiconv. tar .gz) TASK:[apache_install|CreateApacheUserInRedhatClient]****************** changed:[172.17.0.5] TASK:[apache_install|UncompressionApacheSoftwareToRedhatClient]******* changed:[172.17.0.5] TASK:[apache_install|CopyApacheConfigToRedhatClient]****************** changed:[172.17.0.5] TASK:[apache_install|CopyApacheVhostConfigToRedhatClient]************ changed:[172.17.0.5] TASK:[apache_install|CopyApacheStartServiceScriptToRedhatClient]*** changed:[172.17.0.5] TASK:[apache_install|CreateLibInstallDir]******************************* ok:[172.17.0.5] TASK:[apache_install|CheckApacheIconvInRedhatClient]****************** changed:[172.17.0.5] TASK:[apache_install|InstallApacheIconvInRedhatClient]**************** changed:[172.17.0.5] TASK:[apache_install|CheckLibInConfigInRedhatClient]***************** 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-1109:40:48.822372" , "item" : "" , "rc" :1, "start" : "2014-08-1109:40:48.815848" } stdout:0 ...ignoring TASK:[apache_install|InstallApacheIconvInRedhatClient]**************** changed:[172.17.0.5] TASK:[apache_install|CreateApacheDir]************************************ 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|InstallCheckScriptInRedhatClient]**************** changed:[172.17.0.5] TASK:[apache_install|CreateIndexHtmlToRedhatClient]******************* changed:[172.17.0.5] TASK:[apache_install|StartApacheServiceInRedhatClient]**************** changed:[172.17.0.5] TASK:[apache_install|AddBootStartApacheServiceInRedhatClient]******* changed:[172.17.0.5] TASK:[apache_install|DeleteApachecompressionSoftwareInRedhatClient]*** changed:[172.17.0.5] TASK:[smokeping_install|CreateSmokepingInstallDir]********************** changed:[172.17.0.5] TASK:[smokeping_install|CopySmokepingSoftwareToRedhatClient]********** 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|InstallEpelYumRepo]***************************** changed:[172.17.0.5] TASK:[smokeping_install|InstallRequireSoftware]************************** changed:[172.17.0.5] TASK:[smokeping_install|UncompressionSmokeping]************************** changed:[172.17.0.5] TASK:[smokeping_install|CopySmokepingConfigToRedhatClient]************ changed:[172.17.0.5] TASK:[smokeping_install|CopySmokepingHttpdConfigToRedhatClient]****** changed:[172.17.0.5] TASK:[smokeping_install|CheckBootStartInRedhatClient]***************** failed:[172.17.0.5]=>{ "changed" : true , "cmd" : "grep-c'/usr/local/smokeping/bin/smokeping--logfile=/var/log/smokeping.log2>&1&'/etc/rc.local" , "delta" : "0:00:00.007325" , "end" : "2014-08-1109:46:03.045378" , "item" : "" , "rc" :1, "start" : "2014-08-1109:46:03.038053" } stdout:0 ...ignoring TASK:[smokeping_install|AddBootStartInRedhatClient]******************* changed:[172.17.0.5] TASK:[smokeping_install|ModifySmokepingDirPermissionInRedhatClient]*** changed:[172.17.0.5] TASK:[smokeping_install|StartSmokepingServiceInRedhatClient]********** changed:[172.17.0.5] TASK:[smokeping_install|RestartApacheServiceInRedhatClient]*********** changed:[172.17.0.5] TASK:[smokeping_install|DeleteInstalledFile]***************************** changed:[172.17.0.5] PLAYRECAP******************************************************************** 172.17.0.5:ok=35changed=33unreachable=0failed=0 real 6m52.934s user 0m15.104s sys 0m1.632s 花费6分52秒完成,花费时间多的主要是yum安装基础库与使用epel安装smokeping依赖库。 9、安装后测试 查看smokeping 由于我做了安全认证,需要输入账户与密码,这个账户与密码就上文第3步的账户与密码 然后默认的其他网络监控(包括1、2、3线电信、移动、联通、铁通与教育网的节点监控已经做好) 如果有其他的监控需要自己来添加即可。 10、删除 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 09:46:08 #timeansible-playbooksmokeping_delete.yml--extra-vars"host=172.17.0.5user=root"-k SSHpassword: PLAY[172.17.0.5]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.5] TASK:[apache_delete|StopHttpdServiceInRedHatClient]******************* changed:[172.17.0.5] TASK:[apache_delete|DeleteBootStartInRedHatClient]******************** changed:[172.17.0.5] TASK:[apache_delete|DeleteApacheDirInRedHatClient]******************** changed:[172.17.0.5] TASK:[apache_delete|DeleteApacheServiceScriptInRedHatClient]********* changed:[172.17.0.5] TASK:[apache_delete|DeleteApacheUser]************************************ changed:[172.17.0.5] TASK:[pcre_delete|DeletePcre]********************************************* changed:[172.17.0.5] TASK:[smokeping_delete|StopSmokepingServiceInRedhatClient]************ changed:[172.17.0.5] TASK:[smokeping_delete|DeleteSmokepingDirInRedhatClient]************** changed:[172.17.0.5] TASK:[smokeping_delete|DeleteBootStartInRedhatClient]***************** changed:[172.17.0.5] PLAYRECAP******************************************************************** 172.17.0.5:ok=10changed=9unreachable=0failed=0 real 0m9.326s user 0m2.914s sys 0m0.446s 11、删除后测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 09:59:45 #ssh172.17.0.5 root@172.17.0.5'spassword: root@56b70c31a07e:~ 09:59:57 #ifconfig eth0Linkencap:EthernetHWaddrA6:80:57:2D:D3:F1 inetaddr:172.17.0.5Bcast:0.0.0.0Mask:255.255.0.0 inet6addr:fe80::a480:57ff:fe2d:d3f1 /64 Scope:Link UPBROADCASTRUNNINGMTU:1500Metric:1 RXpackets:84520errors:0dropped:0overruns:0frame:0 TXpackets:86385errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:69075188(65.8MiB)TXbytes:9400662(8.9MiB) loLinkencap:LocalLoopback inetaddr:127.0.0.1Mask:255.0.0.0 inet6addr:::1 /128 Scope:Host UPLOOPBACKRUNNINGMTU:16436Metric:1 RXpackets:2errors:0dropped:0overruns:0frame:0 TXpackets:2errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:0 RXbytes:168(168.0b)TXbytes:168(168.0b) root@56b70c31a07e:~ 09:59:59 #ps-ef|grephttpd root10171002010:00pts /0 00:00:00 grep httpd root@56b70c31a07e:~ 10:00:04 #ps-ef|grepsmokeping root10191002010:00pts /0 00:00:00 grep smokeping root@56b70c31a07e:~ 10:00:07 #ll/usr/local/ total40 drwxr-xr-x2rootroot4096Sep232011bin drwxr-xr-x2rootroot4096Sep232011etc drwxr-xr-x2rootroot4096Sep232011games drwxr-xr-x2rootroot4096Sep232011include drwxr-xr-x2rootroot4096Aug1109:40lib drwxr-xr-x2rootroot4096Sep232011lib64 drwxr-xr-x2rootroot4096Sep232011libexec drwxr-xr-x2rootroot4096Sep232011sbin drwxr-xr-x5rootroot4096Sep232011share drwxr-xr-x2rootroot4096Sep232011src root@56b70c31a07e:~ 10:00:11 #cat/etc/rc.local #!/bin/sh # #Thisscriptwillbeexecuted*after*alltheotherinitscripts. #Youcanputyourowninitializationstuffinhereifyoudon't #wanttodothefullSysVstyleinitstuff. touch /var/lock/subsys/local 如果大家想使用我的例子,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/smokeping_install),然后放到/etc/ansible目录里,下面是内容 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1538444,如需转载请自行联系原作者

优秀的个人博客,低调大师

运维自动化之ansible playbook结合docker安装redis主从

上次给大家介绍了ansible结合docker安装smokeping(地址http://dl528888.blog.51cto.com/2382721/1538444),现在在介绍一下ansible结合docker安装redis主从(redis版本是2.6.17)。 目前ansible使用的人比较多,docker也最近比较流行,而且做测试的话,ansible+docker是个很好的组合。本文主要是介绍如何使用ansible的playbook安装redis主从,可以自动的做好主从,这样节省安装时间、减少问题产生。 docker版本 1 2 3 4 5 6 7 8 9 10 09:49:09 #dockerversion Clientversion:0.11.1 ClientAPIversion:1.11 Goversion(client):go1.2.1 Gitcommit(client):fb99f99 /0 .11.1 Serverversion:0.11.1 ServerAPIversion:1.11 Gitcommit(server):fb99f99 /0 .11.1 Goversion(server):go1.2.1 Laststableversion:1.1.2,pleaseupdatedocker ansible版本 1 2 09:51:55 #ansible--version ansible1.4.3 1、查看已有的docker镜像 1 2 3 4 5 09:39:26 #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE ubuntu3.06cee552765289weeksago369.8MB centos53.0e08d23b091899weeksago840.9MB centos63.0e94a3b24a19b9weeksago415.9MB 2、查看当前运行的docker容器 1 2 3 4 5 6 09:39:47 #dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 846efb9e4d7aubuntu:3.0 /usr/sbin/sshd -D2weeksagoUp6days0.0.0.0:49167->22 /tcp ubuntu-test1 b9a9e6f2caedcentos6:3.0 /usr/sbin/sshd -D3weeksagoUp6days0.0.0.0:49166->22 /tcp zabbix-server 978fff134b18centos6:3.0 /usr/sbin/sshd -D5weeksagoUp6days0.0.0.0:49165->22 /tcp centos6-test5 root@ip-10-10-10-10: /etc/ansible/roles/redis_install/templates 3、加载测试容器 由于是做redis主从,所以需要2个容器 1 2 3 4 5 6 7 8 9 10 11 12 13 09:39:50 #timedockerinspect$(dockerrun-d-p22--name="redis-master"centos6:3.0/usr/sbin/sshd-D)|grep-iaddress|awk-F'"''{print$4}' 172.17.0.5 real 0m6.369s user 0m0.036s sys 0m0.049s root@ip-10-10-10-10: /etc/ansible/roles/redis_install/templates 09:40:25 #timedockerinspect$(dockerrun-d-p22--name="redis-slave"centos6:3.0/usr/sbin/sshd-D)|grep-iaddress|awk-F'"''{print$4}' 172.17.0.6 real 0m12.567s user 0m0.047s sys 0m0.060s 然后把新容器的ip加入到ansible的hosts里 1 2 3 4 5 root@ip-10-10-10-10: /etc/ansible/roles/redis_install/templates 09:40:46 #echo"172.17.0.5">>/etc/ansible/hosts root@ip-10-10-10-10: /etc/ansible/roles/redis_install/templates 09:40:58 #echo"172.17.0.6">>/etc/ansible/hosts root@ip-10-10-10-10: /etc/ansible/roles/redis_install/templates 4、ansible安装redis的信息 1 2 3 4 5 6 7 09:52:11 #cat/etc/ansible/roles/redis_install/vars/main.yml redis_dir: /data redis_version:2.6.17 redis_port:6379 redis_conf_dir: /data/redis-2 .6.17 /conf redis_db_dir: /data/redis-2 .6.17 /db redis_log_dir: /data/redis-2 .6.17 /log 5、下面是redis的playbook结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 09:55:12 #tree/etc/ansible/roles/redis_install/etc/ansible/roles/redis_delete /etc/ansible/roles/redis_install ├──files │└──redis-2.6.17. tar .gz ├──handlers ├──meta │└──main.yml ├──tasks │├──copy.yml │├──delete.yml │├── install .yml │└──main.yml ├──templates │└──redis.conf └──vars └──main.yml /etc/ansible/roles/redis_delete ├──files ├──handlers ├──meta │└──main.yml ├──tasks │├──delete.yml │└──main.yml ├──templates │└──delete_redis.sh └──vars └──main.yml 12directories,13files 6、playbook安装redis的内容是 1 2 3 4 5 6 7 8 09:57:09 #catredis_install.yml --- -hosts: "`host`" remote_user: "`user`" gather_facts:True roles: -common -redis_install 7、playbook删除redis的内容是 1 2 3 4 5 6 7 09:57:31 #catredis_delete.yml --- -hosts: "`host`" remote_user: "`user`" gather_facts:True roles: -redis_delete 下面是安装redis主从 8、安装redis master 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 09:43:11 #timeansible-playbookredis_install.yml--extra-vars"host=172.17.0.5user=root"-k SSHpassword: PLAY[172.17.0.5]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.5] TASK:[common|Installinitializtionrequiresoftware]*********************** changed:[172.17.0.5] TASK:[redis_install|CopyRedisSoftwareToRedhatClient]****************** ok:[172.17.0.5] TASK:[redis_install|CreateRedisInstallDir]****************************** ok:[172.17.0.5] TASK:[redis_install|UncompressionRedisSoftwareToRedhatClient]********* changed:[172.17.0.5] TASK:[redis_install|CopyRedisConfigToRedhatClient]******************** changed:[172.17.0.5] TASK:[redis_install|CreateSoftLinkInRedhatClient]********************* changed:[172.17.0.5]=>(item=redis-cli) changed:[172.17.0.5]=>(item=redis-server) TASK:[redis_install|CheckBootStartInRedhatClient]********************* failed:[172.17.0.5]=>{ "changed" : true , "cmd" : "grep-c'/usr/bin/redis-server/data/redis-2.6.17/conf/redis_6379.conf'/etc/rc.local" , "delta" : "0:00:00.007160" , "end" : "2014-08-1309:45:18.660617" , "item" : "" , "rc" :1, "start" : "2014-08-1309:45:18.653457" } stdout:0 ...ignoring TASK:[redis_install|AddBootStartInRedhatClient]*********************** changed:[172.17.0.5] TASK:[redis_install|StartRedisServiceInRedhatClient]****************** changed:[172.17.0.5] TASK:[redis_install|DeleteRediscompressionSoftwareInRedhatClient]**** changed:[172.17.0.5] PLAYRECAP******************************************************************** 172.17.0.5:ok=11changed=8unreachable=0failed=0 real 0m12.757s user 0m3.453s sys 0m0.497s 9、查看redis master安装情况 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 09:48:39 #ssh172.17.0.5 root@172.17.0.5'spassword: Lastlogin:WedAug1309:45:282014from172.17.42.1 root@06762530db8c:~ 09:48:43 #ps-ef|grepredis root2941009:45?00:00:00 /usr/bin/redis-server /data/redis-2 .6.17 /conf/redis_6379 .conf root343329009:48pts /0 00:00:00 grep redis root@06762530db8c:~ 09:48:46 #cat/etc/rc.local #!/bin/sh # #Thisscriptwillbeexecuted*after*alltheotherinitscripts. #Youcanputyourowninitializationstuffinhereifyoudon't #wanttodothefullSysVstyleinitstuff. touch /var/lock/subsys/local /usr/bin/redis-server /data/redis-2 .6.17 /conf/redis_6379 .conf root@06762530db8c:~ 09:48:52 #redis-cli-h172.17.0.5-p6379 redis172.17.0.5:6379>keys* (emptylistor set ) redis172.17.0.5:6379> 10、安装redis slave 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 09:45:20 #timeansible-playbookredis_install.yml--extra-vars"host=172.17.0.6user=rootredis_master_ip=172.17.0.5redis_master_port=6379"-k SSHpassword: PLAY[172.17.0.6]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.6] TASK:[common|Installinitializtionrequiresoftware]*********************** changed:[172.17.0.6] TASK:[redis_install|CopyRedisSoftwareToRedhatClient]****************** changed:[172.17.0.6] TASK:[redis_install|CreateRedisInstallDir]****************************** ok:[172.17.0.6] TASK:[redis_install|UncompressionRedisSoftwareToRedhatClient]********* changed:[172.17.0.6] TASK:[redis_install|CopyRedisConfigToRedhatClient]******************** changed:[172.17.0.6] TASK:[redis_install|CreateSoftLinkInRedhatClient]********************* changed:[172.17.0.6]=>(item=redis-cli) changed:[172.17.0.6]=>(item=redis-server) TASK:[redis_install|CheckBootStartInRedhatClient]********************* failed:[172.17.0.6]=>{ "changed" : true , "cmd" : "grep-c'/usr/bin/redis-server/data/redis-2.6.17/conf/redis_6379.conf'/etc/rc.local" , "delta" : "0:00:00.006751" , "end" : "2014-08-1309:49:07.569522" , "item" : "" , "rc" :1, "start" : "2014-08-1309:49:07.562771" } stdout:0 ...ignoring TASK:[redis_install|AddBootStartInRedhatClient]*********************** changed:[172.17.0.6] TASK:[redis_install|StartRedisServiceInRedhatClient]****************** changed:[172.17.0.6] TASK:[redis_install|DeleteRediscompressionSoftwareInRedhatClient]**** changed:[172.17.0.6] PLAYRECAP******************************************************************** 172.17.0.6:ok=11changed=9unreachable=0failed=0 real 1m48.579s user 0m6.781s sys 0m0.654s 11、查看redis slave安装情况 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 09:59:24 #ssh172.17.0.6 root@172.17.0.6'spassword: root@dfec766fbaa7:~ 09:59:28 #ll total0 root@dfec766fbaa7:~ 09:59:31 #ps-ef|grepredis root1971009:49?00:00:00 /usr/bin/redis-server /data/redis-2 .6.17 /conf/redis_6379 .conf root227212009:59pts /0 00:00:00 grep redis 09:59:49 #grepslave/data/redis-2.6.17/conf/redis_6379.conf|egrep-v"^#" slaveof172.17.0.56379 slave-serve-stale-data yes slave- read -only yes slave-priority100 client-output-buffer-limitslave256mb64mb60 root@dfec766fbaa7:~ 10:00:09 #redis-cli-h172.17.0.6-p6379 redis172.17.0.6:6379>keys* (emptylistor set ) redis172.17.0.6:6379>info #Server redis_version:2.6.17 redis_git_sha1:00000000 redis_git_dirty:0 redis_mode:standalone os:Linux2.6.32-431.17.1.el6.x86_64x86_64 arch_bits:64 multiplexing_api:epoll gcc_version:4.4.7 process_id:197 run_id:81207df2727abe534ae606afc0cb80016f75a422 tcp_port:6379 uptime_in_seconds:685 uptime_in_days:0 hz:10 lru_clock:280339 #Clients connected_clients:2 client_longest_output_list:0 client_biggest_input_buf:0 blocked_clients:0 #Memory used_memory:878072 used_memory_human:857.49K used_memory_rss:7569408 used_memory_peak:877280 used_memory_peak_human:856.72K used_memory_lua:31744 mem_fragmentation_ratio:8.62 mem_allocator:jemalloc-3.2.0 #Persistence loading:0 rdb_changes_since_last_save:0 rdb_bgsave_in_progress:0 rdb_last_save_time:1407894548 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:-1 rdb_current_bgsave_time_sec:-1 aof_enabled:0 aof_rewrite_in_progress:0 aof_rewrite_scheduled:0 aof_last_rewrite_time_sec:-1 aof_current_rewrite_time_sec:-1 aof_last_bgrewrite_status:ok #Stats total_connections_received:1 total_commands_processed:70 instantaneous_ops_per_sec:0 rejected_connections:0 expired_keys:0 evicted_keys:0 keyspace_hits:0 keyspace_misses:0 pubsub_channels:0 pubsub_patterns:0 latest_fork_usec:0 #Replication role:slave master_host:172.17.0.5 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_priority:100 slave_read_only:1 connected_slaves:0 #CPU used_cpu_sys:0.24 used_cpu_user:0.10 used_cpu_sys_children:0.00 used_cpu_user_children:0.00 #Keyspace 可以从上面的Replication里看到主从做好了,信息如下图 然后去redis master里查看主从信息 12、redis 主从测试 A.redis master插入key 1 2 3 4 5 6 7 8 redis172.17.0.5:6379> set master1 OK redis172.17.0.5:6379> set slave0 OK redis172.17.0.5:6379>getmaster "1" redis172.17.0.5:6379>getslave "0" B.redis slave读取key 1 2 3 4 5 6 7 redis172.17.0.6:6379>keys* 1) "master" 2) "slave" redis172.17.0.6:6379>getmaster "1" redis172.17.0.6:6379>getslave "0" 可以看到主从建立完成 下面是redis slave的日志情况 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 10:08:04 #cat/data/redis-2.6.17/log/redis_6379.log _._ _.-``__ '' -._ _.-```.`_. '' -._Redis2.6.17(00000000 /0 )64bit .-``.-```.```\/_.,_ '' -._ (',.-`|`,)Running in standalonemode |`-._`-...-`__...-.``-._| '`_.-' |Port:6379 |`-._`._/_.-'|PID:197 `-._`-._`-./_.- '_.-' |`-._`-._`-.__.- '_.-' _.-'| |`-._`-.__.- '_.-' |http: //redis .io `-._`-._`-.__.- '_.-' _.-' |`-._`-._`-.__.- '_.-' _.-'| |`-._`-.__.- '_.-' | `-._`-._`-.__.- '_.-' _.-' `-._`-.__.- '_.-' `-.__.-' `-.__.-' [197]13Aug09:49:08.878 #Serverstarted,Redisversion2.6.17 [197]13Aug09:49:08.879 #WARNINGovercommit_memoryissetto0!Backgroundsavemayfailunderlowmemorycondition.Tofixthisissueadd'vm.overcommit_memory=1'to/etc/sysctl.confandthenrebootorrunthecommand'sysctlvm.overcommit_memory=1'forthistotakeeffect. [197]13Aug09:49:08.879*Theserverisnowreadytoacceptconnectionsonport6379 [197]13Aug09:49:09.879*ConnectingtoMASTER172.17.0.5:6379 [197]13Aug09:49:09.879*MASTER<->SLAVE sync started [197]13Aug09:49:09.881*Nonblockingconnect for SYNCfiredtheevent. [197]13Aug09:49:09.881*MasterrepliedtoPING,replicationcan continue ... [197]13Aug09:49:10.035*MASTER<->SLAVE sync :receiving18bytesfrommaster [197]13Aug09:49:10.035*MASTER<->SLAVE sync :LoadingDB in memory [197]13Aug09:49:10.035*MASTER<->SLAVE sync :Finishedwithsuccess [197]13Aug10:04:56.980*1changes in 900seconds.Saving... [197]13Aug10:04:56.982*Backgroundsavingstartedbypid233 [233]13Aug10:04:57.226*DBsavedondisk [233]13Aug10:04:57.227*RDB:6MBofmemoryusedbycopy-on-write [197]13Aug10:04:57.293*Backgroundsavingterminatedwithsuccess 13、删除redis安装 无论redis主从,删除都是一样的命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 09:57:32 #timeansible-playbookredis_delete.yml--extra-vars"host=172.17.0.5user=root"-k SSHpassword: PLAY[172.17.0.5]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.5] TASK:[redis_delete|StopRedisServiceInRedhatClient]******************** changed:[172.17.0.5] TASK:[redis_delete|DeleteRedisSoftLineInRedhatClient]**************** changed:[172.17.0.5]=>(item=redis-cli) changed:[172.17.0.5]=>(item=redis-server) TASK:[redis_delete|DeleteRedisDirInRedhatClient]********************** changed:[172.17.0.5] TASK:[redis_delete|DeleteBootStartInRedhatClient]********************* changed:[172.17.0.5] PLAYRECAP******************************************************************** 172.17.0.5:ok=5changed=4unreachable=0failed=0 real 0m6.929s user 0m1.942s sys 0m0.250s root@ip-10-10-10-10: /etc/ansible 10:09:18 #timeansible-playbookredis_delete.yml--extra-vars"host=172.17.0.6user=root"-k SSHpassword: PLAY[172.17.0.6]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.6] TASK:[redis_delete|StopRedisServiceInRedhatClient]******************** changed:[172.17.0.6] TASK:[redis_delete|DeleteRedisSoftLineInRedhatClient]**************** changed:[172.17.0.6]=>(item=redis-cli) changed:[172.17.0.6]=>(item=redis-server) TASK:[redis_delete|DeleteRedisDirInRedhatClient]********************** changed:[172.17.0.6] TASK:[redis_delete|DeleteBootStartInRedhatClient]********************* changed:[172.17.0.6] PLAYRECAP******************************************************************** 172.17.0.6:ok=5changed=4unreachable=0failed=0 real 0m5.897s user 0m1.726s sys 0m0.258s 15、删除后测试 A.redis master上 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 10:09:55 #ifconfig eth0Linkencap:EthernetHWaddrC6:3A:D2:D9:DD:D9 inetaddr:172.17.0.5Bcast:0.0.0.0Mask:255.255.0.0 inet6addr:fe80::c43a:d2ff:fed9:ddd9 /64 Scope:Link UPBROADCASTRUNNINGMTU:1500Metric:1 RXpackets:13236errors:0dropped:0overruns:0frame:0 TXpackets:12843errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:26106313(24.8MiB)TXbytes:906412(885.1KiB) loLinkencap:LocalLoopback inetaddr:127.0.0.1Mask:255.0.0.0 inet6addr:::1 /128 Scope:Host UPLOOPBACKRUNNINGMTU:16436Metric:1 RXpackets:196errors:0dropped:0overruns:0frame:0 TXpackets:196errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:0 RXbytes:9665(9.4KiB)TXbytes:9665(9.4KiB) root@06762530db8c:~ 10:09:56 #ps-ef|grepredis root431329010:09pts /0 00:00:00 grep redis root@06762530db8c:~ 10:09:59 #cat/etc/rc.local #!/bin/sh # #Thisscriptwillbeexecuted*after*alltheotherinitscripts. #Youcanputyourowninitializationstuffinhereifyoudon't #wanttodothefullSysVstyleinitstuff. touch /var/lock/subsys/local root@06762530db8c:~ 10:10:01 #ll/data/ total4 drwxr-xr-x2rootroot4096Jun510:21soft root@06762530db8c:~ B. redis slave上 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 10:08:09 #ifconfig eth0Linkencap:EthernetHWaddrBE:97:0C:B2:02:D9 inetaddr:172.17.0.6Bcast:0.0.0.0Mask:255.255.0.0 inet6addr:fe80::bc97:cff:feb2:2d9 /64 Scope:Link UPBROADCASTRUNNINGMTU:1500Metric:1 RXpackets:13062errors:0dropped:0overruns:0frame:0 TXpackets:12704errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:25967216(24.7MiB)TXbytes:842881(823.1KiB) loLinkencap:LocalLoopback inetaddr:127.0.0.1Mask:255.0.0.0 inet6addr:::1 /128 Scope:Host UPLOOPBACKRUNNINGMTU:16436Metric:1 RXpackets:86errors:0dropped:0overruns:0frame:0 TXpackets:86errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:0 RXbytes:5288(5.1KiB)TXbytes:5288(5.1KiB) root@dfec766fbaa7:~ 10:10:32 #ps-ef|grepredis root319212010:10pts /0 00:00:00 grep redis root@dfec766fbaa7:~ 10:10:37 #cat/etc/rc.local #!/bin/sh # #Thisscriptwillbeexecuted*after*alltheotherinitscripts. #Youcanputyourowninitializationstuffinhereifyoudon't #wanttodothefullSysVstyleinitstuff. touch /var/lock/subsys/local root@dfec766fbaa7:~ 10:10:39 #ll/data/ total4 drwxr-xr-x2rootroot4096Jun510:21soft root@dfec766fbaa7:~ 如果大家想使用我的例子,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/redis_install),然后放到/etc/ansible目录里,下面是内容 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1539251,如需转载请自行联系原作者

优秀的个人博客,低调大师

运维自动化-监控平台】监控平台内置的主机监控指标

``` 监控平台默认初始内置了丰富的主机监控指标,基本能满足主机基础性能纬度的各种监控 ``` # 指标分类 - 系统负载 - 单核CPU - CPU整体 - 内存 - 交换分区 - 磁盘空间 - 磁盘inode - 磁盘IO - 网卡 - 系统环境 - TCP/UDP连接数 ## 各分类的指标名称和含义 **系统负载** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605171704/20044/20230605171704/--ae4d914a4fa15fadae4a197549c9178c.png) **CPU整体** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605171732/20044/20230605171732/--b4010bf185e5f7425dcaa5f5c58f9478.png) **单核CPU** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605171802/20044/20230605171802/--2d215b5cdc7d37650c35db717b1c9b9b.png) **内存** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172021/20044/20230605172021/--44ec2935a598986eb0fa2ac446e560ae.png) **交换分区** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172538/20044/20230605172538/--18808ac3619caf802fe67d95484788a2.png) **磁盘空间** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172548/20044/20230605172548/--3a2613a2523296fbeb9ba955bbac63c4.png) **磁盘inode** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172601/20044/20230605172601/--b249059a45562fbfd051418a1858effb.png) **磁盘IO** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172613/20044/20230605172613/--7c64b698c57fef183c51d30abf0c2a39.png) **网卡** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172631/20044/20230605172631/--130fd93cd10a5d6e8cc9d97b72759bd6.png) **系统环境** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172642/20044/20230605172642/--da64a877f3d5fde9846d13f6c36e63a5.png) **TCP/UDP连接数** ![](https://smartpublic-10032816.file.myqcloud.com/custom/20230605172651/20044/20230605172651/--2f52c274608499a2f0831a5e335e29bf.png) 说明:适合产品版本 V6.1/V6.2/V7.0/V7.1

优秀的个人博客,低调大师

运维自动化之ansible playbook安装mysql tpcc测试OLTP能力

上周介绍了zabbix监控cdn带宽,这次在介绍一下ansible结合docker来一键化安装与测试mysql tpcc,然后通过tpcc测试OLTP系统性能。 写这个的原因就是重复性的安装太麻烦,浪费时间,而且我这里新业务不断上线,上线前使用tpcc进行OLTP测试对整体系统性能上也有了解。 一、Myql Tpcc介绍(网上找的内容) Tpcc-mysql是percona基于tpcc衍生出来的产品,用来测试OLTP(在线事务处理)系统性能的软件, TPCC-MYSQL是开源的TPC-C测试软件其源码放在bazaar(Bazaar是一个分布式的版本控制系统,采用GPL许可协议,可运行于Windows、GNU/Linux、UNIX 以及 Mac OS 系统之上。Bazaar 由Canonical公司(Ubuntu母公司)赞助商,因此还需要先安装bazaar客户端。 二、测试环境 平台:cloudsbox 虚拟化:kvm 系统:centos6.5 Docker版本:0.11.1 Docker容器系统版本:centos 6.3 Ansible版本:1.6 三、测试步骤 1、使用docker生成一个新的容器mysql-tpcc; 2、使用ansible在新生成的容器mysql-tpcc里进行安装mysql-tpcc并进行测试; 3、测试完成后,从容器里把测试结果拉回本地。 下面开始是测试过程 四、docker里操作 1、查看当然容器 1 2 3 4 5 6 7 17:49:46 #dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES dfec766fbaa7centos6:3.0 /usr/sbin/sshd -D12daysagoUp12days0.0.0.0:49159->22 /tcp redis-slave 06762530db8ccentos6:3.0 /usr/sbin/sshd -D12daysagoUp12days0.0.0.0:49158->22 /tcp redis-master 846efb9e4d7aubuntu:3.0 /usr/sbin/sshd -D3weeksagoUp2weeks0.0.0.0:49167->22 /tcp ubuntu-test1 b9a9e6f2caedcentos6:3.0 /usr/sbin/sshd -D5weeksagoUp2weeks0.0.0.0:49166->22 /tcp zabbix-server 978fff134b18centos6:3.0 /usr/sbin/sshd -D6weeksagoUp2weeks0.0.0.0:49165->22 /tcp centos6-test5 2、生成新容器 1 2 3 4 5 6 17:49:53 #timedockerinspect$(dockerrun-d-p22--name="mysql-tpcc"centos6:3.0/usr/sbin/sshd-D)|grep-iaddress|awk-F'"''{print$4}' 172.17.0.7 real 0m9.415s user 0m0.028s sys 0m0.140s 3、查看当前已有容器 1 2 3 4 5 6 7 8 17:50:07 #dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 6331fb9bf19bcentos6:3.0 /usr/sbin/sshd -D21secondsagoUp12seconds0.0.0.0:49160->22 /tcp mysql-tpcc dfec766fbaa7centos6:3.0 /usr/sbin/sshd -D12daysagoUp12days0.0.0.0:49159->22 /tcp redis-slave 06762530db8ccentos6:3.0 /usr/sbin/sshd -D12daysagoUp12days0.0.0.0:49158->22 /tcp redis-master 846efb9e4d7aubuntu:3.0 /usr/sbin/sshd -D3weeksagoUp2weeks0.0.0.0:49167->22 /tcp ubuntu-test1 b9a9e6f2caedcentos6:3.0 /usr/sbin/sshd -D5weeksagoUp2weeks0.0.0.0:49166->22 /tcp zabbix-server 978fff134b18centos6:3.0 /usr/sbin/sshd -D6weeksagoUp2weeks0.0.0.0:49165->22 /tcp centos6-test5 4、新容器ip加入到ansible的访问主机列表里 1 2 17:52:47 #echo"172.17.0.7">>hosts root@ip-10-10-10-10: /etc/ansible 五、ansible里操作 其中命令为ansible-playbookmysql_tpcc_install.yml --extra-vars "host=172.17.0.17 user=rootwarehouse=50 w=50 c=50 r=120 l=600”,extra-vars后面都是变量,都是可以自行修改变量,满足个性化测试需求 下面是运行情况 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 time ansible-playbookmysql_tpcc_install.yml--extra-vars "host=172.17.0.7user=rootwarehouse=50w=50c=50r=120l=600" -k SSHpassword: PLAY[172.17.0.7]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.7] TASK:[common|Installinitializtionrequiresoftware]*********************** changed:[172.17.0.7] TASK:[mysql_install|CopyMysqlSoftwareToRedhatClient]****************** changed:[172.17.0.7] TASK:[mysql_install|CreateMysqlUserInRedhatClient]******************** changed:[172.17.0.7] TASK:[mysql_install|CopyMysqlStartScriptToRedhatClient]************** changed:[172.17.0.7] TASK:[mysql_install|CopyInstallMysqlScriptToRedhatClient]*********** changed:[172.17.0.7] TASK:[mysql_install|CopyMysqlConfigToRedhatClient]******************** changed:[172.17.0.7] TASK:[mysql_install|CopyMysqlSecurityScriptToRedhatClient]*********** changed:[172.17.0.7] TASK:[mysql_install|CreateMysqlInstallDir]****************************** ok:[172.17.0.7] TASK:[mysql_install|UncompressionMysqlSoftwareToRedhatClient]********* changed:[172.17.0.7] TASK:[mysql_install|ModifyMysqlDirPermissionInRedhatClient]********** ok:[172.17.0.7]=>(item= /data/mysql/datadir ) ok:[172.17.0.7]=>(item= /data/mysql/basedir ) TASK:[mysql_install|InstallMysqlScriptInRedhatClient]***************** changed:[172.17.0.7] TASK:[mysql_install|StartMyqlSecurityScriptInRedhatClient]*********** changed:[172.17.0.7] TASK:[mysql_install|AddBootStartMysqlServiceInRedhatClient]********* changed:[172.17.0.7] TASK:[mysql_install|DeleteMysqlcompressionSoftwareInRedhatClient]**** changed:[172.17.0.7] TASK:[mysql_tpcc_install|InstallBaseRequireSoftwareInRedhatClient]*** changed:[172.17.0.7] TASK:[mysql_tpcc_install|CopyTpccSoftwareToRedhatClient]************* changed:[172.17.0.7]=>(item=tpcc-mysql. tar .gz) TASK:[mysql_tpcc_install|DownloadTpccSoftwareToRedhatClient]********** changed:[172.17.0.7] TASK:[mysql_tpcc_install|CompileTpccSoftwareToRedhatClient]*********** changed:[172.17.0.7] TASK:[mysql_tpcc_install|CreateMysqlTpccDatabaseInRedhatClient]****** changed:[172.17.0.7]=>(item=createdatabasetpcc100;) TASK:[mysql_tpcc_install|LoadMysqlTpccDataTableInRedhatClient]***** changed:[172.17.0.7]=>(item=create_table.sql) changed:[172.17.0.7]=>(item=add_fkey_idx.sql) TASK:[mysql_tpcc_install|CreateTpccMysqlTestDataToRedhatClient]***** changed:[172.17.0.7] TASK:[mysql_tpcc_install|StartMysqlTpccTestInRedhatClient]********** changed:[172.17.0.7] TASK:[mysql_tpcc_install|CopyMysqlTpccResultfromRedhatClient]******** changed:[172.17.0.7] TASK:[mysql_tpcc_install|DeleteZabbixcompressionSoftwareInRedhatClient]*** changed:[172.17.0.7]=>(item=tpcc-mysql. tar .gz) changed:[172.17.0.7]=>(item=tpcc100.sql) PLAYRECAP******************************************************************** 172.17.0.7:ok=25changed=22unreachable=0failed=0 real 89m21.833s user 0m27.365s sys 0m2.680s 可以看到89分钟就安装完成,可能有的人疑问为什么这么长时间,注意是在tpcc_load里加载测试数据差不多就话费3分之二时间,本来我想做好一个测试库后,使用mysqldump导出,但即使导出后在算上传输时间、导入时间跟现在时间差不多,所以就没有使用这个方法。 2、查看mysql-tpcc的结果 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 20:21:31 #ll/tmp/mysql-tpcc-172.17.0.7.log -rw-r--r--1rootroot8215Aug2520:21 /tmp/mysql-tpcc-172 .17.0.7.log root@ip-10-10-10-10: /mnt/ansible 20:21:44 #cat/tmp/mysql-tpcc-172.17.0.7.log *************************************** *** ###easy###TPC-CLoadGenerator*** *************************************** optionhwithvalue '172.17.0.7' optionuwithvalue 'root' optionpwithvalue 'E4yR3WnoluSFTCBAI' optiondwithvalue 'tpcc100' optionwwithvalue '50' optioncwithvalue '50' optionrwithvalue '120' optionlwithvalue '600' optionfwithvalue 'tpcc-mysql-result' <Parameters> [server]:172.17.0.7 [port]:3306 [DBname]:tpcc100 [user]:root [pass]:E4yR3WnoluSFTCBAI [warehouse]:50 [connection]:50 [rampup]:120(sec.) [measure]:600(sec.) RAMP-UPTIME.(120sec.) MEASURINGSTART. 10,2491(110):4.671|6.975,2494(0):1.001|1.625,250(0):0.510|0.939,251(0):6.439|7.783,246(0):13.922|17.389 20,1649(305):6.303|7.654,1649(0):1.337|1.521,164(0):0.718|0.737,164(0):7.859|8.443,173(0):17.100|18.067 30,1701(294):6.378|7.320,1694(0):1.338|1.685,171(0):0.701|0.787,170(0):7.824|8.124,164(0):17.122|18.446 40,1857(310):6.198|6.755,1861(0):1.301|1.528,184(0):0.716|0.857,187(0):7.595|7.996,190(0):16.457|17.335 50,1543(352):6.504|7.504,1543(0):1.460|1.977,157(0):0.727|0.947,154(0):8.237|8.365,150(0):17.165|17.904 60,1728(385):6.425|7.139,1732(0):1.393|1.873,172(0):0.728|0.845,174(0):7.782|8.069,175(0):16.524|16.731 70,1824(321):6.199|6.856,1826(0):1.306|1.639,181(0):0.751|0.859,182(0):7.650|7.921,183(0):16.011|16.740 80,1598(399):6.367|7.330,1595(0):1.371|1.649,162(0):0.761|0.962,159(0):7.532|7.632,158(0):17.059|17.390 90,1740(371):6.347|6.910,1740(0):1.357|1.872,172(0):0.751|0.821,174(0):7.828|8.164,172(0):17.291|17.397 100,1758(399):6.350|6.993,1757(0):1.343|1.625,176(0):0.726|0.744,176(0):8.042|8.247,179(0):17.284|17.362 110,1791(359):6.364|6.983,1792(0):1.352|1.595,180(0):0.770|0.852,180(0):7.597|7.962,181(0):16.908|17.897 120,1762(367):6.397|7.016,1760(0):1.332|1.580,175(0):0.690|0.873,174(0):8.184|8.551,173(0):17.208|17.613 130,1935(267):6.118|6.846,1938(0):1.290|1.535,194(0):0.735|0.800,194(0):7.329|7.667,193(0):16.368|16.718 140,1602(371):6.391|7.331,1598(0):1.377|1.551,161(0):0.875|0.986,161(0):8.105|8.791,164(0):17.402|18.088 150,1814(275):6.329|6.780,1816(0):1.321|1.614,181(0):0.671|0.869,182(0):8.143|8.568,179(0):16.673|17.081 160,1908(284):6.041|7.137,1911(0):1.366|1.742,190(0):0.720|0.794,190(0):7.571|8.524,192(0):15.846|16.471 170,1740(46):5.313|6.052,1743(0):1.199|1.636,175(0):0.699|0.805,175(0):6.750|6.918,174(0):15.899|16.343 180,3700(10):4.368|5.826,3692(0):1.036|1.361,367(0):0.574|0.751,368(0):5.685|6.103,372(0):13.234|13.676 190,5243(0):2.843|4.661,5249(0):0.704|1.119,528(0):0.391|0.655,525(0):4.449|5.307,525(0):8.626|11.532 200,4634(9):3.744|6.482,4630(0):0.904|1.317,462(0):0.450|0.678,463(0):5.635|7.451,462(0):11.847|12.898 210,1567(161):6.223|6.673,1567(0):1.312|1.540,156(0):0.701|0.757,155(0):7.851|8.040,157(0):17.377|17.517 220,3125(78):5.695|7.167,3126(0):1.142|1.361,312(0):0.610|0.691,315(0):7.122|7.630,310(0):15.943|16.664 230,1913(75):5.546|6.814,1911(0):1.225|1.521,194(0):0.592|0.732,190(0):7.236|7.631,190(0):14.452|15.462 240,2825(39):5.187|6.421,2831(0):1.152|1.677,284(0):0.674|0.809,283(0):6.705|7.467,287(0):14.756|15.847 250,2795(80):5.612|6.583,2790(0):1.147|1.582,277(0):0.629|0.744,280(0):6.924|7.108,277(0):14.721|15.484 260,3200(39):5.114|6.319,3204(0):1.161|1.717,321(0):0.642|0.760,321(0):7.173|8.076,321(0):14.395|14.923 270,2124(136):5.903|6.660,2123(0):1.233|1.612,210(0):0.633|0.835,211(0):7.194|7.598,211(0):15.481|16.417 280,1785(142):5.773|6.158,1781(0):1.269|1.564,181(0):0.755|0.933,180(0):7.181|7.396,177(0):14.987|16.114 290,1649(254):6.228|7.476,1653(0):1.334|1.666,163(0):0.682|0.715,164(0):7.552|7.958,167(0):16.458|18.312 300,1683(181):6.048|6.788,1676(0):1.376|1.725,169(0):0.655|0.721,169(0):7.266|7.550,165(0):15.377|16.599 310,1782(191):6.072|7.079,1785(0):1.342|1.662,179(0):0.708|0.995,178(0):7.479|7.790,182(0):15.789|16.220 320,2122(58):5.375|6.219,2122(0):1.184|1.492,211(0):0.577|0.708,211(0):6.726|7.536,213(0):15.324|16.262 330,2088(9):4.735|5.830,2082(0):1.226|1.573,210(0):0.657|0.808,208(0):5.856|5.963,208(0):13.431|15.987 340,1514(201):5.871|6.529,1524(0):1.292|1.560,151(0):0.742|0.782,151(0):7.418|7.639,154(0):16.177|16.801 350,1897(89):5.645|6.443,1889(0):1.242|1.555,187(0):0.777|0.898,188(0):7.183|7.971,188(0):14.419|14.601 360,2340(18):4.835|6.052,2349(0):1.212|1.869,238(0):0.598|0.685,238(0):6.727|7.723,234(0):13.155|15.648 370,1817(264):6.349|6.903,1807(0):1.371|1.607,180(0):0.785|0.890,181(0):8.153|8.362,182(0):16.410|16.923 380,1592(433):6.465|7.550,1588(0):1.379|1.660,158(0):0.773|0.804,160(0):7.763|7.853,152(0):17.126|17.280 390,1666(420):6.401|7.250,1676(0):1.390|1.560,168(0):0.734|0.764,167(0):7.988|8.532,167(0):16.822|17.297 400,1718(439):6.390|6.753,1704(0):1.359|1.732,172(0):0.748|0.804,169(0):7.749|7.784,178(0):17.143|18.053 410,1576(389):6.431|7.726,1586(0):1.371|1.962,158(0):0.717|0.816,160(0):7.860|8.113,150(0):17.143|17.348 420,1639(404):6.420|6.884,1639(0):1.345|2.205,161(0):0.718|0.981,162(0):7.725|8.204,169(0):16.941|17.532 430,1828(391):6.333|6.998,1828(0):1.363|1.712,185(0):0.712|0.831,184(0):7.781|8.109,183(0):16.935|17.534 440,1693(365):6.427|7.375,1696(0):1.380|1.689,168(0):0.830|0.848,169(0):8.020|8.507,172(0):16.618|16.924 450,1743(403):6.424|7.377,1743(0):1.376|1.610,176(0):0.706|0.857,176(0):7.915|8.236,172(0):16.736|17.716 460,1854(334):6.202|6.753,1853(0):1.341|1.501,185(0):0.724|0.812,183(0):7.673|7.825,185(0):16.963|17.401 470,1944(259):6.271|7.049,1946(0):1.284|1.709,195(0):0.685|0.697,195(0):7.756|8.023,198(0):16.338|18.186 480,1708(407):6.317|7.343,1706(0):1.380|1.881,170(0):0.784|0.855,171(0):7.952|8.688,168(0):17.000|17.313 490,1849(380):6.371|7.301,1851(0):1.344|1.589,185(0):0.741|1.008,186(0):7.992|8.086,185(0):16.715|16.806 500,1518(414):6.470|7.747,1514(0):1.363|1.780,153(0):0.790|0.800,152(0):8.059|8.249,147(0):17.433|17.965 510,1617(397):6.295|7.219,1619(0):1.360|1.852,162(0):0.737|0.882,161(0):7.860|11.366,165(0):16.747|18.100 520,1729(391):6.380|7.159,1726(0):1.436|1.731,171(0):0.707|0.792,173(0):7.879|8.168,172(0):17.220|17.623 530,1628(393):6.353|7.159,1631(0):1.360|1.567,163(0):0.743|0.837,164(0):7.953|8.167,161(0):17.195|18.550 540,1745(382):6.377|6.962,1747(0):1.396|1.697,174(0):0.709|0.951,172(0):7.558|7.684,179(0):17.103|18.918 550,1129(319):6.680|7.058,1117(0):1.452|1.727,115(0):0.755|0.913,117(0):8.050|8.419,116(0):17.458|19.481 560,1062(285):6.842|7.845,1067(0):1.451|1.785,104(0):0.707|0.759,104(0):8.291|8.489,100(0):18.638|19.465 570,980(254):6.661|7.531,959(0):1.532|1.765,99(0):0.892|1.034,100(0):8.231|9.792,105(0):18.520|19.243 580,923(161):7.483|8.429,900(0):2.066|2.429,92(0):0.847|0.861,94(0):13.631|15.379,99(2):19.999|22.666 590,89(24):10.320|10.529,90(0):2.331|2.606,9(0):1.077|1.084,10(0):10.935|12.559,9(1):17.615|22.311 600,1732(264):6.335|6.926,1784(0):1.363|2.580,174(0):0.765|0.967,166(0):7.857|8.124,166(0):17.084|17.509 STOPPINGTHREADS.................................................. <RawResults> [0]sc:100049lt:15157rt:0fl:0 [1]sc:115210lt:0rt:0fl:0 [2]sc:11522lt:0rt:0fl:0 [3]sc:11521lt:0rt:0fl:0 [4]sc:11523lt:3rt:0fl:0 in 600sec. <RawResults2( sum ver.)> [0]sc:100049lt:15157rt:0fl:0 [1]sc:115214lt:0rt:0fl:0 [2]sc:11522lt:0rt:0fl:0 [3]sc:11521lt:0rt:0fl:0 [4]sc:11523lt:3rt:0fl:0 <ConstraintCheck>(allmustbe[OK]) [transactionpercentage] Payment:43.48%(>=43.0%)[OK] Order-Status:4.35%(>=4.0%)[OK] Delivery:4.35%(>=4.0%)[OK] Stock-Level:4.35%(>=4.0%)[OK] [response time (atleast90%passed)] New-Order:86.84%[NG]* Payment:100.00%[OK] Order-Status:100.00%[OK] Delivery:100.00%[OK] Stock-Level:99.97%[OK] <TpmC> 11520.600TpmC 其实测试结果最关键的就是最后一行11520.600 TpmC,下面是介绍一下TpmC是做什么用的 1 流量指标(Throughput,简称tpmC):按照TPC组织的定义,流量指标描述了系统在执行支付操作、订单状态查询、发货和库存状态查询这4种交易的同时,每分钟可以处理多少个新订单交易。所有交易的响应时间必须满足TPC-C测试规范的要求,且各种交易数量所占的比例也应该满足TPC-C测试规范的要求。在这种情况下,流量指标值越大说明系统的联机事务处理能力越高。 具体关于Tpcc介绍可以参考http://baike.baidu.com/view/2776305.htm 3、删除tpcc 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 09:35:47 #timeansible-playbookmysql_tpcc_delete.yml--extra-vars"host=172.17.0.7user=rootwarehouse=50w=50c=50r=120l=600"-k SSHpassword: PLAY[172.17.0.7]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.17.0.7] TASK:[mysql_tpcc_delete|DeleteMysqlTpccDatabase]************************ changed:[172.17.0.7] TASK:[mysql_tpcc_delete|DeleteMysqlTpccDir]***************************** changed:[172.17.0.7] TASK:[mysql_delete|StopMysqlService]************************************* changed:[172.17.0.7] TASK:[mysql_delete|DeleteMysqlBootStartScript]************************* changed:[172.17.0.7] TASK:[mysql_delete|DeleteMysqlDirAndSocket]**************************** changed:[172.17.0.7] TASK:[mysql_delete|DeleteMysqlUser]************************************** changed:[172.17.0.7] TASK:[mysql_delete|DeleteMysqlServiceStartScript]********************** changed:[172.17.0.7] PLAYRECAP******************************************************************** 172.17.0.7:ok=8changed=7unreachable=0failed=0 real 0m25.780s user 0m2.446s sys 0m0.408s 如果大家想使用我的例子,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/mysql_tpcc_install),然后放到/etc/ansible目录里,下面是内容 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1545032,如需转载请自行联系原作者

优秀的个人博客,低调大师

运维自动化之ansible playbook一键化安装mysql主从

今天qq群里有朋友讨论使用ansible创建mysql主从的问题,正好我公司之前有需求,我就写了这个模块,现在分享给大家。 一、各软件版本 1、docker版本 1 2 3 4 5 6 7 8 9 Clientversion:1.3.2 ClientAPIversion:1.15 Goversion(client):go1.3.3 Gitcommit(client):39fa2fa /1 .3.2 OS /Arch (client):linux /amd64 Serverversion:1.3.2 ServerAPIversion:1.15 Goversion(server):go1.3.3 Gitcommit(server):39fa2fa /1 .3.2 2、docker存储 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Containers:2 Images:4 StorageDriver:devicemapper PoolName:docker-253:1-1430610-pool PoolBlocksize:65.54kB Data file : /var/lib/docker/devicemapper/devicemapper/data Metadata file : /var/lib/docker/devicemapper/devicemapper/metadata DataSpaceUsed:9.855GB DataSpaceTotal:107.4GB MetadataSpaceUsed:6.095MB MetadataSpaceTotal:2.147GB LibraryVersion:1.02.84-RHEL7(2014-03-26) ExecutionDriver:native-0.2 KernelVersion:3.18.3-1.el7.elrepo.x86_64 OperatingSystem:CentOSLinux7(Core) 二、docker方面 1、新建立2个容器test1(mysql master)与test2(mysql slave) 1 2 3 4 5 6 7 8 [root@docker-test3~] #shcreate_docker_container_use_static_ip.shtest1docker.ops-chukong.com:5000/centos6-http:new/usr/bin/supervisord10 { 'Physics_ip' : '10.10.17.3' , 'Container_name' : 'test1' , 'Container_ip' : '172.16.1.2/24' , 'Container_vlan' : '10' , 'Container_vlan_gateway' : '172.16.1.1/24' , 'Container_create' : '2015-03-0514:49:19' , 'Container_status' : 'running' } [root@docker-test3~] #shcreate_docker_container_use_static_ip.shtest2docker.ops-chukong.com:5000/centos6-http:new/usr/bin/supervisord10 { 'Physics_ip' : '10.10.17.3' , 'Container_name' : 'test2' , 'Container_ip' : '172.16.1.3/24' , 'Container_vlan' : '10' , 'Container_vlan_gateway' : '172.16.1.1/24' , 'Container_create' : '2015-03-0514:49:39' , 'Container_status' : 'running' } [root@docker-test3~] #dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 36b3b3643097docker.ops-chukong.com:5000 /centos6-http :new" /usr/bin/supervisor AboutaminuteagoUpAboutaminutetest2 90f8ffc29d41docker.ops-chukong.com:5000 /centos6-http :new" /usr/bin/supervisor AboutaminuteagoUpAboutaminutetest1 已经创建了2个实例,test1的ip是172.16.1.2,test2的ip是172.16.1.3 使用这个创建是使用了持久化固定ip原因,各位使用其他方式创建也可以。 宿主机的ip是10.10.17.3 三、ansible方面 1、添加路由 在ansible里添加一条到这个主机的路由,方便直接ansible对容器的ip进行部署mysql 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [root@puppetansible] #routeadd-net172.16.0.0netmask255.255.0.0gw10.10.17.3 ping 那2个容器ip [root@puppetansible] #ping-c2172.16.1.2 PING172.16.1.2(172.16.1.2)56(84)bytesofdata. 64bytesfrom172.16.1.2:icmp_seq=1ttl=63 time =0.846ms 64bytesfrom172.16.1.2:icmp_seq=2ttl=63 time =0.121ms ---172.16.1.2 ping statistics--- 2packetstransmitted,2received,0%packetloss, time 1001ms rttmin /avg/max/mdev =0.121 /0 .483 /0 .846 /0 .363ms Youhavemail in /var/spool/mail/root [root@puppetansible] #ping-c2172.16.1.3 PING172.16.1.3(172.16.1.3)56(84)bytesofdata. 64bytesfrom172.16.1.3:icmp_seq=1ttl=63 time =0.672ms 64bytesfrom172.16.1.3:icmp_seq=2ttl=63 time =0.111ms ---172.16.1.3 ping statistics--- 2packetstransmitted,2received,0%packetloss, time 999ms rttmin /avg/max/mdev =0.111 /0 .391 /0 .672 /0 .281ms 可以看到通了,把这2个ip放到ansible的hosts里 2、添加hosts 1 2 3 4 [root@puppetansible] #tail-n3/etc/ansible/hosts [container_mysql] 172.16.1.2:22 172.16.1.3:22 3、使用ansible部署mysql A、部署mysql master,在test1节点部署 1 time ansible-playbookmysql_master_install.yml--extra-vars "host=172.16.1.2user=rootmysql_slave_ip=172.16.1.3" -k mysql_slave_ip是从库的ip,弄这个是在master里给slave进行账号授权 下面开始部署 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 root@puppetansible] #timeansible-playbookmysql_master_install.yml--extra-vars"host=172.16.1.2user=rootmysql_slave_ip=172.16.1.3"-k SSHpassword: PLAY[172.16.1.2]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.16.1.2] TASK:[common|Installinitializtionrequiresoftware]*********************** changed:[172.16.1.2] TASK:[mysql_master_install|CopyMysqlSoftwareToRedhatClient]*********** changed:[172.16.1.2] TASK:[mysql_master_install|CreateMysqlUserInRedhatClient]************* changed:[172.16.1.2] TASK:[mysql_master_install|CopyMysqlStartScriptToRedhatClient]******* changed:[172.16.1.2] TASK:[mysql_master_install|CopyInstallMysqlScriptToRedhatClient]**** changed:[172.16.1.2] TASK:[mysql_master_install|CopyMysqlConfigToRedhatClient]************* changed:[172.16.1.2] TASK:[mysql_master_install|CopyMysqlSecurityScriptToRedhatClient]**** changed:[172.16.1.2] TASK:[mysql_master_install|CreateMysqlInstallDir]*********************** ok:[172.16.1.2] TASK:[mysql_master_install|UncompressionMysqlSoftwareToRedhatClient]*** changed:[172.16.1.2] TASK:[mysql_master_install|ModifyMysqlDirPermissionInRedhatClient]*** ok:[172.16.1.2]=>(item= /data/mysql/datadir ) ok:[172.16.1.2]=>(item= /data/mysql/basedir ) TASK:[mysql_master_install|InstallMysqlScriptInRedhatClient]********** changed:[172.16.1.2] TASK:[mysql_master_install|WaitUntilsMysqlServiceAvaiableInRedhatClient]*** changed:[172.16.1.2] TASK:[mysql_master_install|StartMyqlSecurityScriptInRedhatClient]**** changed:[172.16.1.2] TASK:[mysql_master_install|AddBootStartMysqlServiceInRedhatClient]*** changed:[172.16.1.2] TASK:[mysql_master_install|CopyMysqlCreateSlaveScriptToRedhatClient]*** changed:[172.16.1.2] TASK:[mysql_master_install|CreateMysqlMasterAndSlaveInredhatClient]*** changed:[172.16.1.2] TASK:[mysql_master_install|DeleteCreateMysqlMasterAndSlaveScriptInredhatClient]*** changed:[172.16.1.2] TASK:[mysql_master_install|DeleteMysqlcompressionSoftwareInRedhatClient]*** changed:[172.16.1.2] PLAYRECAP******************************************************************** 172.16.1.2:ok=19changed=16unreachable=0failed=0 real 3m2.646s user 0m14.250s sys 0m0.854s 可以看到3分钟部署完成,最浪费时间的是yum安装基础库 现在去test1里查看 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 [root@puppetansible] #ssh172.16.1.2 root@172.16.1.2'spassword: Lastlogin:MonNov1714:10:392014from172.17.42.1 root@b8d17d0f3941:~ 15:02:39 #netstat-tlnp ActiveInternetconnections(onlyservers) ProtoRecv-QSend-QLocalAddressForeignAddressStatePID /Program name tcp00172.16.1.2:33060.0.0.0:*LISTEN- tcp000.0.0.0:220.0.0.0:*LISTEN8 /sshd tcp00:::80:::*LISTEN14 /httpd tcp00:::22:::*LISTEN8 /sshd root@b8d17d0f3941:~ root@b8d17d0f3941:~ 15:03:12 #mysql-h172.16.1.2-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnection id is12 Serverversion:5.5.21-logSourcedistribution Copyright(c)2000,2011,Oracleand /or itsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand /or its affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type 'help;' or '\h' for help.Type '\c' to clear thecurrentinputstatement. mysql>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |mysql| |performance_schema| +--------------------+ 3rows in set (0.00sec) mysql>usemysql Readingtableinformation for completionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql> select host,user,passwordfromuser; +------------+--------+-------------------------------------------+ |host|user|password| +------------+--------+-------------------------------------------+ |localhost|root|*BE78618CBAFFF409CE17D81579C1678B94439BE1| |172.16.1.3|root|*BE78618CBAFFF409CE17D81579C1678B94439BE1| |172.16.1.2|root|*BE78618CBAFFF409CE17D81579C1678B94439BE1| |%|zabbix|*DEEF4D7D88CD046ECA02A80393B7780A63E7E789| +------------+--------+-------------------------------------------+ 4rows in set (0.00sec) mysql> 可以看到数据库部署成功,并已经给予slave授予了权限。 B、部署从库 在test2节点部署 1 time ansible-playbookmysql_slave_install.yml--extra-vars "host=172.16.1.3user=rootmysql_master_ip=172.16.1.2mysql_master_port=3306mysql_master_user=rootmysql_master_passwd=E4yR3WnoluSFTCBAI" -k mysql_master_ip是mysql master的ip mysql_master_port是mysql master的mysql端口 mysql_master_user是mysql master的mysql用户 mysql_master_passwd是mysql 的密码 如果你使用我模块部署mysql的master了,直接运行命令就行,如果没有,只想单独弄个从库,主库不弄,那么第一步创建mysql master就不需要,只需要你在mater里授予slave的权限,然后运行mysql slave的模块就行 下面是运行情况 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 [root@puppetansible] #timeansible-playbookmysql_slave_install.yml--extra-vars"host=172.16.1.3user=rootmysql_master_ip=172.16.1.2mysql_master_port=3306mysql_master_user=rootmysql_master_passwd=E4yR3WnoluSFTCBAI"-k SSHpassword: PLAY[172.16.1.3]************************************************************* GATHERINGFACTS*************************************************************** ok:[172.16.1.3] TASK:[common|Installinitializtionrequiresoftware]*********************** changed:[172.16.1.3] TASK:[mysql_slave_install|CopyMysqlSoftwareToRedhatClient]************ changed:[172.16.1.3] TASK:[mysql_slave_install|CreateMysqlUserInRedhatClient]************** changed:[172.16.1.3] TASK:[mysql_slave_install|CopyMysqlStartScriptToRedhatClient]******** changed:[172.16.1.3] TASK:[mysql_slave_install|CopyInstallMysqlScriptToRedhatClient]***** changed:[172.16.1.3] TASK:[mysql_slave_install|CopyMysqlConfigToRedhatClient]************** changed:[172.16.1.3] TASK:[mysql_slave_install|CopyMysqlSecurityScriptToRedhatClient]***** changed:[172.16.1.3] TASK:[mysql_slave_install|CreateMysqlInstallDir]************************ ok:[172.16.1.3] TASK:[mysql_slave_install|UncompressionMysqlSoftwareToRedhatClient]*** changed:[172.16.1.3] TASK:[mysql_slave_install|ModifyMysqlDirPermissionInRedhatClient]**** ok:[172.16.1.3]=>(item= /data/mysql/datadir ) ok:[172.16.1.3]=>(item= /data/mysql/basedir ) TASK:[mysql_slave_install|InstallMysqlScriptInRedhatClient]*********** changed:[172.16.1.3] TASK:[mysql_slave_install|WaitUntilsMysqlServiceAvaiableInRedhatClient]*** changed:[172.16.1.3] TASK:[mysql_slave_install|StartMyqlSecurityScriptInRedhatClient]***** changed:[172.16.1.3] TASK:[mysql_slave_install|AddBootStartMysqlServiceInRedhatClient]*** changed:[172.16.1.3] TASK:[mysql_slave_install|CopyMysqlCreateSlaveScriptToRedhatClient]*** changed:[172.16.1.3] TASK:[mysql_slave_install|CreateMysqlMasterAndSlaveInredhatClient]*** changed:[172.16.1.3] TASK:[mysql_slave_install|DeleteCreateMysqlMasterAndSlaveScriptInredhatClient]*** changed:[172.16.1.3] TASK:[mysql_slave_install|DeleteMysqlcompressionSoftwareInRedhatClient]*** changed:[172.16.1.3] PLAYRECAP******************************************************************** 172.16.1.3:ok=19changed=16unreachable=0failed=0 real 2m59.966s user 0m14.413s sys 0m0.987s 部署完成,下面测试一下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 15:26:22 #netstat-tlnp ActiveInternetconnections(onlyservers) ProtoRecv-QSend-QLocalAddressForeignAddressStatePID /Program name tcp00172.16.1.3:33060.0.0.0:*LISTEN- tcp000.0.0.0:220.0.0.0:*LISTEN8 /sshd tcp00:::80:::*LISTEN14 /httpd tcp00:::22:::*LISTEN8 /sshd root@4ac2891ba3fd:~ 15:26:27 #mysql-h172.16.1.3-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnection id is16 Serverversion:5.5.21-logSourcedistribution Copyright(c)2000,2011,Oracleand /or itsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand /or its affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type 'help;' or '\h' for help.Type '\c' to clear thecurrentinputstatement. mysql>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |mysql| |performance_schema| +--------------------+ 3rows in set (0.01sec) mysql>showprocesslist; +----+-------------+------------------+------+---------+------+-----------------------------------------------------------------------------+------------------+-----------+---------------+-----------+ |Id|User|Host|db|Command|Time|State|Info|Rows_sent|Rows_examined|Rows_read| +----+-------------+------------------+------+---------+------+-----------------------------------------------------------------------------+------------------+-----------+---------------+-----------+ |11|systemuser||NULL|Connect|192|Waiting for mastertosendevent|NULL|0|0|1| |12|systemuser||NULL|Connect|192|Slavehas read allrelaylog;waiting for theslaveI /O threadtoupdateit|NULL|0|0|1| |14|root|172.16.1.3:53445|NULL|Query|0|NULL|showprocesslist|0|0|4| +----+-------------+------------------+------+---------+------+-----------------------------------------------------------------------------+------------------+-----------+---------------+-----------+ 3rows in set (0.00sec) mysql>showslavestatus\G ***************************1.row*************************** Slave_IO_State:Waiting for mastertosendevent Master_Host:172.16.1.2 Master_User:mysql_sync Master_Port:3306 Connect_Retry:60 Master_Log_File:mysql-bin.000003 Read_Master_Log_Pos:1663 Relay_Log_File:mysql-relay-bin.000002 Relay_Log_Pos:253 Relay_Master_Log_File:mysql-bin.000003 Slave_IO_Running:Yes Slave_SQL_Running:Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno:0 Last_Error: Skip_Counter:0 Exec_Master_Log_Pos:1663 Relay_Log_Space:409 Until_Condition:None Until_Log_File: Until_Log_Pos:0 Master_SSL_Allowed:No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master:0 Master_SSL_Verify_Server_Cert:No Last_IO_Errno:0 Last_IO_Error: Last_SQL_Errno:0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id:2 1row in set (0.00sec) 可以看到从库数据库创建成功,并且主从(sql与i这2个状态也是yes)创建成功。 C、测试主从状态 在master里创建一个数据库mysql_master,并创建表test插入数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 [root@puppetansible] #ssh172.16.1.2 root@172.16.1.2'spassword: Lastlogin:ThuMar515:02:392015from10.10.11.125 root@b8d17d0f3941:~ 15:27:20 #mysql-h172.16.1.2-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnection id is17 Serverversion:5.5.21-logSourcedistribution Copyright(c)2000,2011,Oracleand /or itsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand /or its affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type 'help;' or '\h' for help.Type '\c' to clear thecurrentinputstatement. mysql>createdatabasemysql_master; QueryOK,1rowaffected(0.00sec) mysql>usemysql_master Databasechanged mysql>createtable test ( id int,namevarchar(4)); QueryOK,0rowsaffected(0.03sec) mysql>desc test ; +-------+------------+------+-----+---------+-------+ |Field|Type|Null|Key|Default|Extra| +-------+------------+------+-----+---------+-------+ | id |int(11)|YES||NULL|| |name|varchar(4)|YES||NULL|| +-------+------------+------+-----+---------+-------+ 2rows in set (0.00sec) mysql>insertinto test value(1, 'test1' ); QueryOK,1rowaffected,1warning(0.00sec) mysql>insertinto test value(2, 'test2' ); QueryOK,1rowaffected,1warning(0.00sec) mysql> select *from test ; +------+------+ | id |name| +------+------+ |1| test | |2| test | +------+------+ 2rows in set (0.00sec) 然后去从库里查看 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 [root@puppetansible] #ssh172.16.1.3 root@172.16.1.3'spassword: Lastlogin:ThuMar515:25:062015from10.10.11.125 root@4ac2891ba3fd:~ 15:31:05 #mysql-h172.16.1.3-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnection id is17 Serverversion:5.5.21-logSourcedistribution Copyright(c)2000,2011,Oracleand /or itsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand /or its affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type 'help;' or '\h' for help.Type '\c' to clear thecurrentinputstatement. mysql>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |mysql| |mysql_master| |performance_schema| +--------------------+ 4rows in set (0.00sec) mysql>usemysql_master Readingtableinformation for completionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql>showtables; +------------------------+ |Tables_in_mysql_master| +------------------------+ | test | +------------------------+ 1row in set (0.00sec) mysql> select *from test ; +------+------+ | id |name| +------+------+ |1| test | |2| test | +------+------+ 2rows in set (0.00sec) 可以看到从库也同步了数据,mysql主从创建成功。 四、模块地址 mysql master 地址 1 https: //github .com /dl528888/ansible-examples/tree/master/mysql_master_install mysql slave地址 1 https: //github .com /dl528888/ansible-examples/tree/master/mysql_slave_install 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1617692 ,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册