关键词:
准备前提
配置ansible主机详情:https://www.cnblogs.com/security-guard/
nginx的安装
编写nginx的自动部署文件nginx.yml hosts主机更改为自己定义的
访问目标主机组的IP地址,查看测试页面
测试页面:显示的是本机ip
<h1>ansible_all_ipv4_addresses</h1>
lnmp架构自动部署
首先免密登录配置
编写lnmp的脚本 lnmp.yml
结果:
ansible自动部署tomcat
--- - hosts: tomcat tasks: - name: 关闭防火墙 service: name=iptables state=stopped - name: 关闭selinux shell: setenforce 0 - name: 安装所需的软件 yum: name=tar,libselinux-python state=latest - name: 推送jdk java环境 copy: src=jdk-8u131-linux-x64_.rpm dest=/root - name: 创建文件夹 file: path=/opt/tomcat state=directory - name: 推送tomcat的压缩包 unarchive: src=apache-tomcat-8.5.35.tar.gz dest=/opt/tomcat - name: 安装jdk yum: name=jdk-8u131-linux-x64_.rpm state=installed - name: 启动tomcat shell: nohup /opt/tomcat/apache-tomcat-8.5.35/bin/startup.sh &
--- - hosts: lnmp tasks: - name: 关闭防火墙 service: name=iptables state=stopped - name: 关闭selinux shell: setenforce 0 - name: 配置相关组件以及MySQL yum: name=zlib-devel,pcre-devel,gcc,gcc-c++,php,php-mysql,php-gd,php-fpm,libselinux-python,tar,vim,unzip state=latest - name: 推送nginx安装包 unarchive: src=nginx-1.16.1.tar.gz dest=/root - name: 安装nginx shell: cd /root/nginx-1.16.1 && ./configure && make && make install - name: 启动nginx shell: netstat -ntlp | grep -q nginx || /usr/local/nginx/sbin/nginx - name: 推送ningx的配置文件 template: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf tags: config-nginx notify: restart-nginx - name: 启动php-fpm service: name=php-fpm state=started - name: 安装mysql yum: name=mysql,mysql-server state=latest - name: 启动mysql service: name=mysqld state=started - name: 删除数据库如果存在 shell: mysql -e "drop database if exists ds;" - name: 创建数据库 shell: mysql -e "create database ds charset=utf8;" - name: 给用户授权 shell: mysql -e "grant all on *.* to ‘tom‘@‘%‘ identified by ‘123‘;" - name: 刷新权限 shell: mysql -e "flush privileges;" - name: 推送电商的安装包并给予权限 unarchive: src=tinyshopV2.5_data.zip dest=/usr/local/nginx/html/ mode=777 handlers: - name: restart-nginx shell: /usr/local/nginx/sbin/nginx -s reload
要求操作系统:centos7
[root@localhost zabbix]# rpm -ivh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm 获取http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm 警告:/var/tmp/rpm-tmp.MEfeuA: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:zabbix-release-4.4-1.el7 ################################# [100%] [root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent [root@localhost ~]# yum -y install mariadb mariadb-server [root@localhost ~]# systemctl start mariadb [root@localhost ~]# systemctl enable mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 2 Server version: 5.5.64-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement. MariaDB [(none)]> create database zabbix charset=utf8; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on *.* to ‘zabbix‘@‘localhost‘ identified by ‘123‘; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye [root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-4.4.1/ [root@localhost zabbix-server-mysql-4.4.1]# ls AUTHORS ChangeLog COPYING create.sql.gz NEWS README [root@localhost zabbix-server-mysql-4.4.1]# zcat create.sql.gz | mysql -uzabbix -p123 zabbix [root@localhost ~]# vim /etc/zabbix/zabbix_server.conf DBName=zabbix //创建的数据库的名字 DBUser=zabbix //用户 DBPassword=123 //用户的密码 [root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf php_value date.timezone Asia/Shanghai [root@localhost ~]# systemctl restart httpd zabbix-server zabbix-agent
ansible-playbook
ansible-playbook(1) Ansible组成部分InventoryModulesAdHocCommandsplaybooksplaybooks:Tasks:任务,即调用的模块完成的某操作variables:变量Templates:模版Roles:角色 基本结构:-host:webserverremote_user:tasks:-task1 module_name:MODULE_NAME-task2 简单... 查看详情
ansible-playbook实例
准备前提配置ansible主机详情:https://www.cnblogs.com/security-guard/ nginx的安装编写nginx的自动部署文件nginx.yml hosts主机更改为自己定义的 访问目标主机组的IP地址,查看测试页面测试页面:显... 查看详情
ansible-playbook手工编译安装nginx
虽然nginx也可以通过yum安装,但是如何使用源码包安装并自定义开启一些nginx功能模块,并且通过ansible下发到被管理集群呢?下面给给位看官提供一个具体实例以供参考。首先我们需要手工编译好一台nginx服务器作为模板,再采... 查看详情
ansible-playbook调试
转载于互联网检测远程主机信息 ansible-i/XXXXX.hostsdev107-msetup 1.ansible-playbook 1)ansible-playbook的语法检测1[root@test-1bin]#ansible-playbook--syntax-checknginx_tags.yaml23playbook:n 查看详情
ansible-playbook用法举例
ansible-playbook变量(vars)
ansible-playbook中定义变量:-hosts:webserversvars:http_port:80 ①、在host里定义变量执行结果: 查看详情
ansible-playbook拾遗
ansible-playbook 和handles一起使用---- hosts: webuser: roottasks:- name: ensure nginx is at the latest versionyum: name=nginx sta 查看详情
ansible-playbook 额外变量的顺序和优先级
】ansible-playbook额外变量的顺序和优先级【英文标题】:ansible-playbookextravarsorderandprecedence【发布时间】:2022-01-2315:25:08【问题描述】:我正在运行ansible-playbook和多个--extra-vars类似ansible-playbook--extra-vars@vars_a.yml--extra-vars@vars_b.yml--ex... 查看详情
2.ansible-playbook基本参数
不错学完了第一课我叫你ansible-playbook的参数--force-handlersrunhandlersevenifataskfails强制执行handler--list-tagslistallavailabletags列出标签--list-taskslistalltasksthatwouldbeexecuted列出要执行的tasks--skip-tags=SKIP_TAGSonlyru 查看详情
ansible-playbook
yaml的基本元素 变量 Inventory 条件测试 迭代 playbook的组成结构; Inventory modules AdhocCommand playbooks tasks:任务 variables:变量 template:模板 handler:处理器 roles:角色 基本结构: -hosts:webservers remot 查看详情
ansible-playbook批量添加zabbix监控项目同步配置信息
前言 在上一篇教程中我们已经实现了使用ansible-playbook批量在远程主机上部署zabbix客户端并正常运行,现在我们再次通过ansible-playbook给客户端主机批量增加zabbix监控项目配置(创建监控项目示例:自动发现远程主机监听的TCP... 查看详情
ansible-playbook使用示例参考
ansible-playbook参考(1)基础示例~]# vim base.yaml- hosts: 192.168.1.114 remote_user: root tasks: - name: install httpd server&nbs 查看详情
ansible-playbook使用示例参考
ansible-playbook参考(1)基础示例~]# vim base.yaml- hosts: 192.168.1.114 remote_user: root tasks: - name: install httpd server&nbs 查看详情
ansible-playbook
语言格式:yml 单个yml文件示例: ----hosts:webservers#主机组vars:##变量设置http_port:80max_clients:200remote_user:roottasks:###主要任务-name:ensureapacheisatthelatestversionyum:pkg=httpdstate=latest-name:writetheapache 查看详情
ansible-playbook
playbook: 通过事先编写好的playbook文件实现批量管理操作 ===============ansible的任务集注意:1.yml中不可使用tabs键2.缩进对齐,严格控制缩进3.#表注释4.---开头 playbook文件 :是ansible主机用于配置,部署和管理托管主机... 查看详情
ansible-playbook主机变量2
ansible-playbook配置hosts后可以指定变量,通过-k可以交互输入密码,也可以将密码写在hosts文件中。入口yaml文件中通过{{**}}获取变量,命令行通过-i指定hosts文件,-e传入参数,如果同时传入多个host参数可使用逗号分隔,同时也可以... 查看详情
ansible-playbook剧本编写(代码片段)
Ansible-playbook一.playbooks组成1.playbooks本身由以下各部分组成二.示例2.when条件判断3.迭代4.Templates模块5.tags模块6.Roles模块一.playbooks组成1.playbooks本身由以下各部分组成(1)Tasks:任务,即通过task调用ansible的模板将多个操作组织在一... 查看详情
ansible-playbook剧本编写(代码片段)
Ansible-playbook一.playbooks组成1.playbooks本身由以下各部分组成二.示例2.when条件判断3.迭代4.Templates模块5.tags模块6.Roles模块一.playbooks组成1.playbooks本身由以下各部分组成(1)Tasks:任务,即通过task调用ansible的模板将多个操作组织在一... 查看详情