文章目录

  • 一、核心功能描述
  • 二、roles内容
    • 2.1 文件结构
    • 2.2 主配置文件
    • 2.3 tasks文件内容
  • 三、files文件内容
  • 四、关键价值

免费个人运维知识库,欢迎您的订阅:literator_ray.flowus.cn

一、核心功能描述

这个 Ansible Role 的核心功能是:​实现 ​IBM HTTP Server (IHS) 访问日志的自动化监控分析。

  1. 环境自动化部署

    • 依赖安装​:自动安装编译工具链(gcc/automake等)及 Perl 环境

    • 组件部署​:解压 AWStats 主程序、配置模板和扩展插件(GeoIP/日志轮转工具)

  2. IHS 日志优化

    • **日志格式重构:**启用增强型日志格式(包含 User-Agent/Referer 等关键字段),集成 cronolog实现按天切割日志 (access_log.%Y%m%d)。

    • **虚拟主机配置:**动态生成虚拟主机配置(基于服务器 IP 和域名),映射 AWStats 资源路径 (如 /awstatsclasses→ 程序目录)。

  3. 安全与权限控制

    • **访问认证:**生成 Basic 认证密码文件 (awstats.passwd),限制 /awstats路径需认证访问(预设账号 admin)​

    • SELinux 适配​:自动设置上下文权限

  4. ​​智能配置管理

    • **动态配置生成:**基于主机名创建配置文件 (awstats.{{主机名}}.conf),自动适配日志路径 (access_log.%YYYY-24%MM-24%DD-24)。

    • 地理数据分析​:集成 GeoIP 组件实现访问者地理位置追踪。

  5. 持续运维机制

    • 定时统计任务:每日 00:10 自动更新分析数据 (awstats_updateall.pl)。

    • 服务集成:自动重启 IHS 服务 (ibmhttp) 及网络服务生效配置。

可以根据自己的实际需求修改脚本

二、roles内容

2.1 文件结构

roles/awstats/
|-- files
|   |-- awstats_conf.sh
|   |-- awstats-conf.tgz
|   |-- awstats-pack.tgz
|   |-- awstats.tgz
|   `-- URI-1.36.tar.gz
|-- tasks
|   |-- awstats_config.yml
|   |-- chcon.yml
|   |-- chown.yml
|   |-- cron.yml
|   |-- directory.yml
|   |-- group.yml
|   |-- htpasswd.yml
|   |-- httpd_config.yml
|   |-- main.yml
|   |-- make.yml
|   |-- service.yml
|   |-- unarchive.yml
|   |-- user.yml
|   `-- yum.yml
`-- templates|-- all-hosts.j2`-- awstats.example.conf.j23 directories, 21 files

2.2 主配置文件

---
- hosts: allremote_user: rootserial: 2roles:- awstats

2.3 tasks文件内容

  • main.yml
[root@ansible ansible]# cat roles/awstats/tasks/main.yml
- include: yum.yml
- include: unarchive.yml
- include: group.yml
- include: user.yml
- include: chown.yml
- include: directory.yml
- include: make.yml
- include: httpd_config.yml
- include: htpasswd.yml
- include: awstats_config.yml
- include: cron.yml
- include: chcon.yml
- include: service.yml
  • include: yum.yml
- name: install pkgyum: name={{ item }} state=presentloop:- gcc- automake- autoconf- libtool- make- zlib-devel- perl-ExtUtils-CBuilder- perl-ExtUtils-MakeMaker- cpan
  • include: unarchive.yml
- name: unarchive awstats pkgunarchive: src={{ item.src }} dest={{ item.dest }}loop:- { src: 'awstats.tgz', dest: '/usr/local/' }- { src: 'awstats-conf.tgz', dest: '/etc/' }- { src: 'awstats-pack.tgz', dest: '/root/'}- { src: 'URI-1.36.tar.gz', dest: '/root/' }- name: unarchive remote_host pkgunarchive: src={{ item.src }} dest={{ item.dest }} copy=noloop:- { src: '/root/awstats-pack/GeoIP.tar.gz', dest: '/root/awstats-pack/' }- { src: '/root/awstats-pack/Geo-IP-1.38.tar.gz', dest: '/root/awstats-pack/' }- { src: '/root/awstats-pack/Geo-IPfree-0.6.tar.gz', dest: '/root/awstats-pack/' }- { src: '/root/awstats-pack/cronolog-1.6.2.tar.gz', dest: '/root/awstats-pack/' }
  • include: group.yml
- name: create groupgroup: name=was system=yes
  • include: user.yml
- name: create useruser: name=was group=was system=yes state=present
  • include: chown.yml
- name: change permissionfile: path=/usr/local/awstats owner=was group=was recurse=yes
- name: chmod 755 logs directoryfile: path=/opt/IBM/HTTPServer/logs mode=0755
  • include: directory.yml
- name: create directoryfile: path=/var/lib/awstats state=directory owner=was group=was
  • include: make.yml
- name: perl makefile add configshell: chdir=/root/awstats-pack/Geo-IP-1.38 perl Makefile.PL LIBS='-L/usr/local/lib' INC='-I/usr/local/include'
- name: perl makefileshell: chdir={{ item }} perl Makefile.PLloop:- /root/awstats-pack/Geo-IPfree-0.6- /root/URI-1.36
- name: configureshell: chdir={{ item }} ./configureloop:- /root/awstats-pack/cronolog-1.6.2- /root/awstats-pack/GeoIP-1.4.6  
- name: make && make installshell: chdir={{ item }} make -j `lscpu | awk '/^CPU\(s\)/{print$2}'` && make installloop:- /root/awstats-pack/cronolog-1.6.2- /root/awstats-pack/GeoIP-1.4.6- /root/awstats-pack/Geo-IP-1.38- /root/awstats-pack/Geo-IPfree-0.6- /root/URI-1.36
  • include: httpd_config.yml
- name: edit httpd.conf configreplace: path=/opt/IBM/HTTPServer/conf/httpd.conf regexp={{ item.src }} replace={{ item.dest }}loop:- { src: '^(CustomLog logs/access_log common)', dest: '#\1' }- { src: '^(LogFormat "%{User-agent}i" agent)', dest: '\1\nLogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" all\nCustomLog "|/usr/local/sbin/cronolog /opt/IBM/HTTPServer/logs/access_log.%Y%m%d" all'}  
- name: write awstats config end of httpd.confscript: awstats_conf.sh
  • include: htpasswd.yml
- name: create htpasswdshell: chdir=/opt/IBM/HTTPServer/bin/ ./htpasswd -b /usr/local/awstats/wwwroot/cgi-bin/awstats.passwd admin longser*
- name: copy htpasswdcopy: src=/usr/local/awstats/wwwroot/cgi-bin/awstats.passwd dest=/etc/awstats/awstats.passwd remote_src=yes
  • include: awstats_config.yml
- name: template config to remote all-hoststemplate: src=all-hosts.j2 dest=/etc/awstats/all-hosts- name: template config to remote awstats.xxx.conftemplate: src=awstats.example.conf.j2 dest=/etc/awstats/awstats.{{ ansible_facts.hostname }}.conf- name: edit awstats.all.conf LogFilereplace: path=/etc/awstats/awstats.all.conf regexp='^(LogFile=).*' replace='\1"/opt/IBM/HTTPServer/logs/access_log.%YYYY-24%MM-24%DD-24"'- name: delete default templatefile: path={{ item }} state=absentloop:- /etc/awstats/awstats.ghtj.conf- /etc/awstats/awstats.ghtjpx.conf
  • include: cron.yml
- name: awstats croncron: minute=10 hour=0 job='/usr/local/awstats/wwwroot/cgi-bin/awstats_updateall.pl now' user=was name=awstats disabled=no
  • include: chcon.yml
- name: because open selinux ,so need set chconshell: chdir=/root {{ item }}loop:- chcon -R -u system_u /etc/awstats- chcon -R -u system_u /usr/local/awstats- chcon -R -u system_u -t httpd_sys_content_t /usr/local/awstats/wwwroot- chcon -R -t httpd_sys_script_exec_t /usr/local/awstats/wwwroot/cgi-bin/*.pl- chcon -R -u system_u -t httpd_sys_content_t /var/lib/awstats/
  • include: service.yml
- name: restart serviceservice: name={{ item }} state=restartedloop:- ibmhttp- network

三、files文件内容

  • awstats_conf.sh
#!/bin/bashIP=`ifconfig eth0 | awk '/netmask/{print$2}'`
DOMAIN=`hostname`.bjzgh12351.orgcat >> /opt/IBM/HTTPServer/conf/httpd.conf <<EOF
NameVirtualHost $IP:80
<VirtualHost $IP:80>ServerName aw$DOMAINAlias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"Alias /awstatscss "/usr/local/awstats/wwwroot/css/"Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"Alias /js "/usr/local/awstats/wwwroot/js/"ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"<Directory "/usr/local/awstats/wwwroot">Options NoneAllowOverride NoneOrder deny,allowDeny from allAllow from all</Directory><Directory "/usr/local/awstats/wwwroot/cgi-bin">AuthName "AWStats Authorization"AuthType BasicAuthUserFile /etc/awstats/awstats.passwdrequire valid-user</Directory>
</VirtualHost>

四、关键价值

  • 开箱即用​:全流程自动化部署,无需人工干预

  • 深度集成​:无缝适配 IHS 日志体系,保留企业级特性

  • 安全可视​:通过 https://服务器IP/awstats/awstats.pl访问加密统计面板

  • 生产就绪​:内置日志切割、定时任务、SELinux 加固等运维关键能力


如果你不请什么是ansible中的角色,动动你的小手,跳转过去看看呗“roles角色”

请不要以此视为定论,这只是我的个人经验

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/93888.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/93888.shtml
英文地址,请注明出处:http://en.pswp.cn/web/93888.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

DELL服务器 R系列 IPMI的配置

1、iDRAC功能默认都是关闭&#xff0c;需要在BIOS面启用&#xff0c;首先重启计算机&#xff0c;按F2然后进入BIOS&#xff0c;选择iDRAC Setting进行iDRAC配置 2、重置一下idrac卡-重置才能恢复默认密码 3、进入iDRAC Setting之后&#xff0c;选择设置网络Network 4、启用iDRA…

模式组合应用-桥接模式(一)

写在前面Hello&#xff0c;我是易元&#xff0c;这篇文章是我学习设计模式时的笔记和心得体会。如果其中有错误&#xff0c;欢迎大家留言指正&#xff01;文章为设计模式间的组合使用&#xff0c;涉及代码较多&#xff0c;个人觉得熟能生巧&#xff0c;希望自己能从中学习到新的…

【clion】visual studio的sln转cmakelist并使用clion构建32位

我想在linux上运行,所以先转为cmake工程 例如可以把exe mfc 部分不构建,这样ubuntu就不用移植。 先转cmakelist,而后clion完成win32的构建,与vs构建对比,验证脚本正确性。 Vcxproj2CMake https://github.com/gns333/Vcxproj2CMake cmakeconverter https://github.com/pave…

MySQL之分区功能

序言 随着业务发展&#xff0c;我们维护的项目数据库中的数据可能会越来越大&#xff0c;那么单张表的数据变多后&#xff0c;接口查询效率可能会变慢&#xff0c;那我们就直接照抄大厂常见的分库分表吗&#xff1f;—— 当然不是的&#xff0c;分库分表不是万能的。 分库分表…

java_spring boot 中使用 log4j2 及 自定义layout设置示例

1. log4j2对比 原始Logback 优势 对于 Spring Boot 3.x&#xff0c;Logback 是默认日志框架&#xff0c;但在高并发、异步日志场景下&#xff0c;Log4j2 通常表现更优。当业务百万级用户、微服务、日志量大时&#xff1a; ✅ 1. Logback&#xff08;默认 Spring Boot 集成&am…

记录Webapi Excel 导出

文章目录1、helper2、control3、前端 axios记录webapi excel 导出File示例.NET8.0 NPOI2.731、helper using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System.Data; using System.IO; /// <summary> /// 导出EXCEL /// </summary> public class Exce…

VPS服务器安全审计方案:从风险评估到防护实施

随着云计算技术的快速发展&#xff0c;VPS服务器已成为企业信息化建设的重要基础设施。随之而来的安全威胁也日益增多&#xff0c;如何通过专业的安全审计方案保障VPS服务器的稳定运行成为关键课题。本文将系统阐述从漏洞扫描到应急响应的全周期安全审计实施策略&#xff0c;帮…

libmicrohttpd 入门

libmicrohttpd 是一个小型的 C 库&#xff0c;用于在项目中嵌入 HTTP 服务器功能。它设计简单、轻量级&#xff0c;适合需要 HTTP 接口但不想要大型 Web 服务器开销的应用程序。 安装 libmicrohttpd Linux 系统 在基于 Debian/Ubuntu 的系统上&#xff1a; bash sudo apt-…

【网络】使用 DNAT 进行负载均衡时,若未配置配套的 SNAT,回包失败

【网络】iptables 1 概念 【网络】iptables 2 查看规则 【网络】使用 DNAT 进行负载均衡时&#xff0c;若未配置配套的 SNAT&#xff0c;回包失败 【网络】回包路由原理 使用 DNAT 进行负载均衡时&#xff0c;若未配置配套的 SNAT&#xff0c;后端服务器将直接回包给客户端&am…

深入解析GCC:从编译原理到嵌入式底层实战

继续更新编译器底层系列&#xff01;&#xff01;&#xff01;硬核C语言的屠龙之术&#xff1a;从GCC到汇编的底层征途&#xff08;一&#xff09;总纲&#xff1a; 恭喜你&#xff0c;决定踏上这条通往嵌入式大佬的硬核之路。这条路的起点&#xff0c;不是C语言的语法书&#…

最新MySQL面试题(2025超详细版)

2025最新超详细MySQL面试题 文章目录2025最新超详细MySQL面试题[toc]一、 SQL 和基本操作1. SQL的执行顺序2. 如何优化MySQL查询3. 常用的聚合函数4. 数据库事务5. 事务的四大特性(ACID)6. 视图7. MySQL中使用LIMIT子句进行分页8. MySQL中使用变量和用户定义的函数9. MySQL中的…

Spring Retry实战指南_让你的应用更具韧性

1 Spring Retry概述 1.1 什么是Spring Retry Spring Retry是Spring生态系统中的一个重要组件,专门用于处理应用程序中的重试逻辑。在分布式系统和微服务架构中,网络通信、外部服务调用、数据库访问等操作都可能因为各种原因而失败,如网络抖动、服务暂时不可用、资源竞争等…

大数据毕业设计选题推荐-基于大数据的1688商品类目关系分析与可视化系统-Hadoop-Spark-数据可视化-BigData

✨作者主页&#xff1a;IT毕设梦工厂✨ 个人简介&#xff1a;曾从事计算机专业培训教学&#xff0c;擅长Java、Python、PHP、.NET、Node.js、GO、微信小程序、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。 ☑文末获取源码☑ 精彩专栏推荐⬇…

【Grafana】grafana-image-renderer配合python脚本实现仪表盘导出pdf

背景 os&#xff1a;centos7Grafana&#xff1a;v12grafana-image-renderer&#xff1a;v4.0.10插件&#xff1a;否grafana-image-renderer可以以插件形式启动&#xff0c;也可以以单独服务启动&#xff0c;在centos7插件启动时&#xff0c;报错glibc版本太低&#xff0c;未找到…

静/动态库 IIC(arm) day58

十七&#xff1a;动态库和静态库 库&#xff1a;一堆可执行二进制文件的集合&#xff0c;由若干个.o文件归并生成 一&#xff1a;静态(链接)库&#xff1a;libxxx.a 生成一个独立的可执行程序(运行时仅需要一个文件即可) 使用方便 不需要安装 文件比较大 多个程序使用同一个静态…

uniapp 手写签名组件开发全攻略

引言在移动应用开发中&#xff0c;手写签名功能是一个常见的需求&#xff0c;特别是在电子合同、审批流程、金融交易等场景中。本文将详细介绍如何基于uni-app框架开发一个高性能、功能丰富的手写签名组件&#xff0c;并分享开发过程中的技术要点和最佳实践。组件概述这个签名组…

理解JavaScript中的函数赋值和调用

&#x1f468; 作者简介&#xff1a;大家好&#xff0c;我是Taro&#xff0c;全栈领域创作者 ✒️ 个人主页&#xff1a;唐璜Taro &#x1f680; 支持我&#xff1a;点赞&#x1f44d;&#x1f4dd; 评论 ⭐️收藏 文章目录前言一、函数赋值二、函数调用三、 代码示例总结前言…

交叉编译 手动安装 SQLite 库 移植ARM

# 下载源码 wget https://www.sqlite.org/2023/sqlite-autoconf-3420000.tar.gz tar -xzf sqlite-autoconf-3420000.tar.gz cd sqlite-autoconf-3420000cd /home/lxh/sqlite-autoconf-3420000 make distclean //清除下&#xff0c;因为我安装失败过。 ./configure --hostarm-…

翻译记忆库(TMX)与机器翻译的结合应用

更多内容请见: 机器翻译修炼-专栏介绍和目录 文章目录 一、核心概念解析 1.1 翻译记忆库 (Translation Memory, TM) 1.2 翻译记忆交换格式 (Translation Memory eXchange, TMX) 二、为何要将两者结合? 2.1 TM和MT的优势是高度互补的 2.2 TMX在结合中的关键作用 2.3 TMX与MT的…

SpringBoot中集成eclipse.paho.client.mqttv3实现mqtt客户端并支持断线重连、线程池高并发改造、存储入库mqsql和redis示例业务流程,附资源下载

场景 SpringBoot整合MQTT服务器实现消息的发送与订阅(推送消息与接收推送)&#xff1a; SpringBoot整合MQTT服务器实现消息的发送与订阅(推送消息与接收推送)_服务端接收mqtt消息-CSDN博客 上面SpringBoot集成MQTT使用的是spring-integration-mqtt依赖&#xff0c;也是经常使…