使用ansible-playbook脚本部署服务器环境,以及必要的软件。

简介: 使用ansible-playbook脚本部署服务器环境,以及必要的软件。配合下面链接脚本使用,效果更加。https://developer.aliyun.com/article/834279?spm=a2c6h.13148508.0.0.66ec4f0er2JWkj
---#固定格式- hosts: genghuanip      #定义需要执行主机  remote_user: root       #远程用户  vars:                   #定义变量    http_port: 8088       #变量  tasks:                             #定义一个任务的开始#安装环境    - name: yum env         #定义任务的名称      yum: name=epel-release,sysstat,dstat,net-tools,wget,lrzsz,mailx,vim,tcpdump,iotop state=installed   #调用模块,具体要做的事情#创建文件夹    - name: mkdir tools         #定义任务的名称      file: path=/tools state=directory
      tags: mkdir_tools
#关闭selinux    - name: disable selinux
      lineinfile: path=/etc/selinux/config regexp="^SELINUX=" line="SELINUX=disabled"      tags: selinux
#修改邮箱配置文件    - name: mail config
      shell: echo -e "set from=发件邮箱名 \nset smtp=smtps://smtp.exmail.qq.com:465 \nset smtp-auth-user=发件邮箱 \nset smtp-auth-password=邮箱服务密码 \nset smtp-auth=login \nset ssl-verify=ignore \nset nss-config-dir=/root/.certs" >> /etc/mail.rc
      tags: configmail
#邮箱证书    - name: mail cert
      shell: mkdir -p /root/.certs/  && cd /root/.certs/ && echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'> ~/.certs/exmail.qq.crt && certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/exmail.qq.crt && certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/exmail.qq.crt && certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i exmail.qq.crt && certutil -L -d /root/.certs
      tags: mailcert
#传输装机文件夹    - name: scp file
      copy: src=/tools/lxj-zj/ dest=/tools/
      tags: scp
#添加服务器检测脚本定时任务    - name: add monitor cron
      cron: name="服务器性能,磁盘等检测" minute=*/10 job='python /tools/monitor/monitor.py >> /tools/monitor/m.log 2>&1 &'      tags: monitor
#添加定时任务备份任务    - name: add cronbackup cron
      cron: name="cron定时任务备份脚本" minute=30 hour=19 job='bash /tools/crontab/cron_backup.sh >> /tools/crontab/cron_backup.log 2>&1 &'      tags: addcronbk
#安装fail2ban软件    - name: add fail2ban
      shell: cd /tools/fail2ban &&  tar -zxvf fail2ban-0.9.4.tar.gz && cd fail2ban-0.9.4 && ./setup.py install && mv /etc/fail2ban/jail.conf /etc/fail2ban/jail.conf.bak && mv /etc/fail2ban/action.d/mail-whois-lines.conf /etc/fail2ban/action.d/mail-whois-lines.conf.bak && cp /tools/fail2ban/jail.conf /etc/fail2ban/ && cp /tools/fail2ban/mail-whois-lines.conf /etc/fail2ban/action.d/ && cp /tools/fail2ban/fail2ban-0.9.4/files/redhat-initd /etc/init.d/fail2ban && sed -i 's@Starting fail2ban.*@&\n    [ ! -e "/var/run/fail2ban" ] \&\& mkdir /var/run/fail2ban@' /etc/init.d/fail2ban && chkconfig fail2ban on && service fail2ban start
      tags: addfail2ban
#安装nodee_exporter    - name: add node_exporter
      shell: cd /tools && tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/ && cd /usr/local/ && mv node_exporter-0.18.1.linux-amd64/ node_exporter && firewall-cmd --add-port=9100/tcp --permanent && firewall-cmd --reload && chmod +x /etc/rc.local && echo 'nohup /usr/local/node_exporter/node_exporter > /usr/local/node_exporter/node_exporter.log 2>&1 &' >> /etc/rc.local && nohup /usr/local/node_exporter/node_exporter > /usr/local/node_exporter/node_exporter.log 2>&1 &
      tags: addnodeexporter
    - name: 添加管理用户       #定义任务的名称      user: name=jumpadmin password="用户密码"#调用模块,具体要做的事情    - name: 添加sudo         #定义任务的名称      blockinfile: path=/etc/sudoers block="jumpadmin    ALL=(ALL)       NOPASSWD:ALL"      tags: addsudo
#安装用户检测脚本    - name: add check users
      shell: /bin/bash /tools/monitor/xs_user_passwd_monitor.sh install
      tags: addcheckusers
#添加用户检测脚本定时任务    - name: add checkusers cron
      cron: name="user-monitor   log:/tmp/diff.log" minute=*/10 job='/bin/bash /tools/monitor/xs_user_passwd_monitor.sh start'      tags: addcheckuserscron
#删除180天前的历史命令记录    - name: delete 180history
      cron: name="删除180天前的历史命令记录" minute=30 hour=19 job='find /var/log/history_record/ -type f -mtime +180 -delete'      tags: delete_180history
#复制调用脚本    - name: scp file
      copy: src=/etc/ansible/playbook/hs_rcd.sh dest=/etc/profile.d/
      tags: scp
目录
相关文章
|
20天前
|
弹性计算 人工智能 前端开发
在阿里云ECS上部署n8n自动化工作流:U2实例实战
本文介绍如何在阿里云ECS的u2i/u2a实例上部署开源工作流自动化平台n8n,利用Docker快速搭建并配置定时任务,实现如每日抓取MuleRun新AI Agent并推送通知等自动化流程。内容涵盖环境准备、安全组设置、实战案例与优化建议,助力高效构建低维护成本的自动化系统。
252 5
|
28天前
|
Java Linux Apache
在CentOS服务器上编译并部署NiFi源码
部署Apache NiFi在CentOS上是一个涉及细节的过程,需要注意Java环境、源码编译、配置调整等多个方面。遵循上述步骤,可以在CentOS服务器上成功部署和配置Apache NiFi,从而高效地处理和分发数据。
118 17
|
2月前
|
弹性计算 安全 Linux
使用阿里云服务器安装Z-Blog博客网站流程,新手一键部署教程
本教程教你如何在阿里云99元服务器上,通过宝塔Linux面板一键部署Z-Blog博客。基于CentOS 7.9系统,从远程连接、安装宝塔面板、开放端口到部署Z-Blog全流程详解,操作简单,新手也能轻松搭建个人博客网站。
352 13
|
2月前
|
弹性计算 Devops Shell
用阿里云 DevOps Flow 实现 ECS 部署自动化:从准备到落地的完整指南
阿里云 DevOps Flow 是一款助力开发者实现自动化部署的高效工具,支持代码流水线构建、测试与部署至ECS实例,显著提升交付效率与稳定性。本文详解如何通过 Flow 自动部署 Bash 脚本至 ECS,涵盖环境准备、流水线搭建、源码接入、部署流程设计及结果验证,助你快速上手云上自动化运维。
190 0
监控 安全 Linux
89 0
|
3月前
|
人工智能 缓存 监控
构建高效MCP客户端:应对多服务器环境的完整指南
本文深入探讨了在多服务器环境下构建高效、可靠的Model Context Protocol(MCP)客户端的关键技术与最佳实践。内容涵盖MCP基础架构、连接管理、请求路由、容错机制、会话管理、性能监控及安全认证等核心设计,提供了完整的实现类与部署配置示例,助力开发者构建高性能MCP客户端,提升AI模型与工具集成的效率与稳定性。
|
3月前
|
存储 监控 Linux
Dell OpenManage Enterprise 4.5 - Dell 服务器、存储和网络设备集中管理软件
Dell OpenManage Enterprise 4.5 - Dell 服务器、存储和网络设备集中管理软件
73 0

热门文章

最新文章