Ansible自动化运维实战
引言Ansible是简单强大的自动化运维工具。本文介绍Ansible的使用和实战。 一、Ansible安装1234567891011# CentOSyum install ansible# Ubuntuapt install ansible# pip安装pip install ansible# 验证ansible --version 二、Inventory配置1234567891011# /etc/ansible/hosts[web]web1 ansible_host=192.168.1.10web2 ansible_host=192.168.1.11[db]db1 ansible_host=192.168.1.20[all:vars]ansible_user=rootansible_ssh_private_key_file=/root/.ssh/id_rsa 三、Ad-Hoc命令1234567891011121314# ping测试ansible all -m ping# 执行命令ansible web -m shell -a "uptime"# 复制文...
ZooKeeper分布式协调服务
引言ZooKeeper是分布式协调服务。本文介绍其核心原理和应用。 一、核心概念12345678ZNode: 数据节点- 持久节点- 临时节点- 顺序节点Watch: 监听机制Session: 会话ACL: 访问控制 二、基本操作123456789101112131415161718192021ZooKeeper zk = new ZooKeeper("localhost:2181", 5000, event -> { System.out.println("Event: " + event.getType());});// 创建节点zk.create("/mynode", "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);// 读取节点byte[] data = zk.getData("/mynode", false, null);// 更新节点z...
Linux常用命令详解
引言Linux命令是服务器运维的基础。本文介绍最常用的Linux命令。 一、文件操作12345678910111213141516171819202122232425262728293031323334353637# 列出文件lsls -l # 详细信息ls -a # 包括隐藏文件ls -lh # 人类可读的大小# 切换目录cd /path/to/dircd ~ # 回到家目录cd - # 回到上一个目录# 显示当前目录pwd# 创建目录mkdir dirmkdir -p parent/child # 创建多级目录# 删除rm filerm -r dir # 删除目录rm -rf dir # 强制删除# 复制cp source destcp -r dir1 dir2 # 复制目录# 移动/重命名mv source dest# 查看文件cat file.txthead -n 10 file.txttail -n 10 file.txttail -f log.txt # 实时查看日志less fi...
Jenkins CI/CD实践指南
引言Jenkins是最流行的CI/CD工具。本文介绍Jenkins的配置和Pipeline实践。 一、Jenkins安装12345678910111213# 安装Javayum install java-11-openjdk# 安装Jenkinswget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.reporpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.keyyum install jenkins# 启动systemctl start jenkinssystemctl enable jenkins# 访问 http://localhost:8080 二、Pipeline基础12345678910111213141516171819202122232425262728293031323334353637383940// Jenkinsfilepipeline { agen...
Kafka消息队列实战
引言Kafka是高吞吐量的分布式消息队列。本文介绍Kafka的核心概念和应用。 一、核心概念123456Producer(生产者)→ Topic(主题)→ Partition(分区)→ Consumer(消费者)Topic: 消息类别Partition: 物理分区Consumer Group: 消费者组Offset: 消息位移 二、生产者123456789101112131415161718Properties props = new Properties();props.put("bootstrap.servers", "localhost:9092");props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");props.put("value.serializer", "org.apache.kafka.common.serialization.Stri...
Git版本控制实战
引言Git是最流行的版本控制系统。本文介绍Git的核心命令和实战技巧。 一、基础命令1234567891011121314151617181920212223# 初始化仓库git init# 克隆仓库git clone https://github.com/user/repo.git# 查看状态git status# 添加文件git add file.txtgit add .# 提交git commit -m "commit message"# 查看历史git loggit log --oneline --graph# 查看差异git diffgit diff HEAD 二、分支管理12345678910111213141516171819202122# 创建分支git branch feature# 切换分支git checkout featuregit switch feature # 新命令# 创建并切换git checkout -b featuregit switch -c feature# 查看分支git branchgit branch -a ...
ELK日志分析平台搭建
引言ELK是企业级日志分析解决方案。本文介绍ELK平台的搭建和使用。 一、Elasticsearch安装123456789101112131415# 下载wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.5.0-linux-x86_64.tar.gz# 解压tar -xvf elasticsearch-8.5.0-linux-x86_64.tar.gz# 配置vim config/elasticsearch.ymlcluster.name: my-clusternode.name: node-1network.host: 0.0.0.0discovery.type: single-node# 启动./bin/elasticsearch 二、Logstash配置1234567891011121314151617181920212223242526272829303132333435# logstash.confinput { file { path =&g...
Redis分布式锁实现
引言分布式锁是分布式系统的关键组件。本文介绍Redis分布式锁的实现。 一、基础实现123456789101112131415161718192021222324252627282930public class RedisLock { private Jedis jedis; public boolean tryLock(String key, String value, int expireSeconds) { String result = jedis.set(key, value, "NX", "EX", expireSeconds); return "OK".equals(result); } public void unlock(String key, String value) { String script = "if redis.call('...
Maven项目管理实战
引言Maven是Java项目的标准构建工具。本文介绍Maven的核心功能和实战应用。 一、Maven核心概念1.1 坐标(Coordinates)12345<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.7.0</version></dependency> 1.2 pom.xml结构12345678910111213141516171819202122232425<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0<...
Prometheus监控告警实战
引言Prometheus是云原生监控的标准。本文介绍Prometheus的使用和告警配置。 一、Prometheus安装123456789# 下载wget https://github.com/prometheus/prometheus/releases/download/v2.40.0/prometheus-2.40.0.linux-amd64.tar.gz# 解压tar -xvf prometheus-2.40.0.linux-amd64.tar.gzcd prometheus-2.40.0.linux-amd64# 启动./prometheus --config.file=prometheus.yml 二、监控配置1234567891011121314151617181920# prometheus.ymlglobal: scrape_interval: 15s evaluation_interval: 15sscrape_configs: - job_name: 'prometheus' static_configs: - ta...





