ansible 部署zabbix_agentd(分应用)
2017-10-09 17:31
423 查看
主机hosts
生成动态inventory
生成批量部署ansible-playbook
得到ansible.sh
ansible-playbook -i /etc/ansible/devhosts.py install.yml --extra-vars "host=all"
复制sudoers,可以准备几个sudoers
ansible -i /etc/ansible/devhosts.py all -m copy -a 'src=/etc/ansible/zabbix/sudoers dest=/etc/sudoers mode=440'
注意权限
chown -R zabbix.zabbix /usr/local/zabbix
手动安装
最后,把主机hosts文件插入数据库
tomcat 192.1.1.121 redis 192.1.1.121 mongodb 192.1.1.121 tomcat 192.1.1.122 tomcat 192.1.1.123 redis 192.1.1.124 mongodb 192.1.1.124 tomcat 192.1.1.124 other 192.1.1.125 tomcat 192.1.1.126 fastdfs 192.1.1.127 fastdfs 192.1.1.128 fastdfs 192.1.1.129 other 192.1.1.130 other 192.1.1.131 fastdfs 192.1.1.132 fastdfs 192.1.1.133
生成动态inventory
devhosts.py #!/usr/bin/python # coding:utf-8 import sys try: import json except ImportError: import simplejson as json def grouplist(): inventory = {} # inventory['local'] = ['127.0.0.1'] # sfile = '/etc/ansible/books.txt' sfile = 'books.txt' with open(sfile, 'rb') as f: for i in f.readlines(): group = i.strip().split()[0] name = i.strip().split()[1] if not group in inventory: inventory[group] = { 'hosts': [] } inventory[group]['hosts'].append(name) print json.dumps(inventory, indent=4) def hostinfo(name): vars = {} vars = { 'admin': 'Jane Jolie', 'datacenter': 1 } print json.dumps(vars, indent=4) if __name__ == '__main__': if len(sys.argv) == 2 and (sys.argv[1] == '--list'): grouplist() elif len(sys.argv) == 3 and (sys.argv[1] == '--host'): hostinfo(sys.argv[2]) else: print "Usage: %s --list or --host <hostname>" % sys.argv[0] sys.exit(1)
生成批量部署ansible-playbook
devansible.py #!/usr/bin/python # coding:utf-8 import sys try: import json except ImportError: import simplejson as json dfile = 'ansible.sh' def grouplist(): inventory = {} # inventory['local'] = ['127.0.0.1'] # sfile = '/etc/ansible/books.txt' sfile = 'books.txt' with open(sfile, 'rb') as f: for i in f.readlines(): group = i.strip().split()[0] name = i.strip().split()[1] if not group in inventory: inventory[group] = { 'hosts': [] } inventory[group]['hosts'].append(name) # print json.dumps(inventory, indent=4) return inventory def hostinfo(name): vars = {} vars = { 'admin': 'Jane Jolie', 'datacenter': 1 } print json.dumps(vars, indent=4) def ansiblelast(): inventory = grouplist() keys = [] stringlist = [] for key, item in inventory.iteritems(): keys.append(key) print keys for key in keys: stringa = 'ansible-playbook -i /etc/ansible/devhosts.py %s.yml --extra-vars ' \ '"host=%s"' % (key,key) stringlist.append(stringa) with open(dfile, 'wb') as f1: for i in stringlist: line = str(i) + "\n" f1.write(line) if __name__ == '__main__': ansiblelast()
得到ansible.sh
ansible-playbook -i /etc/ansible/devhosts.py fastdfs.yml --extra-vars "host=fastdfs" ansible-playbook -i /etc/ansible/devhosts.py mongodb.yml --extra-vars "host=mongodb" ansible-playbook -i /etc/ansible/devhosts.py other.yml --extra-vars "host=other" ansible-playbook -i /etc/ansible/devhosts.py redis.yml --extra-vars "host=redis" ansible-playbook -i /etc/ansible/devhosts.py tomcat.yml --extra-vars "host=tomcat"默认最基本的模板
ansible-playbook -i /etc/ansible/devhosts.py install.yml --extra-vars "host=all"
复制sudoers,可以准备几个sudoers
ansible -i /etc/ansible/devhosts.py all -m copy -a 'src=/etc/ansible/zabbix/sudoers dest=/etc/sudoers mode=440'
注意权限
chown -R zabbix.zabbix /usr/local/zabbix
手动安装
useradd zabbix -s /sbin/nologin touch /var/log/zabbix_agentd.log chmod 777 /var/log/zabbix_agentd.log sudoers
最后,把主机hosts文件插入数据库
相关文章推荐
- 线上应用: ZABBIX监控部署安装
- ansible自动部署 zabbix-agent 的模块
- ansible的安装部署及简单应用
- Ansible部署Zabbix监控工具
- Centos6.5_salt自动部署zabbix_agentd(二)-- 部署windows以及linux系统
- 使用 Ansible 部署无服务(serverless)应用
- Zabbix应用之Server/Agent部署
- zabbix应用之proxy分布式部署(1)
- ansible自动化部署zabbix客户端
- ansible 批量安装zabbix agentd客户端
- ANSIBLE部署ZABBIX客户端
- ansible部署及应用--持续更新中
- zabbix应用之proxy分布式部署(2)
- zabbix-agentd部署
- 通过Ansible 安装部署 TiDB 及将 TiDB作为Zabbix 的数据库
- 使用ansible结合FTP部署zabbix_agent
- 用 Ansible 部署无服务应用!
- ansible部署zabbix客户端
- ansible部署zabbix客户端
- 自动化运维工具Ansible架构部署应用及playbooks简单应用