Ansible
[Ansible] 7. Ansible Playbook을 활용한 Zabbix Agent 자동 설치
mr.november11
2018. 8. 31. 20:06
[Ansible]7. Ansible Playbook을 활용한 Zabbix Agent 자동 설치
Ansible Playbook을 활용하여 Zabbix Agent 3.4.9 버전을 자동 설치
[Ansible]7. Ansible Playbook을 활용한 Zabbix Agent 자동 설치1. 자동화 관련 Flow2. 관련 Command 및 실행 결과1) 실행 Command2) 명령어 매개변수3) 실행 결과3. 관련 파일1) zabbix-agent.yml2) hosts3) zabbix-agentd.conf.j2
1. 자동화 관련 Flow
Zabbix Agent 3.4.9 RPM을 원격지로 파일 전송
Zabbix Agent 설치
Zabbix Agent 관련 Config 파일 설정
zabbix-agentd.conf.j2 파일의 템플릿을 활용하며
기본적인 Log 옵션 및 Server/Agent 의 정보 입력을 자동화 했다.
Zabbix Agent 서비스 Start
Ansible Server 실행 디렉토리 내에 rpm 파일이 있어야 함
2. 관련 Command 및 실행 결과
1) 실행 Command
1[test@server1 ansible]$ ansible-playbook -k -i hosts zabbix-agent.yml -K -e 'zabbix_server_ipaddr=X.X.X.X target=server4 target_userid=test' --ask-become-pass
2) 명령어 매개변수
| zabbix_server_ipaddr | zabbix server 의 IP Address, 지정 시 zabbix-agentd.conf.j2 내 입력 된다. |
|---|---|
| target | 설치 대상, hosts inventory 파일 내 있는 대상이어야 한다. |
| target_userid | 원격지 접속 시 사용할 계정, su 를 통해 root 권한 획득이 가능한 계정이어야 한다. |
3) 실행 결과
1[test@server1 ansible]$ ansible-playbook -k -i hosts zabbix-agent.yml -K -e 'zabbix_server_ipaddr=X.X.X.X target=server4 target_userid=test' --ask-become-pass2SSH password:3SUDO password[defaults to SSH password]:45PLAY [Install zabbix-agent-3.4.9] *************************************************************************************67TASK [Gathering Facts] ************************************************************************************************8[WARNING]: sftp transfer mechanism failed on [server4]. Use ANSIBLE_DEBUG=1 to see detailed information910ok: [server4]1112TASK [1. Test connection] *********************************************************************************************13[WARNING]: sftp transfer mechanism failed on [server4]. Use ANSIBLE_DEBUG=1 to see detailed information1415ok: [server4]1617TASK [2. Copy Zabbix Agent rpm to Remote host] ************************************************************************18[WARNING]: sftp transfer mechanism failed on [server4]. Use ANSIBLE_DEBUG=1 to see detailed information1920changed: [server4]2122TASK [3. Install Zabbix Agent] ****************************************************************************************23[WARNING]: sftp transfer mechanism failed on [server4]. Use ANSIBLE_DEBUG=1 to see detailed information2425changed: [server4]2627TASK [4. Configure Zabbix Agent] **************************************************************************************28[WARNING]: sftp transfer mechanism failed on [server4]. Use ANSIBLE_DEBUG=1 to see detailed information2930changed: [server4]3132TASK [5. Restart Zabbix Agent] ****************************************************************************************33[WARNING]: sftp transfer mechanism failed on [server4]. Use ANSIBLE_DEBUG=1 to see detailed information3435changed: [server4]3637PLAY RECAP ************************************************************************************************************38server4 : ok=6 changed=4 unreachable=0 failed=0
3. 관련 파일
1) zabbix-agent.yml
1---2- name: Install zabbix-agent-3.4.93hosts: "{{ target }}"4remote_user: "{{ target_userid }}"5gather_facts: yes6become: yes7become_user : root8tasks:9- name: 1. Test connection10ping:1112- name: 2. Copy Zabbix Agent rpm to Remote host13copy:14src: zabbix-agent-3.4.9-1.el7.x86_64.rpm15dest: zabbix-agent-3.4.9-1.el7.x86_64.rpm16owner: "{{ target_userid }}"
17group: "{{ target_userid }}"
18mode: 064419backup: yes2021- name: 3. Install Zabbix Agent22yum:23name: zabbix-agent-3.4.9-1.el7.x86_64.rpm24state: present2526- name: 4. Configure Zabbix Agent27template:28src: zabbix-agentd.conf.j229dest: /etc/zabbix/zabbix_agentd.conf30owner: root31group: root32backup: yes3334- name: 5. Start Zabbix Agent35service:36name: zabbix-agent37state: started38enabled: yes
2) hosts
1[test]2server23server34server4
3) zabbix-agentd.conf.j2
1# This is a configuration file for Zabbix agent daemon (Unix)2# To get more information about Zabbix, visit http://www.zabbix.com34############ GENERAL PARAMETERS #################56### Option: PidFile7# Name of PID file.8#9# Mandatory: no10# Default:11# PidFile=/tmp/zabbix_agentd.pid1213PidFile=/var/run/zabbix/zabbix_agentd.pid1415### Option: LogType16# Specifies where log messages are written to:17# system - syslog18# file - file specified with LogFile parameter19# console - standard output20#21# Mandatory: no22# Default:23# LogType=file2425### Option: LogFile26# Log file name for LogType 'file' parameter.27#28# Mandatory: no29# Default:30# LogFile=3132LogFile=/var/log/zabbix/zabbix_agentd.log3334### Option: LogFileSize35# Maximum size of log file in MB.36# 0 - disable automatic log rotation.37#38# Mandatory: no39# Range: 0-102440# Default:41# LogFileSize=14243LogFileSize=1004445### Option: DebugLevel46# Specifies debug level:47# 0 - basic information about starting and stopping of Zabbix processes48# 1 - critical information49# 2 - error information50# 3 - warnings51# 4 - for debugging (produces lots of information)52# 5 - extended debugging (produces even more information)53#54# Mandatory: no55# Range: 0-556# Default:57# DebugLevel=35859### Option: SourceIP60# Source IP address for outgoing connections.61#62# Mandatory: no63# Default:64# SourceIP=6566### Option: EnableRemoteCommands67# Whether remote commands from Zabbix server are allowed.68# 0 - not allowed69# 1 - allowed70#71# Mandatory: no72# Default:73# EnableRemoteCommands=07475### Option: LogRemoteCommands76# Enable logging of executed shell commands as warnings.77# 0 - disabled78# 1 - enabled79#80# Mandatory: no81# Default:82# LogRemoteCommands=08384##### Passive checks related8586### Option: Server87# List of comma delimited IP addresses (or hostnames) of Zabbix servers.88# Incoming connections will be accepted only from the hosts listed here.89# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.90#91# Mandatory: no92# Default:93# Server=9495Server={{ zabbix_server_ipaddr }}9697### Option: ListenPort98# Agent will listen on this port for connections from the server.99#100# Mandatory: no101# Range: 1024-32767102# Default:103# ListenPort=10050104105### Option: ListenIP106# List of comma delimited IP addresses that the agent should listen on.107# First IP address is sent to Zabbix server if connecting to it to retrieve list of active checks.108#109# Mandatory: no110# Default:111# ListenIP=0.0.0.0112ListenIP={{ ansible_all_ipv4_addresses[0] }}113114### Option: StartAgents115# Number of pre-forked instances of zabbix_agentd that process passive checks.116# If set to 0, disables passive checks and the agent will not listen on any TCP port.117#118# Mandatory: no119# Range: 0-100120# Default:121# StartAgents=3122123##### Active checks related124125### Option: ServerActive126# List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.127# If port is not specified, default port is used.128# IPv6 addresses must be enclosed in square brackets if port for that host is specified.129# If port is not specified, square brackets for IPv6 addresses are optional.130# If this parameter is not specified, active checks are disabled.131# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]132#133# Mandatory: no134# Default:135# ServerActive=136137ServerActive={{ zabbix_server_ipaddr }}138139### Option: Hostname140# Unique, case sensitive hostname.141# Required for active checks and must match hostname as configured on the server.142# Value is acquired from HostnameItem if undefined.143#144# Mandatory: no145# Default:146# Hostname=147148Hostname={{ ansible_hostname }}149150### Option: HostnameItem151# Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.152# Does not support UserParameters or aliases.153#154# Mandatory: no155# Default:156# HostnameItem=system.hostname157158### Option: HostMetadata159# Optional parameter that defines host metadata.160# Host metadata is used at host auto-registration process.161# An agent will issue an error and not start if the value is over limit of 255 characters.162# If not defined, value will be acquired from HostMetadataItem.163#164# Mandatory: no165# Range: 0-255 characters166# Default:167# HostMetadata=168169### Option: HostMetadataItem170# Optional parameter that defines an item used for getting host metadata.171# Host metadata is used at host auto-registration process.172# During an auto-registration request an agent will log a warning message if173# the value returned by specified item is over limit of 255 characters.174# This option is only used when HostMetadata is not defined.175#176# Mandatory: no177# Default:178# HostMetadataItem=179180### Option: RefreshActiveChecks181# How often list of active checks is refreshed, in seconds.182#183# Mandatory: no184# Range: 60-3600185# Default:186# RefreshActiveChecks=120187RefreshActiveChecks=300188189### Option: BufferSend190# Do not keep data longer than N seconds in buffer.191#192# Mandatory: no193# Range: 1-3600194# Default:195# BufferSend=5196197### Option: BufferSize198# Maximum number of values in a memory buffer. The agent will send199# all collected data to Zabbix Server or Proxy if the buffer is full.200#201# Mandatory: no202# Range: 2-65535203# Default:204# BufferSize=100205206### Option: MaxLinesPerSecond207# Maximum number of new lines the agent will send per second to Zabbix Server208# or Proxy processing 'log' and 'logrt' active checks.209# The provided value will be overridden by the parameter 'maxlines',210# provided in 'log' or 'logrt' item keys.211#212# Mandatory: no213# Range: 1-1000214# Default:215# MaxLinesPerSecond=20216217############ ADVANCED PARAMETERS #################218219### Option: Alias220# Sets an alias for an item key. It can be used to substitute long and complex item key with a smaller and simpler one.221# Multiple Alias parameters may be present. Multiple parameters with the same Alias key are not allowed.222# Different Alias keys may reference the same item key.223# For example, to retrieve the ID of user 'zabbix':224# Alias=zabbix.userid:vfs.file.regexp[/etc/passwd,^zabbix:.:([0-9]+),,,,\1]225# Now shorthand key zabbix.userid may be used to retrieve data.226# Aliases can be used in HostMetadataItem but not in HostnameItem parameters.227#228# Mandatory: no229# Range:230# Default:231232### Option: Timeout233# Spend no more than Timeout seconds on processing234#235# Mandatory: no236# Range: 1-30237# Default:238# Timeout=3239Timeout=10240241### Option: AllowRoot242# Allow the agent to run as 'root'. If disabled and the agent is started by 'root', the agent243# will try to switch to the user specified by the User configuration option instead.244# Has no effect if started under a regular user.245# 0 - do not allow246# 1 - allow247#248# Mandatory: no249# Default:250# AllowRoot=0251252### Option: User253# Drop privileges to a specific, existing user on the system.254# Only has effect if run as 'root' and AllowRoot is disabled.255#256# Mandatory: no257# Default:258# User=zabbix259260### Option: Include261# You may include individual files or all files in a directory in the configuration file.262# Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.263#264# Mandatory: no265# Default:266# Include=267268Include=/etc/zabbix/zabbix_agentd.d/269270# Include=/usr/local/etc/zabbix_agentd.userparams.conf271# Include=/usr/local/etc/zabbix_agentd.conf.d/272# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf273274####### USER-DEFINED MONITORED PARAMETERS #######275276### Option: UnsafeUserParameters277# Allow all characters to be passed in arguments to user-defined parameters.278# The following characters are not allowed:279# \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @280# Additionally, newline characters are not allowed.281# 0 - do not allow282# 1 - allow283#284# Mandatory: no285# Range: 0-1286# Default:287# UnsafeUserParameters=0288289### Option: UserParameter290# User-defined parameter to monitor. There can be several user-defined parameters.291# Format: UserParameter=<key>,<shell command>292# See 'zabbix_agentd' directory for examples.293#294# Mandatory: no295# Default:296# UserParameter=297298####### LOADABLE MODULES #######299300### Option: LoadModulePath301# Full path to location of agent modules.302# Default depends on compilation options.303#304# Mandatory: no305# Default:306# LoadModulePath=${libdir}/modules307308### Option: LoadModule309# Module to load at agent startup. Modules are used to extend functionality of the agent.310# Format: LoadModule=<module.so>311# The modules must be located in directory specified by LoadModulePath.312# It is allowed to include multiple LoadModule parameters.313#314# Mandatory: no315# Default:316# LoadModule=317318####### TLS-RELATED PARAMETERS #######319320### Option: TLSConnect321# How the agent should connect to server or proxy. Used for active checks.322# Only one value can be specified:323# unencrypted - connect without encryption324# psk - connect using TLS and a pre-shared key325# cert - connect using TLS and a certificate326#327# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)328# Default:329# TLSConnect=unencrypted330331### Option: TLSAccept332# What incoming connections to accept.333# Multiple values can be specified, separated by comma:334# unencrypted - accept connections without encryption335# psk - accept connections secured with TLS and a pre-shared key336# cert - accept connections secured with TLS and a certificate337#338# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)339# Default:340# TLSAccept=unencrypted341342### Option: TLSCAFile343# Full pathname of a file containing the top-level CA(s) certificates for344# peer certificate verification.345#346# Mandatory: no347# Default:348# TLSCAFile=349350### Option: TLSCRLFile351# Full pathname of a file containing revoked certificates.352#353# Mandatory: no354# Default:355# TLSCRLFile=356357### Option: TLSServerCertIssuer358# Allowed server certificate issuer.359#360# Mandatory: no361# Default:362# TLSServerCertIssuer=363364### Option: TLSServerCertSubject365# Allowed server certificate subject.366#367# Mandatory: no368# Default:369# TLSServerCertSubject=370371### Option: TLSCertFile372# Full pathname of a file containing the agent certificate or certificate chain.373#374# Mandatory: no375# Default:376# TLSCertFile=377378### Option: TLSKeyFile379# Full pathname of a file containing the agent private key.380#381# Mandatory: no382# Default:383# TLSKeyFile=384385### Option: TLSPSKIdentity386# Unique, case sensitive string used to identify the pre-shared key.387#388# Mandatory: no389# Default:390# TLSPSKIdentity=391392### Option: TLSPSKFile393# Full pathname of a file containing the pre-shared key.394#395# Mandatory: no396# Default:397# TLSPSKFile=
'Ansible' 카테고리의 다른 글
| [Ansible] Ansible을 활용하여 Linux 로그 주기 설정인 logrotate 설정 변경 (0) | 2018.11.09 |
|---|---|
| [Ansible] 6 . Ansible Playbook에서 Command line을 통해 입력 받은 변수 사용 방법 (2) | 2018.08.25 |
| [Ansible] 5 . Ansible 의 멱등성 이해 및 Cron 모듈 예제 (0) | 2018.08.22 |
| [Ansible] 4 . Ansible Playbook 에서 hosts 인벤토리 파일 지정 (0) | 2018.08.22 |
| [Ansible] 3 . Ansible Playbook 에서 gather_facts 설정 해제 (0) | 2018.08.22 |
'Ansible'의 다른글
- 현재글[Ansible] 7. Ansible Playbook을 활용한 Zabbix Agent 자동 설치