Ссылки:
1 |
https://www.zabbix.com/download?zabbix=7.0&os_distribution=debian&os_version=12&components=server_frontend_agent&db=mysql&ws=apache |
install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
0. Качаем и ставим пакет: wget https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.0+debian12_all.deb dpkg -i zabbix-release_latest_7.0+debian12_all.deb apt update 1. Ставим пакеты: apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent 2. Создаем базу: mysql -uroot -p --------------- create database zabbix character set utf8mb4 collate utf8mb4_bin; create user zabbix@localhost identified by 'password'; grant all privileges on zabbix.* to zabbix@localhost; set global log_bin_trust_function_creators = 1; quit; ---------------- 3. Заливаем базу zabbix: zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix 4. Отключите опцию log_bin_trust_function_creators после импорта схемы базы данных. mysql -uroot -p --------------- set global log_bin_trust_function_creators = 0; quit; --------------- 5. Редактируем конфиг и пароль для базы: vim /etc/zabbix/zabbix_server.conf ---------------------------------- DBPassword=password ---------------------------------- 6. Запускаем zabbix systemctl restart zabbix-server zabbix-agent apache2 systemctl enable zabbix-server zabbix-agent apache2 |
Пример ansible book
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
mkdir prod cd prod cat > install_zabbix_7.yaml << "EOF" --- - name: Install Zabbix vesrion 7 on server Debian 12 hosts: all become: yes vars: mysql_root_password: "password" ansible_fqdn: zabbix destin_file_cnf: /root/.my.cnf source_file_cnf: ./my.cnf zabbix_user: "zabbix" zabbix_password: "zabbix" zabbix_db: "zabbix" zabbix_host: "localhost" zabbix_priv: "{{ zabbix_db }}.*:ALL" destin_conf: /usr/share/zabbix/conf/zabbix.conf.php source_conf: ./zabbix.conf.php tasks: - name: Update apt repo and cache on all Debian/Ubuntu boxes apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 - name: Upgrade all packages on servers apt: upgrade=dist force_apt_get=yes - name: Install a .deb package from the internet apt: deb: https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.0+debian12_all.deb - name: Run the equivalent of "apt-get update" as a separate step apt: update_cache: yes cache_valid_time: 3600 - name: Install a list of packages apt: pkg: - zabbix-server-mysql - zabbix-frontend-php - zabbix-apache-conf - zabbix-agent - mariadb-server - python3-apt - python3 - python3-pip - python3-setuptools - python3-pymysql - zabbix-agent - zabbix-sql-scripts state: latest update_cache: True - name: Copy file cnf to Servers copy: src={{ source_file_cnf }} dest={{ destin_file_cnf }} mode=0600 owner=root group=root backup=yes - name: Edit line password lineinfile: path: /root/.my.cnf state: present regexp: '^password=' line: 'password="{{ mysql_root_password }}"' - name: Remove the test database mysql_db: login_unix_socket: /var/run/mysqld/mysqld.sock name: test state: absent - name: Remove anonymous user mysql_user: login_unix_socket: /var/run/mysqld/mysqld.sock name: '' state: absent - name: Sets the root password mysql_user: login_unix_socket: /var/run/mysqld/mysqld.sock user: root password: "{{ mysql_root_password }}" host: localhost - name: "Create new databases with names {{ zabbix_user }}" mysql_db: login_unix_socket: /var/run/mysqld/mysqld.sock name: "{{ zabbix_user }}" encoding: utf8 collation: utf8_bin state: present - name: "Add user and add privilege for {{ zabbix_db }}" mysql_user: login_unix_socket: /var/run/mysqld/mysqld.sock login_host: "localhost" name: "{{ zabbix_db }}" password: "{{ zabbix_password }}" host: "localhost" priv: "{{ zabbix_priv }}" state: present append_privs: yes - name: Importing databases mysql_db: name: "{{ zabbix_db }}" login_user: "{{zabbix_user}}" login_host: localhost login_password: "{{ zabbix_password }}" config_file: no state: import encoding: utf8 collation: utf8_bin target: "/usr/share/zabbix-sql-scripts/mysql/server.sql.gz" - name: Edit line db_password for zabbix-server lineinfile: path: /etc/zabbix/zabbix_server.conf state: present regexp: '^DBPassword=' line: 'DBPassword={{ zabbix_password }}' - name: Edit line time zone lineinfile: path: /etc/zabbix/apache.conf state: present regexp: '^php_value date.timezone Europe/Riga' line: 'php_value date.timezone Europe/Moscow' - name: Copy file conf php to server zabbix copy: src={{ source_conf }} dest={{ destin_conf }} mode=0644 owner=root group=root backup=yes - name: Service zabbix restart and add autostart shell: systemctl restart zabbix-server zabbix-agent apache2 && systemctl enable zabbix-server zabbix-agent apache2 ... EOF cat > my.cnf << "EOF" [client] user="root" password=mysql_root_password EOF cat > hosts.txt << "EOF" localhost ansible_connection=local EOF cat > ansible.cfg << "EOF" [defaults] #interpreter_python = /usr/bin/python3 host_key_cheking = false allow_world_readable_tmpfiles= true #bug mysql import inventory = ./hosts.txt forks = 10 timeout = 10 log_path = ./ansible.log pipelining = True EOF cat > zabbix.conf.php << "EOF" <?php // Zabbix GUI configuration file. $DB['TYPE'] = 'MYSQL'; $DB['SERVER'] = 'localhost'; $DB['PORT'] = '0'; $DB['DATABASE'] = 'zabbix'; $DB['USER'] = 'zabbix'; $DB['PASSWORD'] = 'zabbix'; // Schema name. Used for PostgreSQL. $DB['SCHEMA'] = ''; // Used for TLS connection. $DB['ENCRYPTION'] = false; $DB['KEY_FILE'] = ''; $DB['CERT_FILE'] = ''; $DB['CA_FILE'] = ''; $DB['VERIFY_HOST'] = false; $DB['CIPHER_LIST'] = ''; // Use IEEE754 compatible value range for 64-bit Numeric (float) history values. // This option is enabled by default for new Zabbix installations. // For upgraded installations, please read database upgrade notes before enabling this option. $DB['DOUBLE_IEEE754'] = true; $ZBX_SERVER = 'localhost'; $ZBX_SERVER_PORT = '10051'; $ZBX_SERVER_NAME = 'zbx'; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG; // Uncomment this block only if you are using Elasticsearch. // Elasticsearch url (can be string if same url is used for all types). //$HISTORY['url'] = [ // 'uint' => 'http://localhost:9200', // 'text' => 'http://localhost:9200' //]; // Value types stored in Elasticsearch. //$HISTORY['types'] = ['uint', 'text']; // Used for SAML authentication. // Uncomment to override the default paths to SP private key, SP and IdP X.509 certificates, and to set extra settings. //$SSO['SP_KEY'] = 'conf/certs/sp.key'; //$SSO['SP_CERT'] = 'conf/certs/sp.crt'; //$SSO['IDP_CERT'] = 'conf/certs/idp.crt'; //$SSO['SETTINGS'] = []; EOF Объяснение плейбука: Скачивание и установка пакета Zabbix: Используется модуль apt для установки пакета. Обновление списка пакетов: Обновляет кэш пакетов. Установка необходимых пакетов Zabbix: Устанавливает все необходимые пакеты. Создание базы данных Zabbix: Использует модуль mysql_db для создания базы данных. Создание пользователя Zabbix: Использует модуль mysql_user для создания пользователя и предоставления ему прав. Установка параметра log_bin_trust_function_creators: Устанавливает переменную MySQL. Импорт схемы базы данных Zabbix: Выполняет команду для импорта схемы. Отключение опции log_bin_trust_function_creators: Устанавливает переменную обратно. Редактирование конфигурационного файла Zabbix: Использует модуль lineinfile для изменения конфигурации. Перезапуск Zabbix: Перезапускает службы Zabbix и Apache. Запуск плейбука: !!! отредактируй строку в пдлейбуке "hosts: your_target_hosts # Replace with your target host group" !!! например: hosts: all или укажи конкретный хост hosts: you_host ansible-playbook install_zabbix_7.yaml a2enmod ssl |