Ansible 자동 운영 및 유지 보수, ZABBIX 모니터링

먼저 관리 머신 준비 (Boss)

1. 환경을 설치합니다.

yum install epel-release -y
yum install ansible libselinux-python -y

2. 버전 보기

ansible --version

관리 노드(노드)가 되기 위한 준비

1. 환경 노드 노드를 준비합니다.

yum install epel-release libselinux-python -y

마스터 노드 구성 호스트:

vim /etc/ansible/hosts

 끝까지 당기다, 포맷하다

[bobo] 이러한 명명 형식은 관리하기 쉽습니다.

[bobo]
172.28.229.146
172.28.229.145

ansible과 연결을 시도하십시오.

ansible bobo -m command -a "hostname" -k -u root

암호를 입력하면 연결이 성공하고 실행이 성공합니다.

 프롬프트가 실패하면 ssh root@ip를 사용하여 다시 연결하십시오.

Ansible의 실행 템플릿:

ansible bobo -m 모듈 이름 -a "쉘 명령"

ansible chaoge -m command -a "uptime"

비밀 없는 로그인 ssh 키를 구성합니다.

1. 마스터 노드에 키 페어 생성

ssh-keygen -f ~/.ssh/id_rsa -P "" > /dev/null 2>&1

2. 공개키 파일 개인키 파일 확인

cd ~/.ssh/
 ls
authorized_keys id_rsa id_rsa.pub known_hosts

3. 마스터 노드는 공개 키 배포 스크립트를 작성합니다.

vim kry.sh
#!/bin/bash
rm -rf ~/.ssh/id_rsa*
ssh-keygen -f ~/.ssh/id_rsa -P "" > /dev/null 2>&1
SSH_Pass=111111
Key_Path=~/.ssh/id_rsa.pub
for ip in 138 139
do
 sshpass -p$SSH_Pass ssh-copy-id -i $Key_Path "-o
StrictHostKeyChecking=no" 192.168.178.$ip
done

 4. key.sh 실행

5. 가능한 하위 테스트 사용:

ansible bobo -m command -a "uname -a"

ansible-doc 명령:

1. ansible에서 지원하는 모든 모듈 나열

ansible-doc -l |grep ^command
ັ 이 모듈에서 지원하는 매개변수 보기
ansible-doc -s command

 명령 모듈은 기본 모듈입니다.

쉘 모듈

shell 모듈은 자주 사용되는 모듈입니다: pear example

 ansible bobo -m shell -a "ps -ef|grep vim|grep -v grep"

일괄적으로 스크립트 실행:

ansible chaoge -m shell -a "mkdir -p /server/myscripts/;echo
'hostname' > /server/myscripts/hostname.sh;chmod +x
/server/myscripts/hostname.sh;bash
/server/myscripts/hostname.sh warn=False"

스크립트 모듈 --- 포커스:

마스터는 모든 노드에서 실행할 수 있는 스크립트를 작성합니다. 형식은 비슷하며 스크립트는 클라이언트에 존재할 필요가 없습니다.

ansible chaoge -m script -a "/myscripts/local_hostname.sh"

복사 모듈: 슬레이브 노드에 데이터 푸시

ansible-doc -s copy  #查看参数的用法

예: 일괄 복사 파일:

ansible chaoge -m copy -a "src=/etc/hosts 
dest=/tmp/m01_hosts owner=learn_ansible group=learn_ansible
mode=0666"

복사된 정보를 확인하십시오.

 ansible chaoge -m command -a "ls -l /tmp/m01_hosts"

yum 모듈 실습:

nginx를 배치로 설치합니다.

ansible chaoge -m yum -a "name=nginx state=installed"

일괄 확인:

ansible chaoge -m shell -a "rpm -qa nginx warn=false"

일괄적으로 nginx를 제거합니다.

ansible chaoge -m yum -a "name=nginx  state=absent"

일괄 업그레이드:

ansible chaoge -m yum -a "name='nginx' state=latest"

플레이북 스크립트:

첫 번째 플레이북: yaml 형식

 호스트 호스트 부분:

 스크립트 작성 사양:

 스크립트 실행:

ansible-playbook nginx.yaml

플레이북의 자세한 출력을 봅니다.

ansible-playbook nginx.yaml --verbose

플레이북 배포 rsyns 실제 전투 주제:

 실제 작성 방법:

 플레이북을 실행합니다.

ansible-playbook install_rsync.yaml -C
ansible-playbook install_rsync.yaml

Zabbixj 모니터링:

메모리 요구 사항은 2g 이상입니다.

getenforce  #查看防火墙状态
iptables -L  #查看iptablees
free -m  #服务端内存,尽量给大点

공식 다운로드 소스 받기:

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

미러 소스 수정:

sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

zabbix 서버 및 에이전트 설치:

yum install zabbix-server-mysql zabbix-agent -y

소프트웨어 컬렉션 설치 :

yum install centos-release-scl -y

zabbix 앞 섹션의 소스를 수정합니다.

vim /etc/yum.repos.d/zabbix.repo 
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$b
asearch/frontend
enabled=1 #修改这里
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

zabbix 프런트 엔드 환경을 설치합니다.

yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

zabbix 데이터베이스를 설치합니다.

yum install mariadb-server -y

데이터베이스를 시작하고 부팅 자체 삭제를 구성합니다.

systemctl enable --now mariadb

데이터베이스 비밀번호 설정: 프롬프트를 따르십시오.

mysql_secure_installation

데이터베이스에 연결:

[root@master ~]# mysql -u root -p

데이터베이스 연결 만들기: 매우 중요

create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'chaoge666';
grant all privileges on zabbix.* to zabbix@localhost;
flush privileges;
quit;

 데이터베이스 정보 가져오기: 사용자 zabbix:

-p 다음에는 데이터베이스 이름(password chaoge666)이 옵니다.

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

로그인 시도:

[root@master ~]# mysql -uzabbix -pchaoge666
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.68-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)]> 

데이터베이스 보기:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+
2 rows in set (0.01 sec)

MariaDB [(none)]> 

zabbix 데이터베이스 사용:

MariaDB [(none)]> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> 
show tables;

구성 파일 암호를 수정합니다.

/etc/zabbix/zabbix_server.conf

찾다:

 변경되었는지 확인:

[root@zabbix-server01 data]# grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

시간대 수정:

/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

 zabbix 서비스를 시작합니다.

 자동으로 시작하도록 설정:

systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

 

추천

출처blog.csdn.net/weixin_42435798/article/details/126111663