自动化安装zabbix-agent
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
| --- - hosts: redis tasks: - name: 换源 shell: "cp -a /etc/yum.repos.d /etc/yum.repos.d.backup && rm -rf /etc/yum.repos.d/*" - get_url: url: http://mirrors.aliyun.com/repo/Centos-7.repo dest: /etc/yum.repos.d/CentOS-Base.repo mode: '0644' - get_url: url: https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm dest: /tmp/zabbix-release-5.0-1.el7.noarch.rpm mode: '0644' - name: 更新源 shell: "rpm -Uvh /tmp/zabbix-release-5.0-1.el7.noarch.rpm && yum clean all && yum makecache" - name: yum安装zabbix-agent2 yum: name: zabbix-agent2 state: present - name: 服务开机自启 service: name: zabbix-agent2 enabled: yes state: started - name: 备份配置文件 shell: "mv /etc/zabbix/zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf.bak" - name: 配置文件写入自动注册 blockinfile: path: /etc/zabbix/zabbix_agent2.conf block: | PidFile=/var/run/zabbix/zabbix_agent2.pid LogFile=/var/log/zabbix/zabbix_agent2.log LogFileSize=0 Server=192.168.10.171 ServerActive=192.168.10.171 Include=/etc/zabbix/zabbix_agent2.d/*.conf ControlSocket=/tmp/agent.sock HostnameItem=system.hostname HostMetadataItem=system.hostname create: yes - name: 重启agent service: name: zabbix-agent2 state: restart
|


自动安装tomcat
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
| --- - hosts: test name: 安全初始化 tasks: - lineinfile: path: /etc/selinux/config regexp: '^SELINUX=' line: SELINUX=enforcing - systemd: name: firewalld state: stopped enabled: no - name: jdk环境准备与测试 hosts: test tasks: - copy: src: /root/jdk-8u421-linux-x64.tar.gz dest: /tmp/jdk-8u421-linux-x64.tar.gz owner: root group: root mode: '0644' - file: path: /usr/local/jdk1.8.0_421 state: absent - unarchive: src: /tmp/jdk-8u421-linux-x64.tar.gz dest: /usr/local/ remote_src: yes owner: root group: root mode: '0755' - lineinfile: path: /etc/profile state: present line: export JAVA_HOME=/usr/local/jdk1.8.0_421 - name: 测试java命令是否可用 shell: "source /etc/profile && /usr/local/jdk1.8.0_421/bin/java -version" - name: tomcat环境准备 hosts: test tasks: - name: 下载tomcat包 get_url: url: https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.95/bin/apache-tomcat-9.0.95.tar.gz dest: /tmp/apache-tomcat-9.0.95.tar.gz mode: '0644' - file: path: /usr/local/tomcat state: absent - unarchive: src: /tmp/apache-tomcat-9.0.95.tar.gz dest: /tmp/ remote_src: yes owner: root group: root mode: '0755' - shell: "mv /tmp/apache-tomcat-9.0.95 /usr/local/tomcat" - shell: "/usr/local/tomcat/bin/version.sh" - debug: msg: "tomcat环境测试成功,版本正常获取"
|

自动安装nginx
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
| --- - hosts: test ignore_errors: true tasks: - user: name: www state: absent remove: yes - file: path: - /usr/local/nginx - /tmp/nginx-1.18.0.tar.gz - /tmp/nginx-1.18.0 state: absent - yum: name: - "@Development Tools" - openssl-devel.x86_64 - epel-release - pcre - pcre-devel state: present - name: 创建专用用户 user: name: www shell: /sbin/nologin create_home: no state: present - name: 下载nignx包 get_url: url: https://nginx.org/download/nginx-1.18.0.tar.gz dest: /tmp/nginx-1.18.0.tar.gz mode: '0644' - name: 解压nignx包 unarchive: src: /tmp/nginx-1.18.0.tar.gz dest: /tmp/ remote_src: yes owner: root group: root mode: '0755' - name: 编译安装nginx shell: | cd /tmp/nginx-1.18.0 && \ ./configure \ --user=www \ --group=www \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/nginx/sbin/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --error-log-path=/usr/local/nginx/logs/error.log \ --http-log-path=/usr/local/nginx/logs/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/lock/subsys/nginx \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-pcre && \ make && \ make install - name: 测试启动 shell: "/usr/local/nginx/sbin/nginx" - shell: "ss -tunlp | grep -w 80" - debug: msg: "nginx启动成功"
|
