├── CentOS7
├── offline.sh
├── stand-alone-agent.sh
├── percona.sh
├── compile-agent-without-admin.sh
├── centos7-mysql8-zabbix44.sh
├── zabbix-partitioning.perl
└── trap-receiver-centos-7-proxy.sh
├── .gitignore
├── .gitattributes
├── HA
├── httpd-HA.ods
├── back-end-HA.ods
├── custom-server-4.0-LTS-zabbix-server-only.sh
└── ubuntu-18.log.sh
├── MariaDB
├── mac.txt
├── image2019-9-2_17-54-52.png
├── maste-master-replication.ods
├── maste-slave-replication.ods
├── zabbix-partitioning.py
├── master2master.sh
├── master2master-node1.sh
└── master2master-node2.sh
├── bash-firewall-add-ports.sh.txt
├── externalscripts-restore-rhel.sh
├── MySQL2PostgreSQL
├── pgloader.txt
└── mariadb10317toPostgres12.txt
├── MySQL
├── event-verify.sql
├── create-seperate-user-for-zabbix-frontend.sh
├── history-table-size.sql
└── manually-create-partition.sh
├── zabbix-offline-ubuntu20-download-packages.sh
├── profile-discovery-install.sh
├── proxy-upgrade-mysql.sh
├── zabbix-offline-ubuntu20-mount-iso-and-install.sh
├── zabbix-java-gateway.sh
├── install-grafana-zabbix-3.4-centos7.sh
├── mariadb2postgres.sh
├── zabbix-db-users.sql
├── postfix-install-ubuntu
└── install.sh
├── crutial-restore-zabbix.sh
├── ubuntu
├── apache2nginx.sh
└── proxy5ubuntu20arm64.sh
├── postgres-maintain-script.sh
├── CentOS8
└── proxy.centos8.sh
├── zabbix-proxy-install-centos7.sh
├── jmx
└── setup-proxy-centos7-java-gateway.sh
├── SuSe
├── agent-install-sles-12.3.sh
└── zabbix-server-3.4.5-opensuse12.1.sh
├── certboot-install-nginx.sh
├── custom-server-install.sh
├── mysql8cluster.sh
├── zabbix-offline-ubuntu20-create-iso.sh
├── zabbix50ol8.sh
├── mysql2postgres.rh8.sh
├── Oracle-XE
├── oracle18c.sh
└── oracle-at-backend.sh
└── postgreSQL12.RH8.sh
/CentOS7/offline.sh:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.ods#
3 | *.odt#
4 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/HA/httpd-HA.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aigarskadikis/zabbix-scripts/HEAD/HA/httpd-HA.ods
--------------------------------------------------------------------------------
/HA/back-end-HA.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aigarskadikis/zabbix-scripts/HEAD/HA/back-end-HA.ods
--------------------------------------------------------------------------------
/MariaDB/mac.txt:
--------------------------------------------------------------------------------
1 | 080027C49A21 192.168.56.101
2 | 0800273FA181 192.168.56.102
3 | 08002727837E 192.168.56.103
--------------------------------------------------------------------------------
/MariaDB/image2019-9-2_17-54-52.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aigarskadikis/zabbix-scripts/HEAD/MariaDB/image2019-9-2_17-54-52.png
--------------------------------------------------------------------------------
/MariaDB/maste-master-replication.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aigarskadikis/zabbix-scripts/HEAD/MariaDB/maste-master-replication.ods
--------------------------------------------------------------------------------
/MariaDB/maste-slave-replication.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aigarskadikis/zabbix-scripts/HEAD/MariaDB/maste-slave-replication.ods
--------------------------------------------------------------------------------
/CentOS7/stand-alone-agent.sh:
--------------------------------------------------------------------------------
1 | mkdir ~/agent34
2 | cd ~/agent34
3 | wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.11-1.el7.x86_64.rpm
4 | rpm2cpio zabbix-agent-3.4.11-1.el7.x86_64.rpm | cpio -idmv
5 | cd ~/agent34/usr/sbin
6 | ./zabbix_agentd -c ~/zabbix_agentd.conf -f
7 |
8 |
--------------------------------------------------------------------------------
/bash-firewall-add-ports.sh.txt:
--------------------------------------------------------------------------------
1 | #!/bash/bin
2 | FirewallEnable()
3 | {
4 | for i oin 80/tcp 10051 162/udp
5 | do
6 | firewall-cmd --list-ports | sed 's,\s\+,\n,g' | grep -o "^${i}$" >/dev/null ||
7 | {
8 | sudo firewall-cmd --add-port=${i} --permanent
9 | sudo firewall-cmd --add-port=${i}
10 | }
11 | done
12 | }
--------------------------------------------------------------------------------
/CentOS7/percona.sh:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # install percona MySQL repo
6 | rpm -ivh https://www.percona.com/redir/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
7 |
8 | # list available packages
9 | yum list | grep percona
10 |
11 | # install percona database server
12 | yum -y install Percona-Server-server-57
13 |
14 |
--------------------------------------------------------------------------------
/externalscripts-restore-rhel.sh:
--------------------------------------------------------------------------------
1 |
2 | cd /usr/lib/zabbix/
3 |
4 | rm externalscripts -rf
5 |
6 | git clone git@github.com:catonrug/externalscripts.git
7 |
8 | chown -R zabbix:zabbix externalscripts
9 |
10 | cd externalscripts
11 |
12 | chmod 770 *
13 |
14 | #install jq support for show-isp.sh to work
15 | curl -sL https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -o /usr/bin/jq
16 | chmod +x /usr/bin/jq
17 |
18 |
--------------------------------------------------------------------------------
/MySQL2PostgreSQL/pgloader.txt:
--------------------------------------------------------------------------------
1 | LOAD DATABASE
2 | FROM mysql://zabbix:zabbix-password@localhost/zabbix
3 | INTO postgresql://zabbix:zabbix-password@localhost/zabbix
4 | WITH include no drop,
5 | truncate,
6 | create no tables,
7 | create no indexes,
8 | no foreign keys,
9 | reset sequences,
10 | data only
11 | SET maintenance_work_mem TO '1024MB', work_mem to '256MB'
12 | ALTER SCHEMA 'zabbix' RENAME TO 'public'
13 | BEFORE LOAD EXECUTE create.sql
14 | AFTER LOAD EXECUTE alter.sql;
15 |
--------------------------------------------------------------------------------
/MySQL/event-verify.sql:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SHOW PROCESSLIST;
5 |
6 |
7 | SET GLOBAL event_scheduler = ON;
8 | SELECT @@global.event_scheduler;
9 |
10 |
11 | SELECT * FROM INFORMATION_SCHEMA.events\G
12 |
13 |
14 |
15 | DELIMITER $$
16 |
17 | USE `zabbix`$$
18 |
19 | CREATE EVENT IF NOT EXISTS `e_part_manage`
20 | ON SCHEDULE EVERY 1 DAY
21 | STARTS '2018-06-11 15:06:00'
22 | ON COMPLETION PRESERVE
23 | ENABLE
24 | COMMENT 'Creating and dropping partitions'
25 | DO BEGIN
26 | CALL zabbix.drop_partitions('zabbix');
27 | CALL zabbix.create_next_partitions('zabbix');
28 | END$$
29 | DELIMITER ;
30 |
31 |
--------------------------------------------------------------------------------
/MySQL/create-seperate-user-for-zabbix-frontend.sh:
--------------------------------------------------------------------------------
1 | #this is one of best practice tip regarding to zabbix frontend setup
2 |
3 | #generate some random password
4 | pw=$(< /dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c10; echo "") && echo $pw
5 |
6 | #authorize in MySQL
7 | mysql -h localhost -uroot -p5sRj4GXspvDKsBXW -P 3306
8 |
9 | #create new user
10 | GRANT SELECT, UPDATE, DELETE, INSERT ON zabbix.* TO 'zabbix_web'@'localhost' identified by 'c$2Q!V4S%R';
11 |
12 | #show grants for this user
13 | SHOW GRANTS FOR 'zabbix_web'@'localhost';
14 |
15 | exit
16 |
17 | vi /etc/zabbix/web/zabbix.conf.php
18 |
19 | #modify /etc/zabbix/web/zabbix.conf.php to look like
20 | #$DB['DATABASE'] = 'zabbix';
21 | #$DB['USER'] = 'zabbix_web';
22 | #$DB['PASSWORD'] = 'c$2Q!V4S%R';
23 |
24 | #restart web server
25 | systemctl restart httpd
26 |
27 |
--------------------------------------------------------------------------------
/zabbix-offline-ubuntu20-download-packages.sh:
--------------------------------------------------------------------------------
1 | # Download Zabbix repo
2 | wget https://repo.zabbix.com/zabbix/5.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.4-1+ubuntu20.04_all.deb
3 |
4 | # Install Zabbix repo
5 | sudo dpkg -i zabbix-release_5.4-1+ubuntu20.04_all.deb
6 |
7 | # Update package list
8 | sudo apt update
9 |
10 | # Clear local apt cache
11 | sudo rm -rf /var/cache/apt/archives/*
12 |
13 | # Download all Zabbix packages with all dependencies
14 | sudo apt-get install --download-only zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent mysql-server
15 |
16 | # Create folder for .deb
17 | mkdir ./zabbix
18 |
19 | # Copy all Zabbix .deb
20 | sudo cp -r /var/cache/apt/archives/* ./zabbix/
21 |
22 | # Copy this folder to your isolated server and install Zabbix from local .deb
23 | sudo dpkg -i ./zabbix/*.deb
24 |
--------------------------------------------------------------------------------
/profile-discovery-install.sh:
--------------------------------------------------------------------------------
1 | #create few profiles
2 | mkdir -p /opt/{profile1,profile23,profile5}
3 |
4 | #create some log files
5 | touch /opt/{profile1,profile23,profile5}/SystemOut.log
6 |
7 | #move to agent custom conf direcotry
8 | cd /etc/zabbix/zabbix_agentd.d
9 |
10 | #list profile.discovery UserParameter
11 | echo "VXNlclBhcmFtZXRlcj1kaXNjb3Zlci5wcm9maWxlcyxscyAtMSAtZCAvb3B0LyogfCBzZWQgInMvXi97XCJ7I1BST0ZJTEV9XCI6XCIvO3MvJC9cIn0sLyIgfCB0ciAtY2QgIls6cHJpbnQ6XSIgfCBzZWQgInMvXi97XCJkYXRhXCI6Wy87cy8sJC9dfS8iCg==" | base64 --decode
12 |
13 | #install parameter:
14 | echo "VXNlclBhcmFtZXRlcj1kaXNjb3Zlci5wcm9maWxlcyxscyAtMSAtZCAvb3B0LyogfCBzZWQgInMvXi97XCJ7I1BST0ZJTEV9XCI6XCIvO3MvJC9cIn0sLyIgfCB0ciAtY2QgIls6cHJpbnQ6XSIgfCBzZWQgInMvXi97XCJkYXRhXCI6Wy87cy8sJC9dfS8iCg==" | base64 --decode > profile_discovery.conf
15 |
16 | #check if it has installed
17 | cat profile_discovery.conf
18 |
19 | grep "^Include" /etc/zabbix/zabbix_agentd.conf
20 |
21 |
22 |
--------------------------------------------------------------------------------
/proxy-upgrade-mysql.sh:
--------------------------------------------------------------------------------
1 |
2 | # yum install -y zabbix-proxy-mysql zabbix-agent
3 | # rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
4 |
5 | systemctl stop zabbix-proxy zabbix-agent
6 | yum -y remove zabbix-release
7 | yum clean all
8 | rm -rf /var/cache/yum
9 | rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-2.el7.noarch.rpm
10 | yum makecache fast
11 | yum -y update zabbix-*
12 | mysql <<< 'drop database zabbix_proxy;'
13 | mysql <<< 'create database zabbix_proxy character set utf8 collate utf8_bin;'
14 | mysql <<< 'grant all privileges on zabbix_proxy.* to zabbix@localhost identified by "zabbix";'
15 | zcat /usr/share/doc/zabbix-proxy-mysql-4.2*/schema.sql.gz | mysql -u'zabbix' -p'zabbix' zabbix_proxy
16 | systemctl start zabbix-proxy zabbix-agent
17 | systemctl enable zabbix-proxy zabbix-agent
18 | grep " Zabbix Proxy " /var/log/zabbix/zabbix_proxy.log
19 | cat /var/log/zabbix/zabbix_proxy.log
20 |
21 |
22 |
--------------------------------------------------------------------------------
/zabbix-offline-ubuntu20-mount-iso-and-install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # use WinSCP to upload '/tmp/zabbix-offline-install-ubuntu20.iso'
4 |
5 | # create a directory where to mount ISO
6 | mkdir /mnt/apt
7 |
8 | # mount ISO
9 | mount /tmp/zabbix-offline-install-ubuntu20.iso /mnt/apt
10 |
11 | # create a backup of original repos
12 | cp /etc/apt/sources.list /etc/apt/sources.list.original
13 |
14 | # enable only offline
15 | echo "deb [trusted=yes] file:/mnt/apt ./" | sudo tee /etc/apt/sources.list
16 |
17 | # refresh apt
18 | apt update
19 | # now apt relies only what is in the ISO
20 |
21 | # install MySQL server
22 | apt install mysql-server
23 |
24 | # follow official instruction to setup Zabbix with MySQL and NGINX on Ubuntu 20
25 | # https://www.zabbix.com/download?zabbix=5.0&os_distribution=ubuntu&os_version=20.04_focal&db=mysql&ws=nginx
26 |
27 | # bring back default repo
28 | cat /etc/apt/sources.list.original > /etc/apt/sources.list
29 |
30 | # umount ISO
31 | umount /mnt/apt
32 |
--------------------------------------------------------------------------------
/zabbix-java-gateway.sh:
--------------------------------------------------------------------------------
1 | yum install zabbix-java-gateway -yum install tomcat -y
2 |
3 | vi /etc/zabbix/zabbix_java_gateway_logback.xml
4 |
5 |
6 |
7 |
8 |
9 |
10 | #define
11 | JavaGateway=127.0.0.1
12 | JavaGatewayPort=10052
13 | StartJavaPollers=5
14 |
15 |
16 | vi /etc/zabbix/zabbix_java_gateway.conf
17 |
18 | START_POLLERS=5
19 |
20 | find / -name server
21 |
22 | vim /usr/libexec/tomcat/server
23 | add
24 | -Dcom.sun.management.jmxremote \
25 | -Dcom.sun.management.jmxremote.port=12345 \
26 | -Dcom.sun.management.jmxremote.rmi.port=12345 \
27 | -Dcom.sun.management.jmxremote.ssl=false \
28 | -Dcom.sun.management.jmxremote.authenticate=false
29 |
30 | systemctl start tomcat
31 |
32 | yum install wget -yum
33 |
34 |
35 | wget https://github.com/jiaqi/jmxterm/releases/download/v1.0.0/jmxterm-1.0.0-uber.jar
36 |
37 |
38 | java -jar jmxterm-1.0.0-uber.jar
39 | open 127.0.0.1:12345
40 |
41 | beans
42 |
43 | #list the beens
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/CentOS7/compile-agent-without-admin.sh:
--------------------------------------------------------------------------------
1 | yum -y install wget gcc
2 |
3 | cd
4 |
5 | dir=~/custom
6 | mkdir -p $dir
7 | cd $dir
8 | wget https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz
9 | tar -vzxf pcre-8.38.tar.gz
10 | export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/sfw/bin:/usr/ccs/bin"
11 | cd $dir/pcre-8.38
12 | ./configure --help
13 | ./configure --prefix=$dir/env --disable-cpp --disable-shared --enable-utf8 --enable-unicode-properties
14 | time make install
15 |
16 | tree $dir/env
17 |
18 |
19 |
20 |
21 | cd $dir
22 | wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz
23 | tar -vzxf openssl-1.0.2o.tar.gz
24 | export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/sfw/bin:/usr/ccs/bin"
25 | cd $dir/openssl-1.0.2o
26 | ./Configure --help
27 | ./Configure no-shared no-threads --prefix=$dir/env dist
28 |
29 | time make install
30 |
31 | tree $dir/env
32 |
33 | cd $dir
34 | wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.11/zabbix-3.4.11.tar.gz
35 | tar -vzxf zabbix-3.4.11.tar.gz
36 | cd $dir/zabbix-3.4.11
37 | dest=~/agent
38 | mkdir -p $dest
39 | ./configure --enable-agent --prefix=$dest -with-openssl=$dir/env -with-libpcre=$dir/env
40 | time make install
41 |
42 | cd ~/agent
43 |
44 |
45 |
--------------------------------------------------------------------------------
/MySQL/history-table-size.sql:
--------------------------------------------------------------------------------
1 | SELECT PARTITION_NAME,PARTITION_ORDINAL_POSITION, TABLE_ROWS, PARTITION_METHOD,round((DATA_LENGTH + index_length) / 1024 / 1024) "DB Size in MB" FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = 'zabbix' AND TABLE_NAME = 'history';
2 |
3 | SELECT PARTITION_NAME,PARTITION_ORDINAL_POSITION, TABLE_ROWS, PARTITION_METHOD,round((DATA_LENGTH + index_length) / 1024 / 1024) "DB Size in MB" FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = 'zabbix' AND TABLE_NAME = 'history_uint';
4 |
5 | SELECT PARTITION_NAME,PARTITION_ORDINAL_POSITION, TABLE_ROWS, PARTITION_METHOD,round((DATA_LENGTH + index_length) / 1024 / 1024) "DB Size in MB" FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = 'zabbix' AND TABLE_NAME = 'history_text';
6 |
7 | SELECT PARTITION_NAME,PARTITION_ORDINAL_POSITION, TABLE_ROWS, PARTITION_METHOD,round((DATA_LENGTH + index_length) / 1024 / 1024) "DB Size in MB" FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = 'zabbix' AND TABLE_NAME = 'history_str';
8 |
9 | SELECT PARTITION_NAME,PARTITION_ORDINAL_POSITION, TABLE_ROWS, PARTITION_METHOD,round((DATA_LENGTH + index_length) / 1024 / 1024) "DB Size in MB" FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = 'zabbix' AND TABLE_NAME = 'history_log';
10 |
11 |
--------------------------------------------------------------------------------
/install-grafana-zabbix-3.4-centos7.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-grafana-to-plot-beautiful-graphs-from-zabbix-on-centos-7
3 |
4 | #install grafana repo
5 | echo "W2dyYWZhbmFdCm5hbWU9Z3JhZmFuYQpiYXNldXJsPWh0dHBzOi8vcGFja2FnZWNsb3VkLmlvL2dyYWZhbmEvc3RhYmxlL2VsLzYvJGJhc2VhcmNoCnJlcG9fZ3BnY2hlY2s9MQplbmFibGVkPTEKZ3BnY2hlY2s9MQpncGdrZXk9aHR0cHM6Ly9wYWNrYWdlY2xvdWQuaW8vZ3BnLmtleSBodHRwczovL2dyYWZhbmFyZWwuczMuYW1hem9uYXdzLmNvbS9SUE0tR1BHLUtFWS1ncmFmYW5hCnNzbHZlcmlmeT0xCnNzbGNhY2VydD0vZXRjL3BraS90bHMvY2VydHMvY2EtYnVuZGxlLmNydAoK" | base64 --decode > /etc/yum.repos.d/grafana.repo
6 | cat /etc/yum.repos.d/grafana.repo
7 |
8 | #install GPG key
9 | cd /etc/pki/rpm-gpg
10 | curl -s -O https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana
11 | rpm --import RPM-GPG-KEY-grafana
12 |
13 | yum install grafana -y
14 | systemctl daemon-reload
15 | systemctl start grafana-server
16 | systemctl enable grafana-server
17 | grafana-cli plugins install alexanderzobnin-zabbix-app
18 |
19 | systemctl restart grafana-server
20 |
21 | #make sure the port 3000 is listening
22 | netstat -tulpn
23 |
24 | firewall-cmd --add-port=3000/tcp --permanent
25 | firewall-cmd --reload
26 |
27 | #http://localhost/zabbix/api_jsonrpc.php
28 |
--------------------------------------------------------------------------------
/mariadb2postgres.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # mariadbversion 10.3.17
4 | SELECT();
5 |
6 | # SELECT POSTGRES version
7 | SELECT();
8 |
9 |
10 | # database size, biggest tables
11 | SELECT table_name,
12 | table_rows,
13 | data_length,
14 | index_length,
15 | round(((data_length + index_length) / 1024 / 1024 / 1024),2) "Size in GB"
16 | FROM information_schema.tables
17 | WHERE table_schema = "zabbix"
18 | ORDER BY round(((data_length + index_length) / 1024 / 1024 / 1024),2) DESC
19 | LIMIT 20;
20 |
21 |
22 | # create stock database with different DB name in same MariaDB engine (simulate test much faster)
23 |
24 | # authorize in postgresSQL server
25 |
26 | # make sure MariaDB server is reachable over 3306
27 |
28 | # create pgloader profile
29 |
30 | # install utility 'screen'
31 |
32 | # determine no tables too much
33 |
34 |
35 |
36 | # yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
37 | # yum install postgresql12-server
38 | # /usr/pgsql-12/bin/postgresql-12-setup initdb
39 | # systemctl enable postgresql-12
40 | # systemctl start postgresql-12
41 |
42 |
43 | # yum install pgloader
44 |
45 | # pgloader -V
46 | # pgloader version "3.6.2"
47 |
48 |
49 | # replace binaries
50 |
51 |
52 |
--------------------------------------------------------------------------------
/MariaDB/zabbix-partitioning.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import psycopg2
4 | from optparse import OptionParser
5 |
6 | tables = {
7 | 'history':'daily',
8 | 'history_sync':'daily',
9 | 'history_uint':'daily',
10 | 'history_uint_sync':'daily',
11 | 'history_str':'daily',
12 | 'history_str_sync':'daily',
13 | 'history_log':'daily',
14 | 'history_text':'daily',
15 | 'trends':'monthly',
16 | 'trends_uint':'monthly',
17 | 'acknowledges':'monthly',
18 | 'alerts':'monthly',
19 | 'auditlog':'monthly',
20 | 'events':'monthly',
21 | 'service_alarms':'monthly',
22 | }
23 |
24 | #change these settings
25 | db_user = 'zabbix'
26 | db_pw = 'zabbix'
27 | db = 'zabbix'
28 | db_host = 'localhost'
29 | #####
30 |
31 | parser = OptionParser()
32 | parser.add_option("-i", "--init", dest="init",help="partitioning init",action="store_true", default=False)
33 |
34 | (options, args) = parser.parse_args()
35 |
36 | if options.init:
37 | init = 1
38 | else:
39 | init = 0
40 |
41 | db_connection = psycopg2.connect(database=db, user=db_user, password=db_pw,host=db_host)
42 | db_cursor = db_connection.cursor()
43 |
44 | for table_key, table_value in tables.iteritems():
45 |
46 | db_cursor.execute('''select create_zbx_partitions(%s,%s,%s)''',[table_key,table_value,init])
47 |
48 | db_connection.commit()
49 | db_cursor.close()
50 | db_connection.close()
51 |
--------------------------------------------------------------------------------
/zabbix-db-users.sql:
--------------------------------------------------------------------------------
1 |
2 | --for MySQL 8
3 | --generate rendom password from bash
4 | -- < /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-20};echo;
5 |
6 | CREATE USER
7 | 'zbx_srv'@'192.168.88.101' IDENTIFIED WITH mysql_native_password BY 'pass_zbx_srv',
8 | 'zbx_srv'@'192.168.88.102' IDENTIFIED WITH mysql_native_password BY 'pass_zbx_srv',
9 | 'zbx_web'@'192.168.88.103' IDENTIFIED WITH mysql_native_password BY 'pass_zbx_web',
10 | 'zbx_web'@'192.168.88.104' IDENTIFIED WITH mysql_native_password BY 'pass_zbx_web',
11 | 'zbx_part'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'pass_zbx_part',
12 | 'zbx_monitor'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'pass_zbx_monitor';
13 |
14 | CREATE ROLE 'zbx_srv_role', 'zbx_web_role';
15 |
16 | GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, ALTER, INDEX, REFERENCES ON zabbix.* TO 'zbx_srv_role';
17 |
18 | GRANT SELECT, UPDATE, DELETE, INSERT ON zabbix.* TO 'zbx_web_role';
19 |
20 | GRANT ALL PRIVILEGES ON *.* to 'zbx_part'@'127.0.0.1';
21 |
22 | GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'127.0.0.1';
23 |
24 |
25 | GRANT 'zbx_srv_role' TO 'zbx_srv'@'192.168.88.101';
26 | GRANT 'zbx_srv_role' TO 'zbx_srv'@'192.168.88.102';
27 | GRANT 'zbx_web_role' TO 'zbx_web'@'192.168.88.103';
28 | GRANT 'zbx_web_role' TO 'zbx_web'@'192.168.88.104';
29 |
30 | SET DEFAULT ROLE 'zbx_srv_role' TO 'zbx_srv'@'192.168.88.101';
31 | SET DEFAULT ROLE 'zbx_srv_role' TO 'zbx_srv'@'192.168.88.102';
32 | SET DEFAULT ROLE 'zbx_web_role' TO 'zbx_web'@'192.168.88.103';
33 | SET DEFAULT ROLE 'zbx_web_role' TO 'zbx_web'@'192.168.88.104';
34 |
35 |
36 |
--------------------------------------------------------------------------------
/postfix-install-ubuntu/install.sh:
--------------------------------------------------------------------------------
1 |
2 | # allow apt-get to be used
3 | rm /var/lib/apt/lists/lock
4 |
5 | # update repos
6 | apt-get -y update
7 |
8 | # install postfix mail server
9 | apt-get -y install logcheck
10 |
11 | # if i got to error:
12 | # E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
13 | # E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
14 | # then wait a minure and try again
15 |
16 | find / -name externalscripts
17 |
18 | # move to external scripts dir
19 | cd /usr/lib/zabbix/externalscripts
20 |
21 | # download file:
22 | wget https://raw.githubusercontent.com/oscm/zabbix/master/postfix/postfix
23 |
24 | # ubuntu keeps the log in a bit different format
25 | sed -i "s/maillog/mail.log/g" postfix
26 |
27 | # set file executable
28 | chmod +x postfix
29 |
30 | # set the right owner
31 | chown zabbix. postfix
32 |
33 | # check if something works
34 | ./postfix discovery
35 |
36 | # move to agent userparameter dir
37 | cd /etc/zabbix/zabbix_agentd.d
38 |
39 | # download userparameter instructions
40 | wget https://raw.githubusercontent.com/oscm/zabbix/master/postfix/userparameter_postfix.conf
41 |
42 | # set postfix location to /usr/lib/zabbix/externalscripts
43 | sed -i "s/\/srv\/zabbix\/libexec/\/usr\/lib\/zabbix\/externalscripts/g" userparameter_postfix.conf
44 |
45 | # make sure the log is there
46 | ls -l /var/log/mail.log
47 | # if the log is not there then stop processing further steps
48 |
49 | # allow 'zabbix' user to read the log
50 | usermod -a -G adm zabbix
51 |
52 | # restart agent
53 | systemctl restart zabbix-agent
--------------------------------------------------------------------------------
/crutial-restore-zabbix.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #push fresh lite image to micro sd card
4 |
5 | #ssh must be enabled. this can be done by creating ssh file (without content) on boot partition
6 |
7 | #all crucial files must be stored in boot partition in directory 'backup'
8 |
9 | #after first boot please move to the root user and update system
10 | #sudo su
11 | apt-get update -y
12 | apt-get dist-upgrade -y
13 | apt-get update -y
14 | apt-get install git -y
15 | apt-get install tree -y
16 | apt-get install vim -y
17 |
18 | cd /home/pi/backup
19 | cp -R * /
20 | #set permissions
21 |
22 | #install git keys
23 | #allow only owner read and write to these keys
24 | chmod 600 ~/.ssh/id_rsa #git private key
25 | chmod 600 ~/.ssh/id_rsa.pub #git public key
26 | chmod 644 ~/.gitconfig #email and username for git
27 |
28 | chown -R zabbix:zabbix /home/zabbix
29 | chown -R zabbix:zabbix /usr/local/share/zabbix
30 | chmod 770 /usr/local/share/zabbix/externalscripts/*
31 | chmod 600 /home/zabbix/.my.cnf
32 |
33 | #install certboot agentls
34 | curl -s https://dl.eff.org/certbot-auto > /usr/bin/certbot
35 | chmod 770 /usr/bin/certbot
36 | #integrate some certbot settings
37 | mkdir -p /etc/letsencrypt
38 | echo renew-hook = systemctl reload nginx> /etc/letsencrypt/cli.ini
39 |
40 | mkdir ~/git
41 | cd ~/git
42 | git clone ssh://git@github.com/catonrug/zabbix-mariadb-nginx-raspbian-stretch.git
43 |
44 | #remove symlink - default nginx sites
45 | unlink /etc/nginx/sites-enabled/default
46 | ln -s /etc/nginx/sites-available/5d61050b753b.sn.mynetname.net /etc/nginx/sites-enabled/5d61050b753b.sn.mynetname.net
47 |
48 | #disable wifi module
49 | #dtoverlay=pi3-disable-wifi
50 |
51 | #backup database
52 | #sudo mysqldump zabbix | bzip2 -9 > dbdump.bz2
53 | #bzcat dbdump.bz2 | sudo mysql zabbix
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/ubuntu/apache2nginx.sh:
--------------------------------------------------------------------------------
1 | systemctl status apache2
2 | systemctl stop apache2
3 | systemctl status apache2
4 |
5 | # remove apache2
6 | apt -y remove apache2
7 |
8 | # if previous command did not succeed. see what is using it
9 | ps aux | grep -i [a]pt
10 |
11 | # reload repo content
12 | apt -y update
13 |
14 | # install nginx
15 | apt -y install nginx php-fpm
16 |
17 | # move to home
18 | cd
19 |
20 | # download repo
21 | wget http://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-1%2Bxenial_all.deb
22 |
23 | # install
24 | dpkg -i zabbix-release_4.0-1+xenial_all.deb
25 |
26 | # search if there is some zabbix packages available
27 | apt search zabbix
28 |
29 | apt -y install zabbix-frontend-php
30 |
31 | # see where the fpm.sock is located and what is exact path
32 | find / -name *fpm.sock
33 |
34 |
35 | cd /etc/nginx/sites-available
36 |
37 | # install zabbix web server directive
38 | cat << 'EOF' > zabbix.conf
39 | server {
40 | listen 80;
41 | root /usr/share/zabbix;
42 | access_log /var/log/nginx/zabbix-access.log;
43 | error_log /var/log/nginx/zabbix-error.log;
44 | index index.php index.html index.htm;
45 | location ~ [^/]\.php(/|$) {
46 | fastcgi_split_path_info ^(.+\.php)(/.+)$;
47 | fastcgi_pass unix:/run/php/php7.0-fpm.sock;
48 | fastcgi_index index.php;
49 | include fastcgi.conf;
50 | fastcgi_param PHP_VALUE "
51 | max_execution_time = 300
52 | memory_limit = 128M
53 | post_max_size = 16M
54 | upload_max_filesize = 2M
55 | max_input_time = 300
56 | date.timezone = EST
57 | always_populate_raw_post_data = -1
58 | ";
59 | }
60 | }
61 | EOF
62 | cat zabbix.conf
63 |
64 | # remove default page
65 | rm -rf /etc/nginx/sites-enabled/default
66 |
67 | # create zabbix site as an only resource available
68 | ln -s /etc/nginx/sites-available/zabbix.conf /etc/nginx/sites-enabled/zabbix.conf
69 |
70 | systemctl restart nginx php7.0-fpm
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/MySQL2PostgreSQL/mariadb10317toPostgres12.txt:
--------------------------------------------------------------------------------
1 | mkdir -p ~/mariadb/10.3.17/conf.d
2 | docker run --name mariadb10317 \
3 | -v /home/rancher/mariadb/10.3.17/conf.d:/etc/mysql/conf.d \
4 | -e MYSQL_ROOT_PASSWORD="zabbix" \
5 | -p 10317:3306 \
6 | -d mariadb:10.3.17
7 |
8 |
9 | dnf remove pgdg-redhat-repo
10 |
11 | # https://support.zabbix.com/browse/PSALE-631
12 | # https://www.postgresql.org/download/linux/redhat/
13 | # https://pgloader.readthedocs.io/en/latest/
14 | # https://centos.pkgs.org/8/raven-x86_64/pgloader-3.6.2-1.el8.x86_64.rpm.html
15 | # https://docs.timescale.com/latest/getting-started/installation/rhel-centos/installation-yum
16 |
17 |
18 | 1) kickstart centos8
19 | # Install the repository RPM:
20 | dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
21 |
22 | # Disable the built-in PostgreSQL module:
23 | dnf -qy module disable postgresql
24 |
25 | # Install PostgreSQL:
26 | dnf install -y postgresql12-server
27 |
28 | # Optionally initialize the database and enable automatic start:
29 | /usr/pgsql-12/bin/postgresql-12-setup initdb
30 | systemctl enable postgresql-12
31 | systemctl start postgresql-12
32 |
33 |
34 | # dependencies for pgloader
35 | dnf -y install openssl-devel
36 |
37 | # third party package
38 | rpm -ivh https://pkgs.dyn.su/el8/base/x86_64/pgloader-3.6.2-1.el8.x86_64.rpm
39 |
40 |
41 |
42 | # download 4.4 source
43 | cd
44 | curl -s https://cdn.zabbix.com/zabbix/sources/oldstable/4.4/zabbix-4.4.10.tar.gz -o zabbix-source.tar.gz
45 | ls -lh zabbix-source.tar.gz
46 | mkdir ~/zabbix-source
47 | gunzip zabbix-source.tar.gz && tar xvf zabbix-source.tar -C ~/zabbix-source
48 |
49 |
50 |
51 |
52 |
53 | LOAD DATABASE
54 | FROM mysql://zabbix:zabbix-password@localhost/zabbix
55 | INTO postgresql://zabbix:zabbix-password@localhost/zabbix
56 | WITH include no drop,
57 | truncate,
58 | create no tables,
59 | create no indexes,
60 | no foreign keys,
61 | reset sequences,
62 | data only
63 | SET maintenance_work_mem TO '1024MB', work_mem to '256MB'
64 | ALTER SCHEMA 'zabbix' RENAME TO 'public'
65 | BEFORE LOAD EXECUTE create.sql
66 | AFTER LOAD EXECUTE alter.sql;
67 |
68 |
--------------------------------------------------------------------------------
/postgres-maintain-script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [[ "$1" == "--help" || "$1" == "-h" || -z "$1" ]]; then
4 | clear
5 | cat < /dev/null
72 | if [ $? -eq 0 ]; then
73 | UNIXTIME_OF_PARTITION=$(date --date="$YEAR-$MONTH-01 00:00:00" +"%s")
74 | else
75 | UNIXTIME_OF_PARTITION=$(date --date="$YEAR-$MONTH-$DAY 00:00:00" +"%s")
76 | fi
77 |
78 |
79 | if [ $UNIXTIME_OF_PARTITION -lt $THRESHOLD ]; then
80 | echo "partition $NAME_OF_PARTITION will be deleted"
81 |
82 | # check if delete=yes
83 | if [ "$DELETE_NOW" = "yes" ]; then
84 | echo executing command
85 |
86 | echo psql --username=postgres --dbname=zabbix --command="DROP TABLE IF EXISTS partitions.$NAME_OF_PARTITION"
87 | psql --username=postgres --dbname=zabbix --command="DROP TABLE IF EXISTS partitions.$NAME_OF_PARTITION"
88 |
89 | fi
90 |
91 | fi
92 |
93 | } done
94 |
95 |
--------------------------------------------------------------------------------
/CentOS8/proxy.centos8.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #======================================================================================
4 | # Package Arch Version Repository Size
5 | #======================================================================================
6 | #Installing:
7 | # zabbix-proxy-sqlite3 x86_64 5.0.6-1.el8 zabbix 1.0 M
8 | #Installing dependencies:
9 | # OpenIPMI-libs x86_64 2.0.27-1.el8 baseos 507 k
10 | # fping x86_64 3.16-1.el8 zabbix-non-supported 51 k
11 | # libtool-ltdl x86_64 2.4.6-25.el8 baseos 58 k
12 | # net-snmp-libs x86_64 1:5.8-17.el8 baseos 823 k
13 | # unixODBC x86_64 2.3.7-1.el8 appstream 458 k
14 |
15 | # zabbix-agent x86_64 5.0.6-1.el8 zabbix 464 k
16 |
17 | # Installing:
18 | # vim-enhanced x86_64 2:8.0.1763-15.el8 appstream 1.4 M
19 | #Installing dependencies:
20 | # gpm-libs x86_64 1.20.7-15.el8 appstream 39 k
21 | # vim-common x86_64 2:8.0.1763-15.el8 appstream 6.3 M
22 | # vim-filesystem noarch 2:8.0.1763-15.el8 appstream 48 k
23 |
24 |
25 |
26 |
27 |
28 | echo 1 | sudo tee /proc/sys/vm/overcommit_memory
29 | sudo dd if=/dev/zero of=/myswap1 bs=1M count=1024 && sudo chown root:root /myswap1 && sudo chmod 0600 /myswap1 && sudo mkswap /myswap1 && sudo swapon /myswap1 && free -m
30 | sudo dd if=/dev/zero of=/myswap2 bs=1M count=1024 && sudo chown root:root /myswap2 && sudo chmod 0600 /myswap2 && sudo mkswap /myswap2 && sudo swapon /myswap2 && free -m
31 |
32 | # install zabbix repo
33 | rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
34 |
35 | # clean package manager cache
36 | dnf clean all
37 |
38 | # install proxy with sqlite3 db at backend
39 | dnf -y install zabbix-proxy-sqlite3
40 | # install agent
41 | dnf -y install zabbix-agent
42 | dnf -y install vim
43 |
44 | # check home for zabbix
45 | grep zabbix /etc/passwd
46 | mkdir -p /var/lib/zabbix && chown -R zabbix. /var/lib/zabbix
47 |
48 |
49 | vim /etc/zabbix/zabbix_proxy.conf
50 | # delete 'Hostname=Zabbix proxy'
51 | # install 'HostnameItem=system.run[hostname --short]'
52 | # install database location to 'DBName=/var/lib/zabbix/zabbix_proxy'
53 |
54 |
55 | vim /etc/zabbix/zabbix_proxy.conf
56 | # delete 'Hostname=Zabbix server'
57 | # install 'HostnameItem=system.run[hostname --short]'
58 | # install 'HostMetadataItem=system.sw.os'
59 |
60 |
61 | systemctl status zabbix-proxy
62 | systemctl status zabbix-agent
63 |
64 | systemctl start zabbix-proxy zabbix-agent
65 |
66 | systemctl enable zabbix-proxy zabbix-agent
67 |
68 |
69 |
--------------------------------------------------------------------------------
/MariaDB/master2master.sh:
--------------------------------------------------------------------------------
1 |
2 | # move to super user
3 |
4 |
5 | # update system
6 | yum -y update && yum -y upgrade
7 |
8 | # setup some conveniences
9 | yum -y install vim
10 |
11 | # add mariadb repo
12 | https://downloads.mariadb.org/mariadb/repositories/#mirror=netinch&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.2
13 |
14 | vim /etc/yum.repos.d/MariaDB.repo
15 | # paste:
16 | # MariaDB 10.2 CentOS repository list - created 2018-08-13 06:39 UTC
17 | # http://downloads.mariadb.org/mariadb/repositories/
18 | [mariadb]
19 | name = MariaDB
20 | baseurl = http://yum.mariadb.org/10.2/centos7-amd64
21 | gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
22 | gpgcheck=1
23 |
24 | # generate cache
25 | yum makecache
26 |
27 | # install mariadb server
28 | yum install MariaDB-server MariaDB-client
29 |
30 | # During installation process MariaDB package will configure initial database and create redo log files with default file size. Remove these files:
31 | rm -rf /var/lib/mysql/ib_logfile* # if change innodb_log_file_size= 32gb
32 |
33 | cat /etc/my.cnf.d/server.cnf
34 | #
35 | # These groups are read by MariaDB server.
36 | # Use it for options that only the server (but not clients) should see
37 | #
38 | # See the examples of server my.cnf files in /usr/share/mysql/
39 | #
40 |
41 | # this is read by the standalone daemon and embedded servers
42 | [server]
43 |
44 | # this is only for the mysqld standalone daemon
45 | [mysqld]
46 | user = mysql
47 | local_infile = 0
48 | symbolic_links = 0
49 |
50 | default-storage-engine = InnoDB
51 | skip-name-resolve
52 | key_buffer_size = 32M
53 | max_allowed_packet = 128M
54 | table_open_cache = 1024
55 | table_definition_cache = 1024
56 | max_connections = 2000
57 | join_buffer_size = 1M
58 | sort_buffer_size = 2M
59 | read_buffer_size = 256K
60 | read_rnd_buffer_size = 256K
61 | myisam_sort_buffer_size = 1M
62 | thread_cache_size = 512
63 | query_cache_type = 0
64 | open_files_limit = 65535
65 | wait_timeout = 86400
66 |
67 | optimizer_switch=index_condition_pushdown=off
68 |
69 | tmp_table_size = 64M
70 | max_heap_table_size = 64M
71 |
72 | binlog_format=mixed
73 | binlog_cache_size = 64M
74 | max_binlog_size = 1G
75 | expire_logs_days = 3
76 |
77 | innodb_buffer_pool_size = 64G
78 | innodb_log_file_size = 4G
79 | innodb_log_buffer_size = 128M
80 | innodb_file_per_table = 1
81 | innodb_flush_method = O_DIRECT
82 | innodb_buffer_pool_instances = 8
83 | innodb_write_io_threads = 8
84 | innodb_read_io_threads = 8
85 | innodb_adaptive_flushing = 1
86 | innodb_lock_wait_timeout = 50
87 |
88 | innodb_flush_log_at_trx_commit = 2
89 |
90 | innodb_io_capacity = 2000
91 | innodb_io_capacity_max = 2500
92 | innodb_flush_neighbors = 0
93 |
94 | innodb_checksums = 1
95 | innodb_doublewrite = 1
96 | innodb_support_xa = 0
97 | innodb_thread_concurrency = 0
98 |
99 | innodb_purge_threads = 4
100 |
101 | gtid_domain_id = 1
102 | server_id =
103 | binlog_checksum = crc32
104 |
105 | innodb_lru_scan_depth = 512
106 |
107 | innodb_stats_on_metadata = 0
108 | innodb_stats_sample_pages = 32
109 |
110 | #
111 | # * Galera-related settings
112 | #
113 | [galera]
114 | # Mandatory settings
115 | #wsrep_on=ON
116 | #wsrep_provider=
117 | #wsrep_cluster_address=
118 | #binlog_format=row
119 | #default_storage_engine=InnoDB
120 | #innodb_autoinc_lock_mode=2
121 | #
122 | # Allow server to accept connections on all interfaces.
123 | #
124 | #bind-address=0.0.0.0
125 | #
126 | # Optional setting
127 | #wsrep_slave_threads=1
128 | #innodb_flush_log_at_trx_commit=0
129 |
130 | # this is only for embedded server
131 | [embedded]
132 |
133 | # This group is only read by MariaDB servers, not by MySQL.
134 | # If you use the same .cnf file for MySQL and MariaDB,
135 | # you can put MariaDB-only options here
136 | [mariadb]
137 |
138 | # This group is only read by MariaDB-10.2 servers.
139 | # If you use the same .cnf file for MariaDB of different versions,
140 | # use this group for options that older servers don't understand
141 | [mariadb-10.2]
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/zabbix-proxy-install-centos7.sh:
--------------------------------------------------------------------------------
1 | #update system
2 | yum update -y
3 |
4 | base=2.4
5 | minor=5
6 |
7 | #install mysql server
8 | yum install mariadb-server -y
9 |
10 | #start mysql server
11 | systemctl start mariadb
12 | echo $?
13 |
14 | #set root password
15 | /usr/bin/mysqladmin -u root password '5sRj4GXspvDKsBXW'
16 | echo $?
17 |
18 | #list existing databases
19 | mysql -h localhost -uroot -p5sRj4GXspvDKsBXW -P 3306 -s <<< 'show databases;'
20 | echo $?
21 |
22 | #create new database
23 | mysql -h localhost -uroot -p5sRj4GXspvDKsBXW -P 3306 -s <<< 'create database zabbix_proxy character set utf8 collate utf8_bin;'
24 | echo $?
25 |
26 | #create use for mysql and assign to database
27 | mysql -h localhost -uroot -p5sRj4GXspvDKsBXW -P 3306 -s <<< 'grant all privileges on zabbix_proxy.* to zabbix@localhost identified by "TaL2gPU5U9FcCU2u";'
28 | echo $?
29 |
30 | mysql -h localhost -uroot -p5sRj4GXspvDKsBXW -P 3306 -s <<< 'flush privileges;'
31 | echo $?
32 |
33 | mysql -h localhost -uroot -p5sRj4GXspvDKsBXW -P 3306 -s <<< 'show databases;'
34 | echo $?
35 |
36 | #enable mysql at startup
37 | systemctl enable mariadb
38 | echo $?
39 |
40 | #install zabbix repo
41 | rpm -ivh http://repo.zabbix.com/zabbix/$base/rhel/7/x86_64/zabbix-release-$base-1.el7.noarch.rpm
42 | rpm -ivh http://repo.zabbix.com/zabbix/$base/rhel/7/x86_64/zabbix-release-$base-2.el7.noarch.rpm
43 | echo $?
44 |
45 | #reroad repo content
46 | yum update -y
47 | echo $?
48 |
49 | #install zabbix proxy
50 | #yum install zabbix-proxy-2.4.5 -y
51 | yum install zabbix-proxy-mysql -y
52 | echo $?
53 | #this package creates user zabbix
54 | grep zabbix /etc/passwd
55 |
56 | #create basic database schema
57 | ls -l /usr/share/doc/zabbix-proxy-mysql*/
58 | zcat /usr/share/doc/zabbix-proxy-mysql*/schema.sql.gz | mysql -uzabbix -pTaL2gPU5U9FcCU2u zabbix_proxy
59 |
60 | grep "DBPassword=" /etc/zabbix/zabbix_proxy.conf
61 | sed -i "s/^.*DBPassword=.*$/DBPassword=TaL2gPU5U9FcCU2u/g" /etc/zabbix/zabbix_proxy.conf
62 | grep -v "^$\|^#" /etc/zabbix/zabbix_proxy.conf
63 |
64 | #check startup status of zabbix and mariadb
65 | systemctl list-unit-files | grep "zabbix\|mariadb"
66 |
67 | systemctl status zabbix-proxy
68 |
69 | systemctl enable zabbix-proxy
70 |
71 | systemctl start zabbix-proxy
72 |
73 | cat /var/log/zabbix/zabbix_proxy.log
74 | #cannot set resource limit: [13] Permission denied
75 |
76 | yum install policycoreutils-python -y
77 | grep "denied.*zabbix.*proxy" /var/log/audit/audit.log | audit2allow -M zabbix_proxy
78 | semodule -i zabbix_proxy.pp
79 |
80 | systemctl enable zabbix-proxy
81 |
82 | sed -i "s/^Server=.*$/Server=5d61050b753b.sn.mynetname.net/g" /etc/zabbix/zabbix_proxy.conf
83 | sed -i "s/^Hostname=.*$/Hostname=CentProxy/g" /etc/zabbix/zabbix_proxy.conf
84 | grep -v "^$\|^#" /etc/zabbix/zabbix_proxy.conf
85 |
86 | systemctl stop zabbix-proxy
87 | sleep 1
88 | > /var/log/zabbix/zabbix_proxy.log
89 | sleep 1
90 | systemctl start zabbix-proxy
91 | sleep 1
92 | cat /var/log/zabbix/zabbix_proxy.log
93 |
94 | #set up encryption
95 | mkdir -p /home/zabbix
96 | openssl rand -hex 32 > /home/zabbix/proxy.psk
97 | chmod 600 /home/zabbix/proxy.psk
98 | chown -R zabbix:zabbix /home/zabbix
99 | sed -i "s/^.*TLSConnect=.*$/TLSConnect=psk/g" /etc/zabbix/zabbix_proxy.conf
100 | sed -i "s/^.*TLSAccept=.*$/TLSAccept=psk/g" /etc/zabbix/zabbix_proxy.conf
101 | sed -i "s/^.*TLSPSKIdentity=.*$/TLSPSKIdentity=PSK002/g" /etc/zabbix/zabbix_proxy.conf
102 | sed -i "s/^.*TLSPSKFile=.*$/TLSPSKFile=\/home\/zabbix\/proxy.psk/g" /etc/zabbix/zabbix_proxy.conf
103 | grep -v "^$\|^#" /etc/zabbix/zabbix_proxy.conf
104 | cat /home/zabbix/proxy.psk
105 |
106 | systemctl stop zabbix-proxy
107 | sleep 1
108 | > /var/log/zabbix/zabbix_proxy.log
109 | sleep 1
110 | systemctl start zabbix-proxy
111 | sleep 1
112 | grep "denied.*proxy.psk" /var/log/audit/audit.log | audit2allow -M zabbix_proxy_psk_read
113 | semodule -i zabbix_proxy_psk_read.pp
114 |
115 | tail -f /var/log/zabbix/zabbix_proxy.log
116 |
117 | #if you receive
118 | #Unable to connect to the server [zabbix.server.name]:10051 [cannot connect to [[zabbix.server.name]:10051]: [13] Permission denied]
119 | #then install again selinux policies
120 | grep "denied.*zabbix.*proxy" /var/log/audit/audit.log | audit2allow -M zabbix_proxy
121 | semodule -i zabbix_proxy.pp
122 |
--------------------------------------------------------------------------------
/HA/custom-server-4.0-LTS-zabbix-server-only.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #this is tested and works together with fresh CentOS-7-x86_64-Minimal-1708.iso
4 | #cd && curl https://raw.githubusercontent.com/catonrug/zabbix-scripts/master/CentOS/custom-server-4.0-LTS-server-only-without-db.sh > install.sh && chmod +x install.sh && time ./install.sh 4.0.1
5 |
6 | #open 80 and 443 into firewall
7 | systemctl enable firewalld && systemctl start firewalld
8 |
9 | firewall-cmd --permanent --add-service=http
10 | firewall-cmd --permanent --add-service=https
11 | firewall-cmd --add-port=162/udp --permanent
12 | firewall-cmd --add-port=10051/tcp --permanent
13 | firewall-cmd --reload
14 |
15 | #update system
16 | yum -y update
17 |
18 | #install SELinux debuging utils
19 | yum -y install policycoreutils-python bzip2 vim nmap
20 |
21 | cat <<'EOF'> /etc/yum.repos.d/MariaDB.repo
22 | # http://downloads.mariadb.org/mariadb/repositories/
23 | [mariadb]
24 | name = MariaDB
25 | baseurl = http://yum.mariadb.org/10.3/centos7-amd64
26 | gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
27 | gpgcheck=1
28 | EOF
29 | cat /etc/yum.repos.d/MariaDB.repo
30 |
31 | yum makecache fast
32 |
33 | #install mariadb (mysql database engine for CentOS 7)
34 | yum -y install MariaDB-client
35 |
36 | #show existing databases
37 | mysql -h10.1.10.11 -uzabbix -pzabbix <<< 'show databases;'
38 |
39 | #add zabbix 4.0 repository
40 | rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
41 |
42 | #install zabbix server which are supposed to use MySQL as a database
43 | yum -y install zabbix-server-mysql
44 |
45 | #create zabbix database structure
46 | ls -l /usr/share/doc/zabbix-server-mysql*/
47 | zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -h10.1.10.11 -uzabbix -pzabbix zabbix
48 |
49 | systemctl status zabbix-server && systemctl stop zabbix-server
50 |
51 | #define server conf file
52 | server=/etc/zabbix/zabbix_server.conf
53 |
54 | # configure DBHost
55 | grep "^DBHost=" $server
56 | if [ $? -eq 0 ]; then
57 | sed -i "s/^DBHost=.*/DBHost=10.1.10.11/" $server
58 | else
59 | ln=$(grep -n "DBHost=" $server | egrep -o "^[0-9]+"); ln=$((ln+1))
60 | sed -i "`echo $ln`iDBHost=10.1.10.11" $server
61 | fi
62 |
63 | # configure DBPort
64 | grep "^DBPort=" $server
65 | if [ $? -eq 0 ]; then
66 | sed -i "s/^DBPort=.*/DBPort=3306/" $server
67 | else
68 | ln=$(grep -n "DBPort=" $server | egrep -o "^[0-9]+"); ln=$((ln+1))
69 | sed -i "`echo $ln`iDBPort=3306" $server
70 | fi
71 |
72 | # configure DBPassword
73 | grep "^DBPassword=" $server
74 | if [ $? -eq 0 ]; then
75 | sed -i "s/^DBPassword=.*/DBPassword=zabbix/" $server #modifies already customized setting
76 | else
77 | ln=$(grep -n "DBPassword=" $server | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
78 | sed -i "`echo $ln`iDBPassword=zabbix" $server #adds new line
79 | fi
80 |
81 | # configure CacheUpdateFrequency
82 | grep "^CacheUpdateFrequency=" $server
83 | if [ $? -eq 0 ]; then
84 | sed -i "s/^CacheUpdateFrequency=.*/CacheUpdateFrequency=4/" $server #modifies already customized setting
85 | else
86 | ln=$(grep -n "CacheUpdateFrequency=" $server | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
87 | sed -i "`echo $ln`iCacheUpdateFrequency=4" $server #adds new line
88 | fi
89 |
90 | #show zabbix server conf file
91 | grep -v "^$\|^#" $server
92 | echo
93 |
94 | #restart zabbix server
95 | systemctl start zabbix-server
96 | sleep 1
97 |
98 | #output all
99 | cat /var/log/zabbix/zabbix_server.log
100 |
101 | yum -y install zabbix-agent
102 |
103 | #define agent conf file
104 | agent=/etc/zabbix/zabbix_agentd.conf
105 |
106 | grep "^EnableRemoteCommands=" $agent
107 | if [ $? -eq 0 ]; then
108 | sed -i "s/^EnableRemoteCommands=.*/EnableRemoteCommands=1/" $agent #modifies already customized setting
109 | else
110 | ln=$(grep -n "EnableRemoteCommands=" $agent | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
111 | sed -i "`echo $ln`iEnableRemoteCommands=1" $agent #adds new line
112 | fi
113 |
114 | systemctl start zabbix-agent && systemctl enable zabbix-agent
115 |
116 | yum -y install zabbix-sender zabbix-get
117 |
118 | # disable zabbix server at startup
119 | systemctl disable zabbix-server
120 |
--------------------------------------------------------------------------------
/jmx/setup-proxy-centos7-java-gateway.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #cd && curl https://raw.githubusercontent.com/catonrug/zabbix-scripts/master/jmx/setup-proxy-centos7-java-gateway.sh > install.sh && chmod +x install.sh && time ./install.sh
4 |
5 | #open 80 and 443 into firewall
6 | systemctl enable firewalld && systemctl start firewalld
7 |
8 | firewall-cmd --permanent --add-service=http
9 | firewall-cmd --permanent --add-service=https
10 | firewall-cmd --add-port=162/udp --permanent
11 | firewall-cmd --add-port=10051/tcp --permanent
12 | firewall-cmd --reload
13 |
14 | #update system
15 | yum -y update
16 |
17 | #install SELinux debuging utils
18 | yum -y install policycoreutils-python bzip2 vim nmap
19 |
20 | #add zabbix 4.0 repository
21 | rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
22 |
23 | #install zabbix server which are supposed to use MySQL as a database
24 | yum -y install zabbix-proxy-sqlite3
25 |
26 |
27 | systemctl status zabbix-proxy && systemctl stop zabbix-proxy
28 |
29 | #define server conf file
30 | server=/etc/zabbix/zabbix_proxy.conf
31 |
32 | # configure Server
33 | grep "^Server=" $server
34 | if [ $? -eq 0 ]; then
35 | sed -i "s/^Server=.*/Server=ec2-35-166-97-138.us-west-2.compute.amazonaws.com/" $server
36 | else
37 | ln=$(grep -n "Server=" $server | egrep -o "^[0-9]+"); ln=$((ln+1))
38 | sed -i "`echo $ln`iServer=ec2-35-166-97-138.us-west-2.compute.amazonaws.com" $server
39 | fi
40 |
41 | # location for database
42 | grep "^DBName=" $server
43 | if [ $? -eq 0 ]; then
44 | sed -i "s/^DBName=.*/DBName=\/dev\/shm\/zabbix_proxy.sqlite3.db/" $server
45 | else
46 | ln=$(grep -n "DBName=" $server | egrep -o "^[0-9]+"); ln=$((ln+1))
47 | sed -i "`echo $ln`iDBName=\/dev\/shm\/zabbix_proxy.sqlite3.db" $server
48 | fi
49 |
50 | # configure CacheUpdateFrequency
51 | grep "^CacheUpdateFrequency=" $server
52 | if [ $? -eq 0 ]; then
53 | sed -i "s/^CacheUpdateFrequency=.*/CacheUpdateFrequency=4/" $server #modifies already customized setting
54 | else
55 | ln=$(grep -n "CacheUpdateFrequency=" $server | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
56 | sed -i "`echo $ln`iCacheUpdateFrequency=4" $server #adds new line
57 | fi
58 |
59 | # configure JavaGateway
60 | grep "^JavaGateway=" $server
61 | if [ $? -eq 0 ]; then
62 | sed -i "s/^JavaGateway=.*/JavaGateway=127.0.0.1/" $server #modifies already customized setting
63 | else
64 | ln=$(grep -n "JavaGateway=" $server | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
65 | sed -i "`echo $ln`iJavaGateway=127.0.0.1" $server #adds new line
66 | fi
67 |
68 | # configure StartJavaPollers
69 | grep "^StartJavaPollers=" $server
70 | if [ $? -eq 0 ]; then
71 | sed -i "s/^StartJavaPollers=.*/StartJavaPollers=1/" $server #modifies already customized setting
72 | else
73 | ln=$(grep -n "StartJavaPollers=" $server | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
74 | sed -i "`echo $ln`iStartJavaPollers=1" $server #adds new line
75 | fi
76 |
77 |
78 |
79 | #show zabbix server conf file
80 | grep -v "^$\|^#" $server
81 | echo
82 |
83 | #restart zabbix server
84 | systemctl start zabbix-proxy
85 | sleep 1
86 |
87 | #output all
88 | cat /var/log/zabbix/zabbix_proxy.log
89 |
90 | yum -y install zabbix-agent
91 |
92 | #define agent conf file
93 | agent=/etc/zabbix/zabbix_agentd.conf
94 |
95 | grep "^EnableRemoteCommands=" $agent
96 | if [ $? -eq 0 ]; then
97 | sed -i "s/^EnableRemoteCommands=.*/EnableRemoteCommands=1/" $agent #modifies already customized setting
98 | else
99 | ln=$(grep -n "EnableRemoteCommands=" $agent | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
100 | sed -i "`echo $ln`iEnableRemoteCommands=1" $agent #adds new line
101 | fi
102 |
103 | systemctl start zabbix-agent && systemctl enable zabbix-agent
104 |
105 | yum -y install zabbix-sender zabbix-get
106 |
107 | # disable zabbix server at startup
108 | systemctl enable zabbix-proxy
109 |
110 | yum -y install zabbix-java-gateway
111 |
112 | echo 'JAVA_OPTIONS="$JAVA_OPTIONS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1"' >> /etc/zabbix/zabbix_java_gateway.conf
113 |
114 |
115 | systemctl start zabbix-java-gateway
116 | systemctl enable zabbix-java-gateway
117 |
118 |
--------------------------------------------------------------------------------
/SuSe/agent-install-sles-12.3.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #http://zabbix.org/wiki/Install_on_openSUSE_/_SLES
4 |
5 | /sbin/SuSEfirewall2 off
6 | cat /etc/os-release
7 | zypper install gcc make
8 |
9 | v=3.4.5
10 |
11 |
12 | wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$v/zabbix-$v.tar.gz
13 | tar xvf zabbix-$v.tar.gz
14 |
15 | cd ~/zabbix-*
16 |
17 | ./configure --enable-agent
18 | #configure: error: Unable to use libpcre (libpcre check failed)
19 |
20 | cd
21 | wget --no-check-certificate https://ftp.internet.de/pub/linux/suse/sdk12sp2/suse/x86_64/libpcrecpp0-8.33-3.314.x86_64.rpm
22 | zypper install libpcrecpp0-8.33-3.314.x86_64.rpm
23 | wget --no-check-certificate https://ftp.internet.de/pub/linux/suse/sdk12sp2/suse/x86_64/libpcreposix0-8.33-3.314.x86_64.rpm
24 | zypper install libpcreposix0-8.33-3.314.x86_64.rpm
25 |
26 |
27 | zypper install zabbix-agent-3.4.5-12.2.x86_64.rpm
28 |
29 |
30 |
31 | cd ~/zabbix-*
32 |
33 | ./configure --enable-agent
34 |
35 |
36 | #configure: error: Unable to use libpcre (libpcre check failed)
37 | zypper search libpcre
38 |
39 | #https://ftp.internet.de/pub/linux/suse/iso/
40 | #SLE-12-SP1-SDK-DVD-x86_64-GM-DVD1.iso
41 | #SLE-12-SP2-SDK-DVD-x86_64-GM-DVD1.iso
42 | #https://ftp.internet.de/pub/linux/suse/sdk12sp2/suse/x86_64/
43 |
44 |
45 | ./configure --enable-agent --with-libcurl --with-libxml2 --with-ssh2
46 |
47 | cd
48 | wget --no-check-certificate https://ftp.internet.de/pub/linux/suse/sdk12sp2/suse/x86_64/libpcrecpp0-8.33-3.314.x86_64.rpm
49 | zypper install libpcrecpp0-8.33-3.314.x86_64.rpm
50 | wget --no-check-certificate https://ftp.internet.de/pub/linux/suse/sdk12sp2/suse/x86_64/libpcreposix0-8.33-3.314.x86_64.rpm
51 | zypper install libpcreposix0-8.33-3.314.x86_64.rpm
52 |
53 | zypper install zabbix-agent-3.4.5-12.2.x86_64.rpm
54 |
55 | Solution 1: do not install zabbix-agent-3.4.5-12.2.x86_64
56 | Solution 2: break zabbix-agent-3.4.5-12.2.x86_64 by ignoring some of its dependencies
57 |
58 |
59 |
60 | zypper install libevent-devel #configure: error: Unable to use libevent (libevent check failed)
61 | zypper install pcre-devel #configure: error: Unable to use libpcre (libpcre check failed)
62 | zypper install curl-devel #configure: error: Curl library not found
63 | zypper install mysql-devel #configure: error: MySQL library not found
64 | zypper install libxml2-devel #configure: error: LIBXML2 library not found
65 | zypper install libssh2-devel #configure: error: SSH2 library not found
66 | cd ~/zabbix-3.4.5
67 | ./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-libxml2 --with-ssh2
68 |
69 | time make install
70 |
71 | sed -i "s/^.*DBPassword=.*$/DBPassword=zabbix/g" /usr/local/etc/zabbix_server.conf
72 | grep -v "^$\|^#" /usr/local/etc/zabbix_server.conf
73 | /usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
74 | ps -aux | grep zabbix_server
75 |
76 |
77 | zypper install httpd
78 |
79 | service apache2 start
80 | service apache2 status
81 |
82 | cd ~/zabbix-*/frontends/php/
83 |
84 | cp -a . /srv/www/htdocs/zabbix
85 |
86 |
87 | /etc/apache2/conf.d
88 |
89 |
90 |
91 |
92 | zypper search php
93 | zypper install apache2-mod_php5
94 |
95 | zypper install
96 |
97 | chown -R wwwrun. /srv/www/zabbix
98 |
99 |
100 | zypper remove apache2-mod_php5 php5 php5-ctype php5-dom php5-iconv php5-json php5-pdo php5-sqlite php5-tokenizer php5-xmlreader php5-xmlwriter php5-devel php5-gd php5-bcmath php5-mysql
101 |
102 | #http://download.opensuse.org/repositories/devel:/languages:/php/SLE_12_SP1/x86_64/
103 | #https://software.opensuse.org/download.html?project=devel%3Alanguages%3Aphp&package=php7
104 | zypper addrepo https://download.opensuse.org/repositories/devel:languages:php/openSUSE_Factory/devel:languages:php.repo
105 | zypper refresh
106 | zypper install php7
107 | zypper install apache2-mod_php7
108 |
109 | #Problem: nothing provides libc.so.6(GLIBC_2.27)(64bit) needed by php7-7.2.5-129.1.x86_64
110 | # Solution 1: do not install apache2-mod_php7-7.2.5-129.1.x86_64
111 | # Solution 2: break apache2-mod_php7-7.2.5-129.1.x86_64 by ignoring some of its dependencies
112 |
113 | #php: error while loading shared libraries: libargon2.so.1: cannot open shared object file: No such file or directory
114 |
115 | zypper se -i php7
116 |
117 | groupadd zabbixs
118 | useradd -g zabbixs zabbixs
119 |
120 | /usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
121 |
122 |
123 | rcmysql start
124 |
125 | rczabbix-agentd start
126 |
127 | zabbix-agent start
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/certboot-install-nginx.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # zabbix speed install with validation
4 |
5 | echo 1 | sudo tee /proc/sys/vm/overcommit_memory
6 | sudo dd if=/dev/zero of=/myswap1 bs=1M count=1024 && sudo chown root:root /myswap1 && sudo chmod 0600 /myswap1 && sudo mkswap /myswap1 && sudo swapon /myswap1 && free -m
7 | sudo dd if=/dev/zero of=/myswap2 bs=1M count=1024 && sudo chown root:root /myswap2 && sudo chmod 0600 /myswap2 && sudo mkswap /myswap2 && sudo swapon /myswap2 && free -m
8 |
9 |
10 | rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
11 | rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
12 | # https://www.postgresql.org/download/linux/redhat/
13 | yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
14 |
15 | /usr/pgsql-12/bin/postgresql-12-setup initdb
16 | systemctl enable postgresql-12
17 | systemctl start postgresql-12
18 |
19 |
20 | yum clean all
21 |
22 | yum install -y python36 vim centos-release-scl zabbix-server-mysql zabbix-server-pgsql zabbix-agent screen
23 |
24 | vim /etc/yum.repos.d/zabbix.repo
25 | [zabbix-frontend]
26 | enabled=1
27 |
28 | yum install -y zabbix-web-mysql-scl zabbix-nginx-conf-scl
29 |
30 | yum -y install mysql-community-server && systemctl enable mysqld && systemctl start mysqld
31 |
32 | #open different schell
33 |
34 | vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
35 | listen.acl_users = apache,nginx
36 | php_value[memory_limit] = 2G
37 | php_value[date.timezone] = Europe/Riga
38 |
39 | vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
40 | listen 80;
41 | server_name next.catonrug.net;
42 |
43 | vim /etc/zabbix/zabbix_server.conf
44 | DBPassword=z4bbi#SIA
45 |
46 | systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
47 | curl -Lsk http://next.catonrug.net | grep Zabbix
48 |
49 |
50 | cd /etc/my.cnf.d
51 |
52 | cat << 'EOF' > performance_schema.cnf
53 | [mysqld]
54 | performance_schema = 0
55 | EOF
56 |
57 | cat << 'EOF' > disable_binary_log.cnf
58 | [mysqld]
59 | disable_log_bin
60 | EOF
61 |
62 | cat << 'EOF' > secure_file_priv.cnf
63 | [mysqld]
64 | secure-file-priv=/tmp
65 | EOF
66 |
67 | cat << 'EOF' > mysql_native_password.cnf
68 | [mysqld]
69 | default-authentication-plugin=mysql_native_password
70 | EOF
71 |
72 | grep "temporary password" /var/log/mysqld.log | sed "s|^.*localhost:.||" | xargs -i echo "/usr/bin/mysqladmin -u root password 'z4bbi#SIA' -p'{}'" | sudo bash
73 | cat << 'EOF' > ~/.my.cnf
74 | [client]
75 | user=root
76 | password='z4bbi#SIA'
77 | EOF
78 |
79 | mysql
80 | CREATE USER "zabbix"@"localhost" IDENTIFIED BY "z4bbi#SIA";
81 | ALTER USER "zabbix"@"localhost" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
82 | CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
83 | GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, ALTER, INDEX, REFERENCES ON zabbix.* TO "zabbix"@"localhost";
84 | FLUSH PRIVILEGES;
85 | exit
86 |
87 | mysql_secure_installation
88 |
89 | zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql zabbix
90 |
91 | #set selinux exceptions for httpd
92 | getsebool -a | grep "httpd_can_network_connect \|zabbix_can_network"
93 | setsebool -P httpd_can_network_connect on
94 | setsebool -P zabbix_can_network on
95 | getsebool -a | grep "httpd_can_network_connect \|zabbix_can_network"
96 |
97 | setenforce 0
98 | systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
99 |
100 | systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
101 |
102 | tail -99 /var/log/zabbix/zabbix_server.log
103 |
104 |
105 | curl -s https://dl.eff.org/certbot-auto -o /usr/bin/certbot-auto
106 | chmod +x /usr/bin/certbot-auto
107 |
108 | USE_PYTHON_3=1 certbot-auto certonly --webroot -w /usr/share/zabbix -d next.catonrug.net
109 |
110 | /etc/letsencrypt/live/next.catonrug.net/fullchain.pem
111 | /etc/letsencrypt/live/next.catonrug.net/privkey.pem
112 |
113 | cat << 'EOF' > /etc/opt/rh/rh-nginx116/nginx/conf.d/http.next.catonrug.net.conf
114 | server {
115 | listen next.catonrug.net:80;
116 | server_name next.catonrug.net;
117 | rewrite ^ https://$server_name$request_uri? permanent;
118 | }
119 | EOF
120 |
121 | vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
122 | listen 443 ssl;
123 |
124 | ssl_certificate /etc/letsencrypt/live/next.catonrug.net/fullchain.pem;
125 | ssl_certificate_key /etc/letsencrypt/live/next.catonrug.net/privkey.pem;
126 |
127 | systemctl reload rh-nginx116-nginx
128 |
129 |
130 | yum install -y policycoreutils-python
131 | audit2allow -a | grep -v "===\|^$" | sed -e '/#!!!!/,+1d'
132 | allow httpd_t zabbix_port_t:tcp_socket name_connect;
133 | grep "comm.*zabbix_server.*zabbix_t" /var/log/audit/audit.log | audit2allow -M comm_zabbix_server_zabbix_t
134 | semodule -i comm_zabbix_server_zabbix_t.pp
135 |
136 |
137 | https://ssl-config.mozilla.org/#server=nginx&version=1.17.7&config=intermediate&openssl=1.1.1d&guideline=5.6
138 |
139 |
140 | echo "* * * * * root USE_PYTHON_3=1 certbot-auto renew" | sudo tee /etc/cron.d/0007_letsencrypt_renewal
141 |
142 | tail -f /var/log/cron
143 |
144 | tail -f /var/log/letsencrypt/letsencrypt.log
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/MariaDB/master2master-node1.sh:
--------------------------------------------------------------------------------
1 |
2 | # ip: 10.0.2.81
3 |
4 | # move to super user
5 | sudo su
6 |
7 | # install vagrant ssh key
8 | echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== imported-openssh-key" > ~/.ssh/authorized_keys && chmod -R 600 ~/.ssh/authorized_keys
9 |
10 | # observe the centos version
11 | rpm --query centos-release
12 |
13 | # disable SELinux on the fly and after reboot
14 | setenforce 0 && sed -i "s/^SELINUX=.*$/SELINUX=disabled/" /etc/selinux/config && getenforce
15 |
16 | # status of firewalld
17 | systemctl status firewalld
18 |
19 | # update system
20 | yum -y update && yum -y upgrade
21 |
22 | # install time daemon
23 | yum -y install ntp && systemctl enable ntpd && systemctl start ntpd
24 |
25 | # set time zone
26 | sudo cp /usr/share/zoneinfo/Etc/GMT-3 /etc/localtime
27 | date
28 |
29 | # setup some conveniences
30 | yum -y install vim
31 |
32 | # add MariaDB repo from http://downloads.mariadb.org/mariadb/repositories/
33 | echo "IyBNYXJpYURCIDEwLjIgQ2VudE9TIHJlcG9zaXRvcnkgbGlzdCAtIGNyZWF0ZWQgMjAxOC0wOC0xMyAwNjozOSBVVEMKIyBodHRwOi8vZG93bmxvYWRzLm1hcmlhZGIub3JnL21hcmlhZGIvcmVwb3NpdG9yaWVzLwpbbWFyaWFkYl0KbmFtZSA9IE1hcmlhREIKYmFzZXVybCA9IGh0dHA6Ly95dW0ubWFyaWFkYi5vcmcvMTAuMi9jZW50b3M3LWFtZDY0CmdwZ2tleT1odHRwczovL3l1bS5tYXJpYWRiLm9yZy9SUE0tR1BHLUtFWS1NYXJpYURCCmdwZ2NoZWNrPTEK" | base64 --decode > /etc/yum.repos.d/MariaDB.repo
34 | cat /etc/yum.repos.d/MariaDB.repo
35 |
36 | # generate cache
37 | yum makecache
38 |
39 | # install mariadb server
40 | yum -y install MariaDB-server MariaDB-client
41 |
42 |
43 | systemctl stop maridb
44 |
45 | # During installation process MariaDB package will configure initial database and create redo log files with default file size. Remove these files:
46 | rm -rf /var/lib/mysql/ib_logfile*
47 |
48 | vim /etc/my.cnf.d/server.cnf
49 | # make sure [mysqld] section contains:
50 | log-bin
51 | server_id = 1
52 | log-basename=master1
53 |
54 | systemctl restart mariadb
55 | systemctl status mariadb
56 | systemctl enable mariadb
57 |
58 | vim /etc/my.cnf.d/server.cnf
59 | # make sure [mysqld] section contains:
60 | log-bin
61 | server_id = 2
62 | log-basename=master2
63 |
64 | systemctl restart mariadb
65 | systemctl status mariadb
66 | systemctl enable mariadb
67 |
68 |
69 | # open mysql
70 | mysql
71 |
72 | mysql <<< 'show variables like "server_id";'
73 | show slave status\G;
74 |
75 | # check the ip address of host
76 | system ip a
77 |
78 | # write all hosts where from where this database must be accessible
79 | mysql <<< 'GRANT REPLICATION SLAVE ON *.* TO "replicator"@"10.0.2.82" identified by "replicator"; FLUSH PRIVILEGES;'
80 | # set database tables in read only mode
81 | mysql <<< 'FLUSH TABLES WITH READ LOCK;'
82 |
83 | # create a dump. note we are using root account without password:
84 | cd
85 | mysqldump --master-data --gtid --all-databases > backup.sql
86 |
87 | # deliver the backup to second node
88 | scp ~/backup.sql root@10.0.2.82:~
89 |
90 | # hust because the destination node contains the databases with the same name, these databases will get droped. Any other database names which is not included in dump, but is in node2 will be leave as unattended.
91 |
92 | # log in into 10.0.2.82
93 |
94 | # stop slave and reset the conf
95 |
96 | cd
97 | # restore from dump
98 | cat backup.sql | mysql
99 |
100 |
101 | mysql <<< 'stop slave; reset slave;'
102 |
103 | # change the master for node2
104 | mysql <<< 'CHANGE MASTER TO master_host="10.0.2.81", master_port=3306, master_user="replicator", master_password="replicator", master_use_gtid=slave_pos;'
105 |
106 | # start slave
107 | mysql <<< 'start slave;'
108 |
109 | # check slave status
110 | mysql <<< 'show slave status\G;'
111 |
112 |
113 |
114 | # test if the replication works. lets create on node1
115 | mysql <<< 'create database zabbix character set utf8 collate utf8_bin;'
116 |
117 | # lest check on node2
118 | mysql <<< 'show databases;'
119 | # observe there is database with name 'zabbix'
120 |
121 | # run on node 2
122 | mysql <<< 'GRANT REPLICATION SLAVE ON *.* TO "replicator"@"10.0.2.81" identified by "replicator"; FLUSH PRIVILEGES;'
123 |
124 | # run on node 1
125 | mysql <<< 'stop slave; reset slave;'
126 | mysql <<< 'CHANGE MASTER TO master_host="10.0.2.82", master_port=3306, master_user="replicator", master_password="replicator", master_use_gtid=slave_pos;'
127 | mysql <<< 'start slave;'
128 |
129 | # there should be no logs under:
130 | mysql <<< 'show slave status\G;'
131 |
132 |
133 |
134 |
135 | mysql <<< 'UNLOCK TABLES;'
136 |
137 | mysql <<< 'drop database zabbix;'
138 |
139 |
140 | # stop slave;
141 |
142 | # reset slave
143 | # reset master
144 |
145 | create database zabbix character set utf8 collate utf8_bin;
146 | show databases;
147 | drop database zabbix;
148 |
149 | # Got fatal error 1236 from master when reading data from binary log: 'Binary log is not open'
150 | # Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
151 |
152 |
--------------------------------------------------------------------------------
/SuSe/zabbix-server-3.4.5-opensuse12.1.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #http://zabbix.org/wiki/Install_on_openSUSE_/_SLES
4 |
5 | cat /etc/os-release
6 |
7 | zypper install gcc make
8 |
9 | /sbin/SuSEfirewall2 off
10 |
11 | zypper install mysql mysql-client
12 |
13 | rcmysql start
14 |
15 | mysql_secure_installation
16 | /usr/bin/mysqladmin -u root password 'zabbix'
17 |
18 |
19 |
20 | mysql -u root -pzabbix
21 | CREATE DATABASE zabbix CHARACTER SET UTF8 collate utf8_bin;
22 | GRANT ALL PRIVILEGES on zabbix.* to "zabbix"@"%" IDENTIFIED BY "zabbix";
23 |
24 | mysql -h localhost -uroot -pzabbix -P 3306 -s <<< 'CREATE DATABASE zabbix CHARACTER SET UTF8 collate utf8_bin;'
25 | mysql -h localhost -uroot -pzabbix -P 3306 -s <<< 'GRANT ALL PRIVILEGES on zabbix.* to "zabbix"@"localhost" IDENTIFIED BY "zabbix";'
26 |
27 | mysql -h localhost -uroot -pzabbix -P 3306 -s <<< 'FLUSH PRIVILEGES;'
28 |
29 | mysql -h localhost -uroot -pzabbix -P 3306 -s <<< 'SHOW GRANTS;'
30 |
31 | mysql -h localhost -uroot -pzabbix -P 3306 -s <<< 'show databases;'
32 | show databases;
33 |
34 |
35 | wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.5/zabbix-3.4.5.tar.gz
36 | tar xvf zabbix-3.4.5.tar.gz
37 |
38 | cd ~/zabbix-3.4.5/database/mysql
39 | ls -1
40 | time mysql -uzabbix -pzabbix zabbix < schema.sql
41 | time mysql -uzabbix -pzabbix zabbix < images.sql
42 | time mysql -uzabbix -pzabbix zabbix < data.sql
43 |
44 |
45 | zypper install libevent-devel #configure: error: Unable to use libevent (libevent check failed)
46 | zypper install pcre-devel #configure: error: Unable to use libpcre (libpcre check failed)
47 | zypper install curl-devel #configure: error: Curl library not found
48 | zypper install mysql-devel #configure: error: MySQL library not found
49 | zypper install libxml2-devel #configure: error: LIBXML2 library not found
50 | zypper install libssh2-devel #configure: error: SSH2 library not found
51 | cd ~/zabbix-3.4.5
52 | ./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-libxml2 --with-ssh2
53 |
54 | time make install
55 |
56 | sed -i "s/^.*DBPassword=.*$/DBPassword=zabbix/g" /usr/local/etc/zabbix_server.conf
57 | grep -v "^$\|^#" /usr/local/etc/zabbix_server.conf
58 | /usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
59 | ps -aux | grep zabbix_server
60 |
61 |
62 | zypper install httpd
63 |
64 | service apache2 start
65 | service apache2 status
66 |
67 | cd ~/zabbix-*/frontends/php/
68 |
69 | cp -a . /srv/www/htdocs/zabbix
70 |
71 |
72 | /etc/apache2/conf.d
73 |
74 | echo "IwojIFphYmJpeCBtb25pdG9yaW5nIHN5c3RlbSBwaHAgd2ViIGZyb250ZW5kCiMKCkFsaWFzIC96YWJiaXggL3Nydi93d3cvaHRkb2NzL3phYmJpeAoKPERpcmVjdG9yeSAiL3Nydi93d3cvaHRkb2NzL3phYmJpeCI+CiAgICBPcHRpb25zIEZvbGxvd1N5bUxpbmtzCiAgICBBbGxvd092ZXJyaWRlIE5vbmUKICAgIE9yZGVyIGFsbG93LGRlbnkKICAgIEFsbG93IGZyb20gYWxsCgogICAgPElmTW9kdWxlIG1vZF9waHA1LmM+CiAgICAgICAgcGhwX3ZhbHVlIG1heF9leGVjdXRpb25fdGltZSAzMDAKICAgICAgICBwaHBfdmFsdWUgbWVtb3J5X2xpbWl0IDEyOE0KICAgICAgICBwaHBfdmFsdWUgcG9zdF9tYXhfc2l6ZSAxNk0KICAgICAgICBwaHBfdmFsdWUgdXBsb2FkX21heF9maWxlc2l6ZSAyTQogICAgICAgIHBocF92YWx1ZSBtYXhfaW5wdXRfdGltZSAzMDAKICAgICAgICBwaHBfdmFsdWUgYWx3YXlzX3BvcHVsYXRlX3Jhd19wb3N0X2RhdGEgLTEKICAgICAgICBwaHBfdmFsdWUgZGF0ZS50aW1lem9uZSBFdXJvcGUvUmlnYQogICAgPC9JZk1vZHVsZT4KPC9EaXJlY3Rvcnk+Cgo8RGlyZWN0b3J5ICIvc3J2L3d3dy9odGRvY3MvemFiYml4L2NvbmYiPgogICAgT3JkZXIgZGVueSxhbGxvdwogICAgRGVueSBmcm9tIGFsbAogICAgPGZpbGVzICoucGhwPgogICAgICAgIE9yZGVyIGRlbnksYWxsb3cKICAgICAgICBEZW55IGZyb20gYWxsCiAgICA8L2ZpbGVzPgo8L0RpcmVjdG9yeT4KCjxEaXJlY3RvcnkgIi9zcnYvd3d3L2h0ZG9jcy96YWJiaXgvYXBwIj4KICAgIE9yZGVyIGRlbnksYWxsb3cKICAgIERlbnkgZnJvbSBhbGwKICAgIDxmaWxlcyAqLnBocD4KICAgICAgICBPcmRlciBkZW55LGFsbG93CiAgICAgICAgRGVueSBmcm9tIGFsbAogICAgPC9maWxlcz4KPC9EaXJlY3Rvcnk+Cgo8RGlyZWN0b3J5ICIvc3J2L3d3dy9odGRvY3MvemFiYml4L2luY2x1ZGUiPgogICAgT3JkZXIgZGVueSxhbGxvdwogICAgRGVueSBmcm9tIGFsbAogICAgPGZpbGVzICoucGhwPgogICAgICAgIE9yZGVyIGRlbnksYWxsb3cKICAgICAgICBEZW55IGZyb20gYWxsCiAgICA8L2ZpbGVzPgo8L0RpcmVjdG9yeT4KCjxEaXJlY3RvcnkgIi9zcnYvd3d3L2h0ZG9jcy96YWJiaXgvbG9jYWwiPgogICAgT3JkZXIgZGVueSxhbGxvdwogICAgRGVueSBmcm9tIGFsbAogICAgPGZpbGVzICoucGhwPgogICAgICAgIE9yZGVyIGRlbnksYWxsb3cKICAgICAgICBEZW55IGZyb20gYWxsCiAgICA8L2ZpbGVzPgo8L0RpcmVjdG9yeT4KCg==" | base64 --decode > /etc/apache2/conf.d/zabbix.conf
75 |
76 | service apache2 stop
77 | service apache2 start
78 | service apache2 status
79 |
80 | zypper install php5
81 | zypper install php5-devel
82 | zypper install php5-gd
83 | zypper install php5-bcmath
84 | zypper install php5-mysql
85 |
86 |
87 | zypper search php
88 | zypper install apache2-mod_php5
89 |
90 | zypper install apache2-mod_php5 php5 php5-ctype php5-dom php5-iconv php5-json php5-pdo php5-sqlite php5-tokenizer php5-xmlreader php5-xmlwriter
91 |
92 | chown -R wwwrun. /srv/www/zabbix
93 |
94 |
95 | zypper remove apache2-mod_php5 php5 php5-ctype php5-dom php5-iconv php5-json php5-pdo php5-sqlite php5-tokenizer php5-xmlreader php5-xmlwriter php5-devel php5-gd php5-bcmath php5-mysql
96 |
97 | #http://download.opensuse.org/repositories/devel:/languages:/php/SLE_12_SP1/x86_64/
98 | #https://software.opensuse.org/download.html?project=devel%3Alanguages%3Aphp&package=php7
99 | zypper addrepo https://download.opensuse.org/repositories/devel:languages:php/openSUSE_Factory/devel:languages:php.repo
100 | zypper refresh
101 | zypper install php7
102 | zypper install apache2-mod_php7
103 |
104 | #Problem: nothing provides libc.so.6(GLIBC_2.27)(64bit) needed by php7-7.2.5-129.1.x86_64
105 | # Solution 1: do not install apache2-mod_php7-7.2.5-129.1.x86_64
106 | # Solution 2: break apache2-mod_php7-7.2.5-129.1.x86_64 by ignoring some of its dependencies
107 |
108 | #php: error while loading shared libraries: libargon2.so.1: cannot open shared object file: No such file or directory
109 |
110 | zypper se -i php7
111 |
112 | groupadd zabbixs
113 | useradd -g zabbixs zabbixs
114 |
115 | /usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/MariaDB/master2master-node2.sh:
--------------------------------------------------------------------------------
1 |
2 | # ip: 10.0.2.82
3 |
4 | # move to super user
5 | sudo su
6 |
7 | # install vagrant ssh key
8 | echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== imported-openssh-key" > ~/.ssh/authorized_keys
9 | chmod -R 600 ~/.ssh/authorized_keys
10 |
11 |
12 | # observe the centos version
13 | rpm --query centos-release
14 |
15 | # disable SELinux on the fly and after reboot
16 | setenforce 0 && sed -i "s/^SELINUX=.*$/SELINUX=disabled/" /etc/selinux/config && getenforce
17 |
18 | # status of firewalld
19 | systemctl status firewalld
20 |
21 | # disable selinux at next bootup
22 |
23 | # update system
24 | yum -y update && yum -y upgrade
25 |
26 | # install time daemon
27 | yum -y install ntp && systemctl enable ntpd && systemctl start ntpd
28 |
29 | # set time zone
30 | sudo cp /usr/share/zoneinfo/Etc/GMT-3 /etc/localtime
31 | date
32 |
33 | # setup some conveniences
34 | yum -y install vim
35 |
36 | # add MariaDB repo from http://downloads.mariadb.org/mariadb/repositories/
37 | echo "IyBNYXJpYURCIDEwLjIgQ2VudE9TIHJlcG9zaXRvcnkgbGlzdCAtIGNyZWF0ZWQgMjAxOC0wOC0xMyAwNjozOSBVVEMKIyBodHRwOi8vZG93bmxvYWRzLm1hcmlhZGIub3JnL21hcmlhZGIvcmVwb3NpdG9yaWVzLwpbbWFyaWFkYl0KbmFtZSA9IE1hcmlhREIKYmFzZXVybCA9IGh0dHA6Ly95dW0ubWFyaWFkYi5vcmcvMTAuMi9jZW50b3M3LWFtZDY0CmdwZ2tleT1odHRwczovL3l1bS5tYXJpYWRiLm9yZy9SUE0tR1BHLUtFWS1NYXJpYURCCmdwZ2NoZWNrPTEK" | base64 --decode > /etc/yum.repos.d/MariaDB.repo
38 | cat /etc/yum.repos.d/MariaDB.repo
39 |
40 |
41 | # generate cache
42 | yum makecache
43 |
44 | # install mariadb server
45 | yum -y install MariaDB-server MariaDB-client
46 |
47 | # During installation process MariaDB package will configure initial database and create redo log files with default file size. Remove these files:
48 | systemctl stop mariadb
49 | rm -rf /var/lib/mysql/ib_logfile*
50 |
51 | cp /etc/my.cnf.d/server.cnf ~
52 | echo "IwojIFRoZXNlIGdyb3VwcyBhcmUgcmVhZCBieSBNYXJpYURCIHNlcnZlci4KIyBVc2UgaXQgZm9yIG9wdGlvbnMgdGhhdCBvbmx5IHRoZSBzZXJ2ZXIgKGJ1dCBub3QgY2xpZW50cykgc2hvdWxkIHNlZQojCiMgU2VlIHRoZSBleGFtcGxlcyBvZiBzZXJ2ZXIgbXkuY25mIGZpbGVzIGluIC91c3Ivc2hhcmUvbXlzcWwvCiMKCiMgdGhpcyBpcyByZWFkIGJ5IHRoZSBzdGFuZGFsb25lIGRhZW1vbiBhbmQgZW1iZWRkZWQgc2VydmVycwpbc2VydmVyXQoKIyB0aGlzIGlzIG9ubHkgZm9yIHRoZSBteXNxbGQgc3RhbmRhbG9uZSBkYWVtb24KW215c3FsZF0KdXNlciA9IG15c3FsCmxvY2FsX2luZmlsZSA9IDAKc3ltYm9saWNfbGlua3MgPSAwCiAKZGVmYXVsdC1zdG9yYWdlLWVuZ2luZSA9IElubm9EQgpza2lwLW5hbWUtcmVzb2x2ZQprZXlfYnVmZmVyX3NpemUgPSAzMk0KbWF4X2FsbG93ZWRfcGFja2V0ID0gMTI4TQp0YWJsZV9vcGVuX2NhY2hlID0gMTAyNAp0YWJsZV9kZWZpbml0aW9uX2NhY2hlID0gMTAyNAptYXhfY29ubmVjdGlvbnMgPSAyMDAwCmpvaW5fYnVmZmVyX3NpemUgPSAxTQpzb3J0X2J1ZmZlcl9zaXplID0gMk0KcmVhZF9idWZmZXJfc2l6ZSA9IDI1NksKcmVhZF9ybmRfYnVmZmVyX3NpemUgPSAyNTZLCm15aXNhbV9zb3J0X2J1ZmZlcl9zaXplID0gMU0KdGhyZWFkX2NhY2hlX3NpemUgPSA1MTIKcXVlcnlfY2FjaGVfdHlwZSA9IDAKb3Blbl9maWxlc19saW1pdCA9IDY1NTM1CndhaXRfdGltZW91dCA9IDg2NDAwCiAKb3B0aW1pemVyX3N3aXRjaD1pbmRleF9jb25kaXRpb25fcHVzaGRvd249b2ZmCiAKdG1wX3RhYmxlX3NpemUgPSA2NE0KbWF4X2hlYXBfdGFibGVfc2l6ZSA9IDY0TQogCmJpbmxvZ19mb3JtYXQ9bWl4ZWQKYmlubG9nX2NhY2hlX3NpemUgPSA2NE0KbWF4X2JpbmxvZ19zaXplID0gMUcKZXhwaXJlX2xvZ3NfZGF5cyA9IDMKIAppbm5vZGJfYnVmZmVyX3Bvb2xfc2l6ZSA9IDFHCmlubm9kYl9sb2dfZmlsZV9zaXplID0gMjU2TQppbm5vZGJfbG9nX2J1ZmZlcl9zaXplID0gMTI4TQppbm5vZGJfZmlsZV9wZXJfdGFibGUgPSAxCmlubm9kYl9mbHVzaF9tZXRob2QgPSBPX0RJUkVDVAppbm5vZGJfYnVmZmVyX3Bvb2xfaW5zdGFuY2VzID0gOAppbm5vZGJfd3JpdGVfaW9fdGhyZWFkcyA9IDgKaW5ub2RiX3JlYWRfaW9fdGhyZWFkcyA9IDgKaW5ub2RiX2FkYXB0aXZlX2ZsdXNoaW5nID0gMQppbm5vZGJfbG9ja193YWl0X3RpbWVvdXQgPSA1MAogCmlubm9kYl9mbHVzaF9sb2dfYXRfdHJ4X2NvbW1pdCA9IDIKIAppbm5vZGJfaW9fY2FwYWNpdHkgPSAyMDAwCmlubm9kYl9pb19jYXBhY2l0eV9tYXggPSAyNTAwCmlubm9kYl9mbHVzaF9uZWlnaGJvcnMgPSAwCiAKaW5ub2RiX2NoZWNrc3VtcyA9IDEKaW5ub2RiX2RvdWJsZXdyaXRlID0gMQppbm5vZGJfc3VwcG9ydF94YSA9IDAKaW5ub2RiX3RocmVhZF9jb25jdXJyZW5jeSA9IDAKIAppbm5vZGJfcHVyZ2VfdGhyZWFkcyA9IDQKIApndGlkX2RvbWFpbl9pZCA9IDEKc2VydmVyX2lkID0gMQpiaW5sb2dfY2hlY2tzdW0gPSBjcmMzMgogCmlubm9kYl9scnVfc2Nhbl9kZXB0aCA9IDUxMgogCmlubm9kYl9zdGF0c19vbl9tZXRhZGF0YSA9IDAKaW5ub2RiX3N0YXRzX3NhbXBsZV9wYWdlcyA9IDMyCgojCiMgKiBHYWxlcmEtcmVsYXRlZCBzZXR0aW5ncwojCltnYWxlcmFdCiMgTWFuZGF0b3J5IHNldHRpbmdzCiN3c3JlcF9vbj1PTgojd3NyZXBfcHJvdmlkZXI9CiN3c3JlcF9jbHVzdGVyX2FkZHJlc3M9CiNiaW5sb2dfZm9ybWF0PXJvdwojZGVmYXVsdF9zdG9yYWdlX2VuZ2luZT1Jbm5vREIKI2lubm9kYl9hdXRvaW5jX2xvY2tfbW9kZT0yCiMKIyBBbGxvdyBzZXJ2ZXIgdG8gYWNjZXB0IGNvbm5lY3Rpb25zIG9uIGFsbCBpbnRlcmZhY2VzLgojCiNiaW5kLWFkZHJlc3M9MC4wLjAuMAojCiMgT3B0aW9uYWwgc2V0dGluZwojd3NyZXBfc2xhdmVfdGhyZWFkcz0xCiNpbm5vZGJfZmx1c2hfbG9nX2F0X3RyeF9jb21taXQ9MAoKIyB0aGlzIGlzIG9ubHkgZm9yIGVtYmVkZGVkIHNlcnZlcgpbZW1iZWRkZWRdCgojIFRoaXMgZ3JvdXAgaXMgb25seSByZWFkIGJ5IE1hcmlhREIgc2VydmVycywgbm90IGJ5IE15U1FMLgojIElmIHlvdSB1c2UgdGhlIHNhbWUgLmNuZiBmaWxlIGZvciBNeVNRTCBhbmQgTWFyaWFEQiwKIyB5b3UgY2FuIHB1dCBNYXJpYURCLW9ubHkgb3B0aW9ucyBoZXJlClttYXJpYWRiXQoKIyBUaGlzIGdyb3VwIGlzIG9ubHkgcmVhZCBieSBNYXJpYURCLTEwLjIgc2VydmVycy4KIyBJZiB5b3UgdXNlIHRoZSBzYW1lIC5jbmYgZmlsZSBmb3IgTWFyaWFEQiBvZiBkaWZmZXJlbnQgdmVyc2lvbnMsCiMgdXNlIHRoaXMgZ3JvdXAgZm9yIG9wdGlvbnMgdGhhdCBvbGRlciBzZXJ2ZXJzIGRvbid0IHVuZGVyc3RhbmQKW21hcmlhZGItMTAuMl0KCg==" | base64 --decode > /etc/my.cnf.d/server.cnf
53 | sed -i "s/^server_id.*$/server_id = 2/" /etc/my.cnf.d/server.cnf
54 | grep server_id /etc/my.cnf.d/server.cnf
55 |
56 | systemctl restart mariadb
57 | systemctl status mariadb
58 | systemctl enable mariadb
59 |
60 | # open mysql
61 | mysql
62 |
63 | show variables like 'server_id';
64 |
65 | # check the ip address of host
66 | system ip a
67 |
68 | GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'10.0.2.81' identified by 'replicator'; FLUSH PRIVILEGES;
69 |
70 | STOP SLAVE;
71 | CHANGE MASTER TO master_host="10.0.2.81", master_port=3306, master_user="replicator", master_password="replicator", master_use_gtid=current_pos;
72 | START SLAVE;
73 |
74 |
75 | # Create replication users on both nodes and reload privileges from grant tables:
76 |
77 |
--------------------------------------------------------------------------------
/CentOS7/centos7-mysql8-zabbix44.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | setenforce 0
4 |
5 | rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
6 |
7 | rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
8 |
9 | yum -y install epel-release
10 |
11 | yum makecache fast
12 |
13 | yum -y install mysql-community-server
14 |
15 | systemctl start mysqld
16 |
17 | systemctl status mysqld
18 |
19 | # change password. do not use '!' in password
20 | grep "temporary password" /var/log/mysqld.log | sed "s|^.*localhost:.||" | xargs -i echo "/usr/bin/mysqladmin -u root password 'z4bbi#SIA' -p'{}'" | sudo bash
21 |
22 | # set the same password as in previous step
23 | cat << 'EOF' > ~/.my.cnf
24 | [client]
25 | user=root
26 | password='z4bbi#SIA'
27 | EOF
28 |
29 | sleep 1
30 |
31 | mysql -e 'CREATE DATABASE zabbix character set utf8 collate utf8_bin;'
32 |
33 | # if ERROR 1396 (HY000): Operation CREATE USER failed for 'zabbix'@'127.0.0.1'
34 | # then
35 |
36 |
37 | # DROP USER "zabbix"@"127.0.0.1";
38 | # DROP USER "zabbix"@"localhost";
39 | # DROP USER "root"@"localhost";
40 |
41 | # flush privileges;
42 | # CREATE USER "zabbix"@"127.0.0.1" IDENTIFIED BY "z4bbi#SIA";
43 | # CREATE USER "zabbix"@"localhost" IDENTIFIED BY "z4bbi#SIA";
44 | # ALTER USER "zabbix"@"127.0.0.1" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
45 | # ALTER USER "zabbix"@"localhost" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
46 | # flush privileges;
47 | #
48 | # mysql -h127.0.0.1 -uzabbix -p'z4bbi#SIA'
49 | # mysql -hlocalhost -uzabbix -p'z4bbi#SIA'
50 |
51 |
52 | mysql -e 'DROP USER "zabbix"@"127.0.0.1";'
53 | mysql -e 'DROP USER "zabbix"@"localhost";'
54 |
55 | mysql -e 'flush privileges;'
56 |
57 | mysql -e 'CREATE USER "zabbix"@"127.0.0.1" IDENTIFIED BY "z4bbi#SIA";'
58 | mysql -e 'CREATE USER "zabbix"@"localhost" IDENTIFIED BY "z4bbi#SIA";'
59 |
60 | # from docker host
61 | mysql -e 'CREATE USER "zabbix"@"172.17.0.10" IDENTIFIED BY "z4bbi#SIA";'
62 | mysql -e 'CREATE USER "odbcuser"@"%" IDENTIFIED BY "z4bbi#SIA";'
63 |
64 |
65 |
66 | # [Z3001] connection to database 'zabbix' failed: [2059] Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
67 | mysql -e 'ALTER USER "zabbix"@"127.0.0.1" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";'
68 | mysql -e 'ALTER USER "zabbix"@"localhost" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";'
69 |
70 | <<<<<<< HEAD
71 |
72 | # ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
73 |
74 | # for mysql monitoring using root from 127.0.0.1 while using 'skip_name_resolve=1'
75 | mysql -e 'ALTER USER "root"@"%" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";'
76 |
77 | =======
78 | # allow DB to be accessed from docker host
79 | mysql -e 'ALTER USER "zabbix"@"172.17.0.10" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";'
80 | mysql -e 'ALTER USER "odbcuser"@"%" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";'
81 | >>>>>>> d2e095dfaa386d9e614c1437de25aeb93a48a8f6
82 |
83 | # ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'z4bbi#SIA'' at line 1
84 | # assign privilages
85 | mysql -e 'GRANT ALL ON zabbix.* TO "zabbix"@"127.0.0.1";'
86 | mysql -e 'GRANT ALL ON zabbix.* TO "zabbix"@"localhost";'
87 | mysql -e 'GRANT ALL ON z40.* TO "zabbix"@"10.133.253.43";'
88 |
89 | <<<<<<< HEAD
90 | # perfect user root to use together with 'skip_name_resolve=1'
91 | DROP USER "root"@"localhost";
92 | FLUSH PRIVILEGES;
93 | CREATE USER "root"@"127.0.0.1" IDENTIFIED BY "z4bbi#SIA";
94 | ALTER USER "root"@"127.0.0.1" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
95 | FLUSH PRIVILEGES;
96 | =======
97 | # allow DB to be accessed from docker host
98 | mysql -e 'GRANT ALL ON zabbix.* TO "zabbix"@"172.17.0.10";'
99 | mysql -e 'GRANT ALL ON zabbix.* TO "odbcuser"@"%";'
100 | >>>>>>> d2e095dfaa386d9e614c1437de25aeb93a48a8f6
101 |
102 | mysql -e 'flush privileges;'
103 |
104 |
105 | yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-agent
106 |
107 | # insert schema
108 | zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql zabbix
109 |
110 | # define server conf file
111 | server=/etc/zabbix/zabbix_server.conf
112 | grep "^DBPassword=" $server
113 | if [ $? -eq 0 ]; then
114 | sed -i "s/^DBPassword=.*/DBPassword=z4bbi#SIA/" $server #modifies already customized setting
115 | else
116 | ln=$(grep -n "DBPassword=" $server | egrep -o "^[0-9]+"); ln=$((ln+1)) #calculate the the line number after default setting
117 | sed -i "`echo $ln`iDBPassword=z4bbi#SIA" $server #adds new line
118 | fi
119 |
120 | # determine the external ip in digital ocean
121 | yum -y install bind-utils
122 | connect=$(dig +short myip.opendns.com @resolver1.opendns.com)
123 |
124 | # configure web server to listen on external IP
125 | sed -i "s|^.*listen.*80.*$|listen 80;|1" /etc/nginx/conf.d/zabbix.conf
126 | sed -i "s|^.*server_name.*example.com.*$|server_name $connect;|1" /etc/nginx/conf.d/zabbix.conf
127 |
128 | # set timezone
129 | timezone=Europe/Riga
130 | sed -i "s|^.*php_value.date.timezone.*$|php_value[date.timezone] = $timezone|" /etc/php-fpm.d/zabbix.conf
131 |
132 | cat << 'EOF' > /etc/zabbix/web/zabbix.conf.php
133 | > $server
100 | grep -v "^$\|^#" $server
101 |
102 | #start
103 | systemctl start zabbix-server
104 | echo $?
105 |
106 | cat /var/log/zabbix/zabbix_server.log
107 |
108 | #enable after reboot
109 | systemctl enable zabbix-server
110 |
111 | #install web server
112 | yum install httpd -y
113 |
114 | yum install dejavu-sans-fonts php php-bcmath php-gd php-ldap php-mbstring php-xml php-mysql -y
115 |
116 | #install front end
117 | rpm -iv zabbix-web-3.4.5
118 | #error: Failed dependencies:
119 | # dejavu-sans-fonts is needed by zabbix-web
120 | # php >= 5.4 is needed by zabbix-web
121 | # php-bcmath is needed by zabbix-web
122 | # php-gd is needed by zabbix-web
123 | # php-ldap is needed by zabbix-web
124 | # php-mbstring is needed by zabbix-web
125 | # php-xml is needed by zabbix-web
126 | # zabbix-web-database = 3.4.8-0.0.1r78441.el7 is needed by zabbix-web
127 |
128 |
129 | rpm -iv zabbix-web-mysql-* zabbix-web-3.*
130 |
131 | #set up timezone
132 | sed -i "s/^.*php_value date.timezone .*$/php_value date.timezone Europe\/Riga/" /etc/httpd/conf.d/zabbix.conf
133 |
134 | systemctl restart httpd
135 | systemctl status httpd
136 |
137 | rpm -iv zabbix-agent-*
138 | systemctl start zabbix-agent
139 | echo $?
140 | systemctl enable zabbix-agent
141 |
142 | rpm -iv zabbix-get-*
143 | rpm -iv zabbix-sender-*
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/MySQL/manually-create-partition.sh:
--------------------------------------------------------------------------------
1 | use zabbix;
2 |
3 | ALTER TABLE `history_uint` PARTITION BY RANGE(clock);
4 |
5 | ALTER TABLE `history_uint` PARTITION BY RANGE(clock)
6 | (
7 | PARTITION p2018___OLD VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-01 00:00:00")) ENGINE=InnoDB,
8 | PARTITION p2018_04_01 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-02 00:00:00")) ENGINE=InnoDB,
9 | PARTITION p2018_04_02 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-03 00:00:00")) ENGINE=InnoDB,
10 | PARTITION p2018_04_03 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-04 00:00:00")) ENGINE=InnoDB,
11 | PARTITION p2018_04_04 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-05 00:00:00")) ENGINE=InnoDB,
12 | PARTITION p2018_04_05 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-06 00:00:00")) ENGINE=InnoDB,
13 | PARTITION p2018_04_06 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-07 00:00:00")) ENGINE=InnoDB,
14 | PARTITION p2018_04_07 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-08 00:00:00")) ENGINE=InnoDB,
15 | PARTITION p2018_04_08 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-09 00:00:00")) ENGINE=InnoDB,
16 | PARTITION p2018_04_09 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-10 00:00:00")) ENGINE=InnoDB,
17 | PARTITION p2018_04_10 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-11 00:00:00")) ENGINE=InnoDB,
18 | PARTITION p2018_04_11 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-12 00:00:00")) ENGINE=InnoDB,
19 | PARTITION p2018_04_12 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-13 00:00:00")) ENGINE=InnoDB,
20 | PARTITION p2018_04_13 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-14 00:00:00")) ENGINE=InnoDB,
21 | PARTITION p2018_04_14 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-15 00:00:00")) ENGINE=InnoDB,
22 | PARTITION p2018_04_15 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-16 00:00:00")) ENGINE=InnoDB,
23 | PARTITION p2018_04_16 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-17 00:00:00")) ENGINE=InnoDB,
24 | PARTITION p2018_04_17 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-18 00:00:00")) ENGINE=InnoDB,
25 | PARTITION p2018_04_18 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-19 00:00:00")) ENGINE=InnoDB,
26 | PARTITION p2018_04_19 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-20 00:00:00")) ENGINE=InnoDB,
27 | PARTITION p2018_04_20 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-21 00:00:00")) ENGINE=InnoDB,
28 | PARTITION p2018_04_21 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-22 00:00:00")) ENGINE=InnoDB,
29 | PARTITION p2018_04_22 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-23 00:00:00")) ENGINE=InnoDB,
30 | PARTITION p2018_04_23 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-24 00:00:00")) ENGINE=InnoDB,
31 | PARTITION p2018_04_24 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-25 00:00:00")) ENGINE=InnoDB,
32 | PARTITION p2018_04_25 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-26 00:00:00")) ENGINE=InnoDB,
33 | PARTITION p2018_04_26 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-27 00:00:00")) ENGINE=InnoDB,
34 | PARTITION p2018_04_27 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-28 00:00:00")) ENGINE=InnoDB,
35 | PARTITION p2018_04_28 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-29 00:00:00")) ENGINE=InnoDB,
36 | PARTITION p2018_04_29 VALUES LESS THAN (UNIX_TIMESTAMP("2018-04-30 00:00:00")) ENGINE=InnoDB,
37 | PARTITION p2018_04_30 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-01 00:00:00")) ENGINE=InnoDB,
38 |
39 | PARTITION p2018_05_01 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-02 00:00:00")) ENGINE=InnoDB,
40 | PARTITION p2018_05_02 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-03 00:00:00")) ENGINE=InnoDB,
41 | PARTITION p2018_05_03 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-04 00:00:00")) ENGINE=InnoDB,
42 | PARTITION p2018_05_04 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-05 00:00:00")) ENGINE=InnoDB,
43 | PARTITION p2018_05_05 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-06 00:00:00")) ENGINE=InnoDB,
44 | PARTITION p2018_05_06 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-07 00:00:00")) ENGINE=InnoDB,
45 | PARTITION p2018_05_07 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-08 00:00:00")) ENGINE=InnoDB,
46 | PARTITION p2018_05_08 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-09 00:00:00")) ENGINE=InnoDB,
47 | PARTITION p2018_05_09 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-10 00:00:00")) ENGINE=InnoDB,
48 | PARTITION p2018_05_10 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-11 00:00:00")) ENGINE=InnoDB,
49 | PARTITION p2018_05_11 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-12 00:00:00")) ENGINE=InnoDB,
50 | PARTITION p2018_05_12 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-13 00:00:00")) ENGINE=InnoDB,
51 | PARTITION p2018_05_13 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-14 00:00:00")) ENGINE=InnoDB,
52 | PARTITION p2018_05_14 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-15 00:00:00")) ENGINE=InnoDB,
53 | PARTITION p2018_05_15 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-16 00:00:00")) ENGINE=InnoDB,
54 | PARTITION p2018_05_16 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-17 00:00:00")) ENGINE=InnoDB,
55 | PARTITION p2018_05_17 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-18 00:00:00")) ENGINE=InnoDB,
56 | PARTITION p2018_05_18 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-19 00:00:00")) ENGINE=InnoDB,
57 | PARTITION p2018_05_19 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-20 00:00:00")) ENGINE=InnoDB,
58 | PARTITION p2018_05_20 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-21 00:00:00")) ENGINE=InnoDB,
59 | PARTITION p2018_05_21 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-22 00:00:00")) ENGINE=InnoDB,
60 | PARTITION p2018_05_22 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-23 00:00:00")) ENGINE=InnoDB,
61 | PARTITION p2018_05_23 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-24 00:00:00")) ENGINE=InnoDB,
62 | PARTITION p2018_05_24 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-25 00:00:00")) ENGINE=InnoDB,
63 | PARTITION p2018_05_25 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-26 00:00:00")) ENGINE=InnoDB,
64 | PARTITION p2018_05_26 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-27 00:00:00")) ENGINE=InnoDB,
65 | PARTITION p2018_05_27 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-28 00:00:00")) ENGINE=InnoDB,
66 | PARTITION p2018_05_28 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-29 00:00:00")) ENGINE=InnoDB,
67 | PARTITION p2018_05_29 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-30 00:00:00")) ENGINE=InnoDB,
68 | PARTITION p2018_05_30 VALUES LESS THAN (UNIX_TIMESTAMP("2018-05-31 00:00:00")) ENGINE=InnoDB,
69 | PARTITION p2018_05_31 VALUES LESS THAN (UNIX_TIMESTAMP("2018-06-01 00:00:00")) ENGINE=InnoDB,
70 |
71 | PARTITION p2018_06_01 VALUES LESS THAN (UNIX_TIMESTAMP("2018-06-02 00:00:00")) ENGINE=InnoDB,
72 | PARTITION p2018_06_02 VALUES LESS THAN (UNIX_TIMESTAMP("2018-06-03 00:00:00")) ENGINE=InnoDB,
73 | PARTITION p2018_06_03 VALUES LESS THAN (UNIX_TIMESTAMP("2018-06-04 00:00:00")) ENGINE=InnoDB,
74 | PARTITION p2018_06_04 VALUES LESS THAN (UNIX_TIMESTAMP("2018-06-05 00:00:00")) ENGINE=InnoDB,
75 | PARTITION p2018_06_05 VALUES LESS THAN (UNIX_TIMESTAMP("2018-06-06 00:00:00")) ENGINE=InnoDB
76 | );
77 |
78 | show create table history_uint\G
79 |
--------------------------------------------------------------------------------
/mysql8cluster.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # MySQL Shell
4 | # Configure and do all the backstage work
5 | # Create a cluster
6 | # Add and remove instances to the cluster
7 | # Monitor the cluster
8 | # Cluster management
9 | # Besides doing queries, updates and administration operations to the instances
10 | # MySQL Router
11 | # Create a proxy for the cluster
12 | # Route database traffic
13 |
14 |
15 |
16 | # curl https://raw.githubusercontent.com/catonrug/zabbix-scripts/master/mysql8cluster.sh > mysql8cluster.sh && chmod +x mysql8cluster.sh
17 |
18 | sudo dd if=/dev/zero of=/myswap1 bs=1M count=1024 && sudo chown root:root /myswap1 && sudo chmod 0600 /myswap1 && sudo mkswap /myswap1 && sudo swapon /myswap1 && free -m
19 |
20 | sudo dd if=/dev/zero of=/myswap2 bs=1M count=1024 && sudo chown root:root /myswap2 && sudo chmod 0600 /myswap2 && sudo mkswap /myswap2 && sudo swapon /myswap2 && free -m
21 |
22 | sudo dd if=/dev/zero of=/myswap3 bs=1M count=1024 && sudo chown root:root /myswap3 && sudo chmod 0600 /myswap3 && sudo mkswap /myswap3 && sudo swapon /myswap3 && free -m
23 |
24 | sudo dd if=/dev/zero of=/myswap4 bs=1M count=1024 && sudo chown root:root /myswap4 && sudo chmod 0600 /myswap4 && sudo mkswap /myswap4 && sudo swapon /myswap4 && free -m
25 |
26 | echo 1 | sudo tee /proc/sys/vm/overcommit_memory
27 |
28 | setenforce 0
29 |
30 |
31 | # install repository
32 | sudo yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
33 |
34 |
35 | sudo yum makecache fast
36 | # sudo yum -y update
37 |
38 | # install conveniences
39 | sudo yum -y install vim
40 |
41 | # install time daemon
42 | sudo yum -y install ntp
43 |
44 | sudo systemctl stop ntpd
45 | sudo ntpd -gq
46 | sudo systemctl start ntpd
47 |
48 | sudo systemctl enable ntpd
49 |
50 | timedatectl set-timezone "Europe/Riga"
51 |
52 | date
53 |
54 | sudo yum -y install mysql-community-client mysql-community-server
55 |
56 | # add to [mysqld] section
57 | cat << EOF >> /etc/my.cnf
58 |
59 | enforce_gtid_consistency = on
60 | gtid_mode = on
61 | log_slave_updates = on
62 | log_bin = on
63 | binlog_format = row
64 | binlog_checksum = none
65 | sync_binlog = 1
66 | master_info_repository = table
67 | relay_log_info_repository = table
68 | transaction_write_set_extraction = XXHASH64
69 | disabled_storage_engines = "MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
70 | default-authentication-plugin=mysql_native_password
71 | server_id = $(hostname -s | grep -Eo "[0-9]+" | sed "s|$|0|")
72 | EOF
73 |
74 | sudo systemctl start mysqld
75 | sudo systemctl enable mysqld
76 |
77 | # change password. do not use '!' in password
78 | grep "temporary password" /var/log/mysqld.log | sed "s|^.*localhost:.||" | xargs -i echo "/usr/bin/mysqladmin -u root password 'z4bbi#SIA' -p'{}'" | sudo bash
79 |
80 | # set the same password as in previous step
81 | cat << 'EOF' > ~/.my.cnf
82 | [client]
83 | user=root
84 | password='z4bbi#SIA'
85 | EOF
86 |
87 |
88 | # never point to 127.0.0.1 while working with nodes
89 | sed -i "s|^.*$(hostname -s).*$||" /etc/hosts
90 |
91 | # add additional records
92 | echo '
93 | 10.133.80.228 mysql1
94 | 10.133.253.44 mysql2
95 | 10.133.253.45 mysql3
96 | ' | tee -a /etc/hosts
97 |
98 | # on all nodes
99 | cat << EOF >> /etc/my.cnf
100 |
101 | report_host = $(hostname -s)
102 | group_replication_ip_whitelist = mysql1,mysql2,mysql3
103 | plugin_load_add = group_replication.so
104 | group_replication_start_on_boot = on
105 | group_replication_single_primary_mode = on
106 |
107 | EOF
108 | cat /etc/my.cnf
109 |
110 | # user to administer cluster
111 | mysql -e '
112 | CREATE USER "cluster_admin"@"%" IDENTIFIED BY "z4bbi#SIA";
113 | GRANT ALL PRIVILEGES ON *.* TO "cluster_admin"@"%" WITH GRANT OPTION;
114 | '
115 |
116 | sudo systemctl stop mysqld && sudo systemctl start mysqld
117 |
118 |
119 | sudo yum -y install mysql-shell
120 |
121 |
122 |
123 | # on first kickstart node
124 | mysql -e '
125 | CREATE USER "zabbix"@"%" IDENTIFIED BY "z4bbi#SIA";
126 | ALTER USER "zabbix"@"%" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
127 | CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
128 | GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, ALTER, INDEX, REFERENCES ON zabbix.* TO "zabbix"@"%";
129 | FLUSH PRIVILEGES;
130 | '
131 |
132 | curl -kLs "https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.3.tar.gz" -o zabbix-source.tar.gz
133 | ls -lh
134 | tar -xzf zabbix-source.tar.gz
135 |
136 | cd ~/zabbix-5.0.3/database/mysql
137 | cat schema.sql images.sql data.sql | mysql zabbix
138 |
139 | mysql -e '
140 | ALTER TABLE `zabbix`.`history` ADD `id` bigint PRIMARY KEY AUTO_INCREMENT;
141 | ALTER TABLE `zabbix`.`history_uint` ADD `id` bigint PRIMARY KEY AUTO_INCREMENT;
142 | ALTER TABLE `zabbix`.`history_str` ADD `id` bigint PRIMARY KEY AUTO_INCREMENT;
143 | ALTER TABLE `zabbix`.`history_log` ADD `id` bigint PRIMARY KEY AUTO_INCREMENT;
144 | ALTER TABLE `zabbix`.`history_text` ADD `id` bigint PRIMARY KEY AUTO_INCREMENT;
145 | ALTER TABLE `zabbix`.`dbversion` ADD `id` bigint PRIMARY KEY AUTO_INCREMENT;
146 | '
147 |
148 | mysqlsh /c cluster_admin@mysql1:3306
149 |
150 | var i1='cluster_admin@mysql1:3306',i2='cluster_admin@mysql2:3306',i3='cluster_admin@mysql3:3306';
151 |
152 | dba.checkInstanceConfiguration(i1);
153 | # z4bbi#SIA
154 | dba.checkInstanceConfiguration(i2);
155 | # z4bbi#SIA
156 | dba.checkInstanceConfiguration(i3);
157 | # z4bbi#SIA
158 |
159 |
160 | var cluster=dba.createCluster('zabbix_cluster',{
161 | memberWeight: 50,
162 | memberSslMode: "REQUIRED",
163 | ipWhitelist: "mysql1, mysql2, mysql3",
164 | localAddress: "mysql1"
165 | });
166 |
167 | cluster.status();
168 |
169 |
170 | cluster.addInstance(i2,{
171 | memberWeight: 30,
172 | ipWhitelist: "mysql1, mysql2, mysql3",
173 | localAddress: "mysql2:33061"
174 | });
175 | # press C to continue
176 |
177 | cluster.addInstance(i3,{
178 | memberWeight: 30,
179 | ipWhitelist: "mysql1, mysql2, mysql3",
180 | localAddress: "mysql3:33061"
181 | });
182 |
183 | \q
184 |
185 | # sudo yum -y install mysql-router-community
186 |
187 | # sudo mysqlrouter --bootstrap cluster_admin@mysql1:3306 --user=mysqlrouter --force
188 | # z4bbi#SIA
189 |
190 | # mysql --protocol=TCP -ucluster_admin -p -P 6446
191 | # z4bbi#SIA
192 |
193 |
194 | CREATE USER "zabbix"@"mysql1" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
195 | GRANT ALL PRIVILEGES ON zabbix.* TO "zabbix"@"mysql1";
196 | CREATE USER "zabbix"@"mysql2" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
197 | GRANT ALL PRIVILEGES ON zabbix.* TO "zabbix"@"mysql2";
198 | CREATE USER "zabbix"@"mysql3" IDENTIFIED WITH mysql_native_password BY "z4bbi#SIA";
199 | GRANT ALL PRIVILEGES ON zabbix.* TO "zabbix"@"mysql3";
200 |
--------------------------------------------------------------------------------
/zabbix-offline-ubuntu20-create-iso.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # instruction based on thread:
4 | # https://gist.github.com/jeanlescure/084dd6113931ea5a0fd9
5 |
6 | # sequence tested on "Ubuntu 20.04.2 LTS"
7 |
8 | # download zabbix repo
9 | wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
10 | # install zabbix repo
11 | dpkg -i zabbix-release_5.0-1+focal_all.deb
12 |
13 | # install prerequisites to create an offline repository
14 | apt-get update && apt-get install -y apt-rdepends dpkg-dev gzip genisoimage
15 |
16 | # create a working directory '/repo' that will hold the scripts which will create an offline repository
17 | # '/repo/offline' will contain all packages
18 | mkdir -p /repo/offline
19 |
20 | # because 'apt' utility runs behind a dedicated service user it's better to set the working directory be owned by user '_apt'
21 | chown _apt -R /repo
22 |
23 | # navigate to user '_apt'
24 | su - _apt -s /bin/bash
25 | # it will say:
26 | # su: warning: cannot change directory to /nonexistent: No such file or directory
27 | # that is fine
28 |
29 | # enter directory where scripts will be located
30 | cd /repo
31 |
32 | # create a script which will download all dependencies
33 | echo "IyEvdXNyL2Jpbi9lbnYgYmFzaAoKZnVuY3Rpb24gZXJyb3JfZXhpdAp7CiAgZWNobyAiJDEiIDE+JjIKICBlY2hvICJVc2FnZTogLi9nZXRwa2cuc2ggPHBhY2thZ2UtbmFtZT4gPHBhY2thZ2VzLWRpcmVjdG9yeT4iIDE+JjIKICBleGl0IDEKfQoKUEtHPSIkMSIKUEtHRElSPSIkMiIKCmlmIFsgLXogIiRQS0ciIF07IHRoZW4KICBlcnJvcl9leGl0ICJObyBwYWNrYWdlIG5hbWUgc2V0ISIKZmkKCmlmIFsgLXogIiRQS0dESVIiIF07IHRoZW4KICBlcnJvcl9leGl0ICJObyBwYWNrYWdlcyBkaXJlY3RvcnkgcGF0aCBzZXQhIgpmaQoKY2QgJFBLR0RJUgoKZm9yIGkgaW4gJChhcHQtcmRlcGVuZHMgJFBLR3xncmVwIC12ICJeICIpCiAgZG8gISBhcHQtZ2V0IGRvd25sb2FkICRpCmRvbmUK" | base64 --decode > getpkg.sh
34 | # set script executable
35 | chmod +x getpkg.sh
36 |
37 |
38 | # request to download a base package. this will download all dependencies too.
39 | ./getpkg.sh mysql-server offline ; ./getpkg.sh zabbix-server-mysql offline ; ./getpkg.sh zabbix-frontend-php offline ; ./getpkg.sh zabbix-nginx-conf offline ; ./getpkg.sh zabbix-agent offline ; ./getpkg.sh zabbix-agent2 offline ; ./getpkg.sh zabbix-proxy-sqlite3 offline ; ./getpkg.sh zabbix-get offline ; ./getpkg.sh zabbix-sender offline ; ./getpkg.sh zabbix-js offline ; ./getpkg.sh zabbix-java-gateway offline
40 | # wait 5 minutes
41 | # during the time, it will print:
42 | # Can't select candidate version from package debconf-2.0 as it has no candidate
43 | # that is fine
44 |
45 | # create a script which will contain data which packages are available in this offline repository.
46 | echo "IyEvdXNyL2Jpbi9lbnYgYmFzaAoKZnVuY3Rpb24gZXJyb3JfZXhpdAp7CiAgZWNobyAiJDEiIDE+JjIKICBlY2hvICJVc2FnZTogLi9ta3JlcG8uc2ggPHBhY2thZ2VzLWRpcmVjdG9yeT4iIDE+JjIKICBleGl0IDEKfQoKUEtHRElSPSIkMSIKCmlmIFsgLXogIiRQS0dESVIiIF07IHRoZW4KICBlcnJvcl9leGl0ICJObyBwYWNrYWdlcyBkaXJlY3RvcnkgcGF0aCBzZXQhIgpmaQoKY2QgJFBLR0RJUgoKZHBrZy1zY2FucGFja2FnZXMgLi8gL2Rldi9udWxsIHwgZ3ppcCAtOWMgPiAuL1BhY2thZ2VzLmd6Cg==" | base64 --decode > mkrepo.sh
47 | # set script executable
48 | chmod +x mkrepo.sh
49 |
50 | # make sure you are located in /repo
51 | cd /repo
52 | # create
53 | ./mkrepo.sh offline
54 | # dpkg-scanpackages: warning: Packages in archive but missing from override file:
55 | # dpkg-scanpackages: warning: adduser ca-certificates ca-certificates-java cdebconf coreutils debconf debianutils default-jre-headless default-mysql-client dpkg fontconfig-config fonts-dejavu fonts-dejavu-core fonts-dejavu-extra fonts-liberation fping gcc-10-base install-info iproute2 java-common libacl1 libaio1 libapparmor1 libargon2-1 libasn1-8-heimdal libasound2 libasound2-data libattr1 libaudit-common libaudit1 libavahi-client3 libavahi-common-data libavahi-common3 libblkid1 libbrotli1 libbsd0 libbz2-1.0 libc6 libcap-ng0 libcap2 libcap2-bin libcom-err2 libcrypt1 libcryptsetup12 libcups2 libcurl4 libdb5.3 libdbus-1-3 libdebian-installer4 libdevmapper1.02.1 libedit2 libelf1 libevent-2.1-7 libevent-core-2.1-7 libevent-pthreads-2.1-7 libexpat1 libffi7 libfontconfig1 libfreetype6 libgcc-s1 libgcrypt20 libgd3 libgdbm-compat4 libgdbm6 libgeoip1 libglib2.0-0 libgmp10 libgnutls30 libgpg-error0 libgraphite2-3 libgssapi-krb5-2 libgssapi3-heimdal libharfbuzz0b libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhiredis0.14 libhogweed5 libhx509-5-heimdal libicu66 libidn2-0 libip4tc2 libjbig0 libjpeg-turbo8 libjpeg8 libjson-c4 libk5crypto3 libkeyutils1 libkmod2 libkrb5-26-heimdal libkrb5-3 libkrb5support0 liblcms2-2 libldap-2.4-2 libldap-common libltdl7 libluajit-5.1-2 libluajit-5.1-common liblz4-1 liblzma5 libmagic-mgc libmagic1 libmaxminddb0 libmecab2 libmnl0 libmount1 libmysqlclient21 libnettle7 libnewt0.52 libnghttp2-14 libnginx-mod-http-auth-pam libnginx-mod-http-cache-purge libnginx-mod-http-dav-ext libnginx-mod-http-echo libnginx-mod-http-fancyindex libnginx-mod-http-geoip libnginx-mod-http-geoip2 libnginx-mod-http-headers-more-filter libnginx-mod-http-image-filter libnginx-mod-http-lua libnginx-mod-http-ndk libnginx-mod-http-perl libnginx-mod-http-subs-filter libnginx-mod-http-uploadprogress libnginx-mod-http-upstream-fair libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-nchan libnginx-mod-stream libnspr4 libnss3 libnuma1 libodbc1 libonig5 libopenipmi0 libp11-kit0 libpam-modules libpam-modules-bin libpam-runtime libpam0g libpci3 libpcre2-8-0 libpcre3 libpcsclite1 libperl5.30 libpng16-16 libpq5 libpsl5 libreadline8 libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules-db libseccomp2 libselinux1 libsemanage-common libsemanage1 libsensors-config libsensors5 libsepol1 libslang2 libsmartcols1 libsnmp-base libsnmp35 libsodium23 libsqlite3-0 libssh-4 libssl1.1 libstdc++6 libsystemd0 libtasn1-6 libtextwrap1 libtiff5 libtinfo6 libudev1 libunistring2 libuuid1 libwebp6 libwind0-heimdal libwrap0 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 libxslt1.1 libxtables12 libzstd1 login lsb-base mime-support mount mysql-client mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 netbase nginx nginx-common nginx-core nginx-extras nginx-full nginx-light openjdk-11-jre-headless openssl passwd pci.ids perl perl-base perl-modules-5.30 php-bcmath php-common php-fpm php-gd php-ldap php-mbstring php-mysql php-pgsql php-xml php7.4-bcmath php7.4-cli php7.4-common php7.4-fpm php7.4-gd php7.4-json php7.4-ldap php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml psmisc readline-common sed sensible-utils sqlite3 systemd systemd-timesyncd tar ttf-bitstream-vera ttf-dejavu-core tzdata ucf util-linux zabbix-agent zabbix-agent2 zabbix-frontend-php zabbix-get zabbix-java-gateway zabbix-js zabbix-nginx-conf zabbix-proxy-sqlite3 zabbix-sender zabbix-server-mysql zlib1g
56 | # dpkg-scanpackages: info: Wrote 261 entries to output Packages file.
57 |
58 | # create ISO file
59 | mkisofs -J -l -R -V "Zabbix" -iso-level 4 -o /tmp/zabbix-offline-install-ubuntu20.iso /repo/offline
60 | # size of iso will be ~135M
61 |
62 | # exit user '_apt'
63 | exit
64 |
65 | # use WinSCP and download '/tmp/zabbix-offline-install-ubuntu20.iso'
66 |
--------------------------------------------------------------------------------
/CentOS7/zabbix-partitioning.perl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use Data::Dumper;
5 | use DBI;
6 | use Sys::Syslog qw(:standard :macros);
7 | use DateTime;
8 | use POSIX qw(strftime);
9 |
10 | openlog("mysql_zbx_part", "ndelay,pid", LOG_LOCAL0);
11 |
12 | my $db_schema = 'zabbix';
13 | my $dsn = 'DBI:mysql:'.$db_schema.':mysql_socket=/var/lib/mysql/mysql.sock';
14 | my $db_user_name = 'zabbix_part';
15 | my $db_password = 'dwyQv5X3G6WwtYKg';
16 | my $tables = { 'history' => { 'period' => 'day', 'keep_history' => '30'},
17 | 'history_log' => { 'period' => 'day', 'keep_history' => '30'},
18 | 'history_str' => { 'period' => 'day', 'keep_history' => '30'},
19 | 'history_text' => { 'period' => 'day', 'keep_history' => '30'},
20 | 'history_uint' => { 'period' => 'day', 'keep_history' => '30'},
21 | 'trends' => { 'period' => 'month', 'keep_history' => '2'},
22 | 'trends_uint' => { 'period' => 'month', 'keep_history' => '2'}
23 | };
24 | my $amount_partitions = 10;
25 |
26 | my $curr_tz = 'Europe/London';
27 |
28 | my $part_tables;
29 |
30 | my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
31 |
32 | unless ( check_have_partition() ) {
33 | print "Your installation of MySQL does not support table partitioning.\n";
34 | syslog(LOG_CRIT, 'Your installation of MySQL does not support table partitioning.');
35 | exit 1;
36 | }
37 |
38 | my $sth = $dbh->prepare(qq{SELECT table_name, partition_name, lower(partition_method) as partition_method,
39 | rtrim(ltrim(partition_expression)) as partition_expression,
40 | partition_description, table_rows
41 | FROM information_schema.partitions
42 | WHERE partition_name IS NOT NULL AND table_schema = ?});
43 | $sth->execute($db_schema);
44 |
45 | while (my $row = $sth->fetchrow_hashref()) {
46 | $part_tables->{$row->{'table_name'}}->{$row->{'partition_name'}} = $row;
47 | }
48 |
49 | $sth->finish();
50 |
51 | foreach my $key (sort keys %{$tables}) {
52 | unless (defined($part_tables->{$key})) {
53 | syslog(LOG_ERR, 'Partitioning for "'.$key.'" is not found! The table might be not partitioned.');
54 | next;
55 | }
56 |
57 | create_next_partition($key, $part_tables->{$key}, $tables->{$key}->{'period'});
58 | remove_old_partitions($key, $part_tables->{$key}, $tables->{$key}->{'period'}, $tables->{$key}->{'keep_history'})
59 | }
60 |
61 | delete_old_data();
62 |
63 | $dbh->disconnect();
64 |
65 | sub check_have_partition {
66 | my $result = 0;
67 | # MySQL 5.5
68 | # my $sth = $dbh->prepare(qq{SELECT variable_value FROM information_schema.global_variables WHERE variable_name = 'have_partitioning'});
69 | # MySQL 5.6
70 | my $sth = $dbh->prepare(qq{SELECT plugin_status FROM information_schema.plugins WHERE plugin_name = 'partition'});
71 |
72 | $sth->execute();
73 |
74 | my $row = $sth->fetchrow_array();
75 |
76 | $sth->finish();
77 |
78 | # MySQL 5.5
79 | # return 1 if $row eq 'YES';
80 | # MySQL 5.6
81 | return 1 if $row eq 'ACTIVE';
82 | }
83 |
84 | sub create_next_partition {
85 | my $table_name = shift;
86 | my $table_part = shift;
87 | my $period = shift;
88 |
89 | for (my $curr_part = 0; $curr_part < $amount_partitions; $curr_part++) {
90 | my $next_name = name_next_part($tables->{$table_name}->{'period'}, $curr_part);
91 | my $found = 0;
92 |
93 | foreach my $partition (sort keys %{$table_part}) {
94 | if ($next_name eq $partition) {
95 | syslog(LOG_INFO, "Next partition for $table_name table has already been created. It is $next_name");
96 | $found = 1;
97 | }
98 | }
99 |
100 | if ( $found == 0 ) {
101 | syslog(LOG_INFO, "Creating a partition for $table_name table ($next_name)");
102 | my $query = 'ALTER TABLE '."$db_schema.$table_name".' ADD PARTITION (PARTITION '.$next_name.
103 | ' VALUES less than (UNIX_TIMESTAMP("'.date_next_part($tables->{$table_name}->{'period'}, $curr_part).'") div 1))';
104 | syslog(LOG_DEBUG, $query);
105 | $dbh->do($query);
106 | }
107 | }
108 | }
109 |
110 | sub remove_old_partitions {
111 | my $table_name = shift;
112 | my $table_part = shift;
113 | my $period = shift;
114 | my $keep_history = shift;
115 |
116 | my $curr_date = DateTime->now;
117 | $curr_date->set_time_zone( $curr_tz );
118 |
119 | if ( $period eq 'day' ) {
120 | $curr_date->add(days => -$keep_history);
121 | $curr_date->add(hours => -$curr_date->strftime('%H'));
122 | $curr_date->add(minutes => -$curr_date->strftime('%M'));
123 | $curr_date->add(seconds => -$curr_date->strftime('%S'));
124 | }
125 | elsif ( $period eq 'week' ) {
126 | }
127 | elsif ( $period eq 'month' ) {
128 | $curr_date->add(months => -$keep_history);
129 |
130 | $curr_date->add(days => -$curr_date->strftime('%d')+1);
131 | $curr_date->add(hours => -$curr_date->strftime('%H'));
132 | $curr_date->add(minutes => -$curr_date->strftime('%M'));
133 | $curr_date->add(seconds => -$curr_date->strftime('%S'));
134 | }
135 |
136 | foreach my $partition (sort keys %{$table_part}) {
137 | if ($table_part->{$partition}->{'partition_description'} <= $curr_date->epoch) {
138 | syslog(LOG_INFO, "Removing old $partition partition from $table_name table");
139 |
140 | my $query = "ALTER TABLE $db_schema.$table_name DROP PARTITION $partition";
141 |
142 | syslog(LOG_DEBUG, $query);
143 | $dbh->do($query);
144 | }
145 | }
146 | }
147 |
148 | sub name_next_part {
149 | my $period = shift;
150 | my $curr_part = shift;
151 |
152 | my $name_template;
153 |
154 | my $curr_date = DateTime->now;
155 | $curr_date->set_time_zone( $curr_tz );
156 |
157 | if ( $period eq 'day' ) {
158 | my $curr_date = $curr_date->truncate( to => 'day' );
159 | $curr_date->add(days => 1 + $curr_part);
160 |
161 | $name_template = $curr_date->strftime('p%Y_%m_%d');
162 | }
163 | elsif ($period eq 'week') {
164 | my $curr_date = $curr_date->truncate( to => 'week' );
165 | $curr_date->add(days => 7 * $curr_part);
166 |
167 | $name_template = $curr_date->strftime('p%Y_%m_w%W');
168 | }
169 | elsif ($period eq 'month') {
170 | my $curr_date = $curr_date->truncate( to => 'month' );
171 | $curr_date->add(months => 1 + $curr_part);
172 |
173 | $name_template = $curr_date->strftime('p%Y_%m');
174 | }
175 |
176 | return $name_template;
177 | }
178 |
179 | sub date_next_part {
180 | my $period = shift;
181 | my $curr_part = shift;
182 |
183 | my $period_date;
184 |
185 | my $curr_date = DateTime->now;
186 | $curr_date->set_time_zone( $curr_tz );
187 |
188 | if ( $period eq 'day' ) {
189 | my $curr_date = $curr_date->truncate( to => 'day' );
190 | $curr_date->add(days => 2 + $curr_part);
191 | $period_date = $curr_date->strftime('%Y-%m-%d');
192 | }
193 | elsif ($period eq 'week') {
194 | my $curr_date = $curr_date->truncate( to => 'week' );
195 | $curr_date->add(days => 7 * $curr_part + 1);
196 | $period_date = $curr_date->strftime('%Y-%m-%d');
197 | }
198 | elsif ($period eq 'month') {
199 | my $curr_date = $curr_date->truncate( to => 'month' );
200 | $curr_date->add(months => 2 + $curr_part);
201 |
202 | $period_date = $curr_date->strftime('%Y-%m-%d');
203 | }
204 |
205 | return $period_date;
206 | }
207 |
208 | sub delete_old_data {
209 | $dbh->do("DELETE FROM sessions WHERE lastaccess < UNIX_TIMESTAMP(NOW() - INTERVAL 1 MONTH)");
210 | $dbh->do("TRUNCATE housekeeper");
211 | $dbh->do("DELETE FROM auditlog_details WHERE NOT EXISTS (SELECT NULL FROM auditlog WHERE auditlog.auditid = auditlog_details.auditid)");
212 | }
213 |
214 |
--------------------------------------------------------------------------------
/HA/ubuntu-18.log.sh:
--------------------------------------------------------------------------------
1 |
2 | 10.1.10.5 node1
3 | 10.1.10.6 node2
4 |
5 | # execute on node 1
6 | sudo hostnamectl set-hostname node1
7 | echo 127.0.0.1 node1|sudo tee -a /etc/hosts
8 | echo 10.1.10.5 node1|sudo tee -a /etc/hosts
9 | echo 10.1.10.6 node2|sudo tee -a /etc/hosts
10 |
11 | # execute on node 2
12 | sudo hostnamectl set-hostname node2
13 | echo 127.0.0.1 node2|sudo tee -a /etc/hosts
14 | echo 10.1.10.5 node1|sudo tee -a /etc/hosts
15 | echo 10.1.10.6 node2|sudo tee -a /etc/hosts
16 |
17 | sudo apt -y update
18 | sudo apt -y upgrade
19 |
20 | sudo apt -y install ntp
21 | sudo systemctl enable ntp
22 | sudo systemctl start ntp
23 | sudo systemctl status ntp
24 |
25 | # install timezone
26 | sudo cp /usr/share/zoneinfo/Europe/Riga /etc/localtime
27 | # check date now
28 | sudo dpkg-reconfigure --frontend noninteractive tzdata
29 | date
30 |
31 |
32 | # https://downloads.mariadb.org/mariadb/repositories/#mirror=digitalocean-nyc&version=10.3
33 | sudo apt-get install software-properties-common
34 | sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
35 | sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main'
36 |
37 | sudo apt -y update
38 | sudo apt -y install mariadb-server mariadb-client
39 |
40 | # install tuning on node1
41 | systemctl stop mariadb
42 | systemctl status mariadb
43 |
44 | rm -rf /var/lib/mysql/ib_logfile*
45 |
46 | cd /etc/mysql/mariadb.conf.d
47 | cat << 'EOF' > server.cnf
48 | [mysqld]
49 | bind-address = 0.0.0.0
50 | user = mysql
51 | local_infile = 0
52 | symbolic_links = 0
53 |
54 | default-storage-engine = InnoDB
55 | skip-name-resolve
56 | key_buffer_size = 32M
57 | max_allowed_packet = 128M
58 | table_open_cache = 1024
59 | table_definition_cache = 1024
60 | max_connections = 2000
61 | join_buffer_size = 1M
62 | sort_buffer_size = 2M
63 | read_buffer_size = 256K
64 | read_rnd_buffer_size = 256K
65 | myisam_sort_buffer_size = 1M
66 | thread_cache_size = 512
67 | query_cache_type = 0
68 | open_files_limit = 65535
69 | wait_timeout = 86400
70 |
71 | optimizer_switch=index_condition_pushdown=off
72 |
73 | tmp_table_size = 64M
74 | max_heap_table_size = 64M
75 |
76 | binlog_format=mixed
77 | binlog_cache_size = 64M
78 | max_binlog_size = 1G
79 | expire_logs_days = 3
80 |
81 | innodb_buffer_pool_size = 512M
82 | innodb_log_file_size = 90M
83 | innodb_log_buffer_size = 128M
84 | innodb_file_per_table = 1
85 | innodb_flush_method = O_DIRECT
86 | innodb_buffer_pool_instances = 8
87 | innodb_write_io_threads = 8
88 | innodb_read_io_threads = 8
89 | innodb_adaptive_flushing = 1
90 | innodb_lock_wait_timeout = 50
91 |
92 | innodb_flush_log_at_trx_commit = 2
93 |
94 | innodb_io_capacity = 2000
95 | innodb_io_capacity_max = 2500
96 | innodb_flush_neighbors = 0
97 |
98 | innodb_checksums = 1
99 | innodb_doublewrite = 1
100 | innodb_thread_concurrency = 0
101 |
102 | innodb_purge_threads = 4
103 |
104 | large-pages
105 |
106 | gtid_domain_id = 1
107 | server_id = 1
108 | binlog_checksum = crc32
109 |
110 | innodb_lru_scan_depth = 512
111 |
112 | innodb_stats_on_metadata = 0
113 | innodb_stats_sample_pages = 32
114 | EOF
115 |
116 |
117 | systemctl start mariadb
118 | netstat -an | grep 3306
119 |
120 | mysql <<< 'show variables like "server_id";'
121 |
122 |
123 | # ============== ON NODE2 =============
124 |
125 | # install tuning on node2
126 | systemctl stop mariadb
127 | rm -rf /var/lib/mysql/ib_logfile*
128 |
129 | cd /etc/mysql/mariadb.conf.d
130 | cat << 'EOF' > server.cnf
131 | [mysqld]
132 | bind-address = 0.0.0.0
133 | user = mysql
134 | local_infile = 0
135 | symbolic_links = 0
136 |
137 | default-storage-engine = InnoDB
138 | skip-name-resolve
139 | key_buffer_size = 32M
140 | max_allowed_packet = 128M
141 | table_open_cache = 1024
142 | table_definition_cache = 1024
143 | max_connections = 2000
144 | join_buffer_size = 1M
145 | sort_buffer_size = 2M
146 | read_buffer_size = 256K
147 | read_rnd_buffer_size = 256K
148 | myisam_sort_buffer_size = 1M
149 | thread_cache_size = 512
150 | query_cache_type = 0
151 | open_files_limit = 65535
152 | wait_timeout = 86400
153 |
154 | optimizer_switch=index_condition_pushdown=off
155 |
156 | tmp_table_size = 64M
157 | max_heap_table_size = 64M
158 |
159 | binlog_format=mixed
160 | binlog_cache_size = 64M
161 | max_binlog_size = 1G
162 | expire_logs_days = 3
163 |
164 | innodb_buffer_pool_size = 512M
165 | innodb_log_file_size = 90M
166 | innodb_log_buffer_size = 128M
167 | innodb_file_per_table = 1
168 | innodb_flush_method = O_DIRECT
169 | innodb_buffer_pool_instances = 8
170 | innodb_write_io_threads = 8
171 | innodb_read_io_threads = 8
172 | innodb_adaptive_flushing = 1
173 | innodb_lock_wait_timeout = 50
174 |
175 | innodb_flush_log_at_trx_commit = 2
176 |
177 | innodb_io_capacity = 2000
178 | innodb_io_capacity_max = 2500
179 | innodb_flush_neighbors = 0
180 |
181 | innodb_checksums = 1
182 | innodb_doublewrite = 1
183 | innodb_thread_concurrency = 0
184 |
185 | innodb_purge_threads = 4
186 |
187 | large-pages
188 |
189 | gtid_domain_id = 1
190 | server_id = 2
191 | binlog_checksum = crc32
192 |
193 | innodb_lru_scan_depth = 512
194 |
195 | innodb_stats_on_metadata = 0
196 | innodb_stats_sample_pages = 32
197 | EOF
198 |
199 | systemctl start mariadb
200 | netstat -an | grep 3306
201 |
202 | mysql <<< 'show variables like "server_id";'
203 |
204 |
205 | # ==== ON NODE1 =======
206 |
207 | mysql <<< 'FLUSH TABLES WITH READ LOCK;'
208 |
209 | # create a backup of node1
210 | cd /home/vagrant
211 |
212 | mysqldump --master-data --gtid --all-databases > backup.sql
213 |
214 | # ==== ON NODE2 =======
215 | # try if node2 can connect to node1
216 | mysql -h 10.1.10.5 -P 3306 -ureplicator -preplicator
217 | # it should NOT work!
218 |
219 | # ==== ON NODE1 =======
220 | # run on node1. allow 10.1.10.6 to connect on 10.1.10.5
221 | mysql <<< 'GRANT REPLICATION SLAVE ON *.* TO "replicator"@"10.1.10.6" identified by "replicator"; GRANT REPLICATION SLAVE ON *.* TO "replicator"@"node2" identified by "replicator"; FLUSH PRIVILEGES;'
222 |
223 | # ==== ON NODE2 =======
224 | # try if node2 can connect to node1
225 | mysql -h 10.1.10.5 -P 3306 -ureplicator -preplicator
226 |
227 | # ==== ON NODE2 =======
228 | # Recover MySQL dump to the slave MySQL server
229 | cd /home/vagrant
230 | cat backup.sql | mysql
231 |
232 | # ==== ON NODE2 =======
233 | mysql <<< 'show slave status\G;'
234 | mysql <<< 'STOP SLAVE;'
235 | mysql <<< 'CHANGE MASTER TO master_host="10.1.10.5", master_port=3306, master_user="replicator", master_password="replicator", master_use_gtid=slave_pos;'
236 | mysql <<< 'START SLAVE;'
237 | mysql <<< 'show slave status\G;'
238 |
239 | # ==== ON NODE1 =======
240 | # try if node1 can connect to node2
241 | mysql -h 10.1.10.6 -P 3306 -ureplicator -preplicator
242 | # it should NOT work
243 |
244 | # ==== ON NODE2 =======
245 | # run on node2. allow 10.1.10.5 to connect on 10.1.10.6
246 | mysql <<< 'GRANT REPLICATION SLAVE ON *.* TO "replicator"@"10.1.10.5" identified by "replicator"; GRANT REPLICATION SLAVE ON *.* TO "replicator"@"node1" identified by "replicator"; FLUSH PRIVILEGES;'
247 |
248 | # ==== ON NODE1 =======
249 | mysql <<< 'show slave status\G;'
250 | mysql <<< 'STOP SLAVE;'
251 | mysql <<< 'CHANGE MASTER TO master_host="10.1.10.6", master_port=3306, master_user="replicator", master_password="replicator", master_use_gtid=slave_pos;'
252 | mysql <<< 'start slave;'
253 | mysql <<< 'show slave status\G;'
254 | mysql <<< 'UNLOCK TABLES;'
255 |
256 |
257 |
258 |
259 |
260 |
261 |
--------------------------------------------------------------------------------
/zabbix50ol8.sh:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | systemctl stop zabbix-server zabbix-proxy zabbix-agent2 nginx php-fpm zabbix-agent snmptrapd zabbix-java-gateway
5 | sudo swapoff --all
6 |
7 |
8 | # Add 4GB of swap space and never check if enough memory is available
9 | sudo dd if=/dev/zero of=/myswap1 bs=1M count=1024 && sudo chown root:root /myswap1 && sudo chmod 0600 /myswap1 && sudo mkswap /myswap1 && sudo swapon /myswap1 && free -m && sudo dd if=/dev/zero of=/myswap2 bs=1M count=1024 && sudo chown root:root /myswap2 && sudo chmod 0600 /myswap2 && sudo mkswap /myswap2 && sudo swapon /myswap2 && free -m && sudo dd if=/dev/zero of=/myswap3 bs=1M count=1024 && sudo chown root:root /myswap3 && sudo chmod 0600 /myswap3 && sudo mkswap /myswap3 && sudo swapon /myswap3 && free -m && sudo dd if=/dev/zero of=/myswap4 bs=1M count=1024 && sudo chown root:root /myswap4 && sudo chmod 0600 /myswap4 && sudo mkswap /myswap4 && sudo swapon /myswap4 && free -m && echo 1 | sudo tee /proc/sys/vm/overcommit_memory
10 | setenforce 0
11 |
12 | timedatectl set-timezone Europe/Riga
13 |
14 | rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
15 | rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
16 | # Install the repository RPM:
17 | sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
18 |
19 | curl https://packages.microsoft.com/config/rhel/8/prod.repo -o /etc/yum.repos.d/mssql-release.repo
20 |
21 | dnf remove unixODBC-utf16 unixODBC-utf16-devel
22 | ACCEPT_EULA=Y dnf install -y msodbcsql18 mssql-tools18
23 |
24 | echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
25 | source ~/.bashrc
26 |
27 |
28 |
29 |
30 |
31 | # Disable the built-in PostgreSQL module:
32 | sudo dnf -qy module disable postgresql
33 | dnf -y install epel-release
34 |
35 |
36 | dnf clean all
37 |
38 | dnf -y install vim git \
39 | zabbix-server-mysql \
40 | zabbix-proxy-sqlite3 \
41 | zabbix-java-gateway \
42 | zabbix-web-mysql \
43 | zabbix-nginx-conf \
44 | zabbix-agent \
45 | zabbix-agent2 \
46 | zabbix-get \
47 | zabbix-js \
48 | zabbix-sender \
49 | postgresql13 \
50 | python3 \
51 | python3-pip \
52 | openldap-clients \
53 | net-snmp-utils \
54 | net-snmp-perl \
55 | certbot \
56 | net-snmp \
57 | mysql \
58 | screen \
59 | jq \
60 | tree \
61 | autoconf automake git pkgconf gcc \
62 | libaio \
63 | docker \
64 | libnsl \
65 | mysql-connector-odbc \
66 | postgresql-odbc \
67 | unzip
68 |
69 | rpm -ivh oracle-instantclient19.15-basic-19.15.0.0.0-1.x86_64.rpm \
70 | oracle-instantclient19.15-basiclite-19.15.0.0.0-1.x86_64.rpm \
71 | oracle-instantclient19.15-odbc-19.15.0.0.0-1.x86_64.rpm
72 |
73 | rpm -ivh https://download.oracle.com/otn_software/linux/instantclient/1915000/oracle-instantclient19.15-basiclite-19.15.0.0.0-1.x86_64.rpm
74 |
75 |
76 |
77 |
78 |
79 | vim /etc/selinux/config
80 | setenforce 0
81 |
82 | systemctl stop zabbix-server zabbix-proxy zabbix-agent zabbix-agent2 nginx php-fpm snmptrapd zabbix-java-gateway
83 | # reconfigure components
84 | cat /root/backup/etc/zabbix/zabbix_agentd.conf > /etc/zabbix/zabbix_agentd.conf
85 | cat /root/backup/etc/zabbix/zabbix_agent2.conf > /etc/zabbix/zabbix_agent2.conf
86 | cat /root/backup/etc/zabbix/zabbix_server.conf > /etc/zabbix/zabbix_server.conf
87 | cat /root/backup/etc/zabbix/zabbix_proxy.conf > /etc/zabbix/zabbix_proxy.conf
88 | cat /root/backup/etc/zabbix/zabbix_java_gateway.conf > /etc/zabbix/zabbix_java_gateway.conf
89 |
90 | # repair php-fpm
91 | cat /root/backup/etc/php-fpm.d/zabbix.conf > /etc/php-fpm.d/zabbix.conf
92 | cat /root/backup/etc/php-fpm.d/www.conf > /etc/php-fpm.d/www.conf
93 |
94 | cp /root/backup/etc/zabbix/web/zabbix.conf.php /etc/zabbix/web
95 | chown apache. /etc/zabbix/web/zabbix.conf.php
96 |
97 | # install old modules
98 | cd /root/backup/usr/share/zabbix/modules && cp -r * /usr/share/zabbix/modules
99 |
100 |
101 | # repair nginx
102 | cd /root/backup/etc/nginx/conf.d
103 | cat /root/backup/etc/nginx/conf.d/php-fpm.conf > /etc/nginx/conf.d/php-fpm.conf
104 | cat /root/backup/etc/nginx/conf.d/zabbix.conf > /etc/nginx/conf.d/zabbix.conf
105 | cat /root/backup/etc/nginx/conf.d/https.zbx.aigarskadikis.com.443.conf > /etc/nginx/conf.d/https.zbx.aigarskadikis.com.443.conf
106 | mkdir -p /etc/letsencrypt/live/zbx.aigarskadikis.com /etc/letsencrypt/archive/zbx.aigarskadikis.com
107 | cd /root/backup/etc/letsencrypt/archive/zbx.aigarskadikis.com && cp * /etc/letsencrypt/archive/zbx.aigarskadikis.com
108 |
109 | cd /root/backup/etc/letsencrypt/live/zbx.aigarskadikis.com && ls -l
110 |
111 | # link back currect certificate
112 | ln -s /etc/letsencrypt/archive/zbx.aigarskadikis.com/cert4.pem /etc/letsencrypt/live/zbx.aigarskadikis.com/cert.pem
113 | ln -s /etc/letsencrypt/archive/zbx.aigarskadikis.com/chain4.pem /etc/letsencrypt/live/zbx.aigarskadikis.com/chain.pem
114 | ln -s /etc/letsencrypt/archive/zbx.aigarskadikis.com/fullchain4.pem /etc/letsencrypt/live/zbx.aigarskadikis.com/fullchain.pem
115 | ln -s /etc/letsencrypt/archive/zbx.aigarskadikis.com/privkey4.pem /etc/letsencrypt/live/zbx.aigarskadikis.com/privkey.pem
116 |
117 | nginx -t
118 |
119 |
120 |
121 | cat /root/backup/etc/snmp/snmptrapd.conf > /etc/snmp/snmptrapd.conf
122 | cat /root/backup/etc/zabbix/zabbix_java_gateway.conf > /etc/zabbix/zabbix_java_gateway.conf
123 |
124 |
125 | cd /root/backup/var/lib/zabbix/.ssh
126 | mkdir -p /var/lib/zabbix/.ssh
127 | mv * /var/lib/zabbix/.ssh
128 | chown -R zabbix. /var/lib/zabbix
129 |
130 |
131 | systemctl enable --now zabbix-server zabbix-proxy zabbix-agent zabbix-agent2 nginx php-fpm snmptrapd zabbix-java-gateway
132 | systemctl enable zabbix-server zabbix-proxy zabbix-agent zabbix-agent2 nginx php-fpm snmptrapd zabbix-java-gateway
133 |
134 | # disabled/optional services
135 | systemctl disable snmpd
136 |
137 | curl https://rclone.org/install.sh | sudo bash
138 | cd /root/backup/root/.config/rclone
139 | mkdir -p /root/.config/rclone
140 | cp rclone.conf /root/.config/rclone
141 |
142 |
143 | # register git ssh key
144 | ssh-keygen -t rsa -b 4096 -C "aigars.kadikis@gmail.com"
145 | cat ~/.ssh/id_rsa.pub
146 | enter key at https://github.com/settings/keys
147 |
148 | cd /root/backup/root/.ssh
149 | mv * /root/.ssh
150 |
151 | cat /root/backup/etc/profile.d/postgres.sh > /etc/profile.d/postgres.sh
152 |
153 | cat /root/backup/etc/sysctl.d/97-zabbix-web-server.conf > /etc/sysctl.d/97-zabbix-web-server.conf
154 | cat /root/backup/etc/sysctl.d/98-zabbix.conf > /etc/sysctl.d/98-zabbix.conf
155 | sysctl --system
156 |
157 | mv /root/backup/etc/cron.d/* /etc/cron.d
158 |
159 | mv /root/backup/root/.gitconfig ~
160 | mv /root/backup/root/.my.cnf ~
161 | mv /root/backup/root/.pgpass ~
162 |
163 | cd /usr/lib/zabbix && rm -rf alertscripts externalscripts
164 |
165 | cd /root/backup/usr/lib/zabbix && mv * /usr/lib/zabbix
166 | mv .git /usr/lib/zabbix
167 | mv .gitattributes /usr/lib/zabbix
168 |
169 | cd /root/backup/usr/local/bin && mv * /usr/local/bin
170 | cd /root/backup/etc/ssh/ssh_config.d && mv * /etc/ssh/ssh_config.d
171 |
172 | cat /root/backup/etc/hosts > /etc/hosts
173 |
174 |
175 | cd /usr/lib/oracle/19.15/client64/bin
176 |
177 | ./odbc_update_ini.sh / /usr/lib/oracle/19.15/client64/bin
178 |
179 |
180 | cd /root/backup/etc/zabbix && mv backup_zabbix_* /etc/zabbix/
181 |
182 | cd /etc/sudoers.d
183 | echo 'zabbix ALL=(ALL) NOPASSWD: /usr/sbin/zabbix_proxy -R config_cache_reload' | sudo tee zabbix_proxy_config_cache_reload
184 | chmod 0440 zabbix_proxy_config_cache_reload
185 |
186 | cd /etc/sudoers.d
187 | echo 'zabbix ALL=(ALL) NOPASSWD: /usr/sbin/zabbix_server -R config_cache_reload' | sudo tee zabbix_server_config_cache_reload
188 | chmod 0440 zabbix_server_config_cache_reload
189 |
190 |
191 |
192 |
--------------------------------------------------------------------------------
/CentOS7/trap-receiver-centos-7-proxy.sh:
--------------------------------------------------------------------------------
1 | #Open SNMP trap listener port 162 in firewall:
2 | firewall-cmd --add-port=162/udp --permanent
3 | firewall-cmd --reload
4 |
5 | #Turn off selinux [optional]:
6 | getenforce
7 | grep "^SELINUX=" /etc/selinux/config
8 | sed -i "s/^SELINUX=.*$/SELINUX=disabled/" /etc/selinux/config
9 | setenforce 0
10 |
11 | #Install SNMP trap listener:
12 | yum -y install net-snmp-utils net-snmp-perl net-snmp nmap
13 |
14 | # Enable and strart the service:
15 | systemctl enable snmptrapd
16 | systemctl start snmptrapd
17 | systemctl status snmptrapd
18 |
19 | # Install 'netstat' command:
20 | yum -y install net-tools
21 |
22 | # Check the listening ports:
23 | netstat -tulpn | grep 162
24 |
25 | # Install "zabbix_trap_receiver.pl":
26 | echo "IyEvdXNyL2Jpbi9wZXJsCgojCiMgWmFiYml4CiMgQ29weXJpZ2h0IChDKSAyMDAxLTIwMTggWmFiYml4IFNJQQojCiMgVGhpcyBwcm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkKIyBpdCB1bmRlciB0aGUgdGVybXMgb2YgdGhlIEdOVSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlIGFzIHB1Ymxpc2hlZCBieQojIHRoZSBGcmVlIFNvZnR3YXJlIEZvdW5kYXRpb247IGVpdGhlciB2ZXJzaW9uIDIgb2YgdGhlIExpY2Vuc2UsIG9yCiMgKGF0IHlvdXIgb3B0aW9uKSBhbnkgbGF0ZXIgdmVyc2lvbi4KIwojIFRoaXMgcHJvZ3JhbSBpcyBkaXN0cmlidXRlZCBpbiB0aGUgaG9wZSB0aGF0IGl0IHdpbGwgYmUgdXNlZnVsLAojIGJ1dCBXSVRIT1VUIEFOWSBXQVJSQU5UWTsgd2l0aG91dCBldmVuIHRoZSBpbXBsaWVkIHdhcnJhbnR5IG9mCiMgTUVSQ0hBTlRBQklMSVRZIG9yIEZJVE5FU1MgRk9SIEEgUEFSVElDVUxBUiBQVVJQT1NFLiBTZWUgdGhlCiMgR05VIEdlbmVyYWwgUHVibGljIExpY2Vuc2UgZm9yIG1vcmUgZGV0YWlscy4KIwojIFlvdSBzaG91bGQgaGF2ZSByZWNlaXZlZCBhIGNvcHkgb2YgdGhlIEdOVSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlCiMgYWxvbmcgd2l0aCB0aGlzIHByb2dyYW07IGlmIG5vdCwgd3JpdGUgdG8gdGhlIEZyZWUgU29mdHdhcmUKIyBGb3VuZGF0aW9uLCBJbmMuLCA1MSBGcmFua2xpbiBTdHJlZXQsIEZpZnRoIEZsb29yLCBCb3N0b24sIE1BICAwMjExMC0xMzAxLCBVU0EuCiMKCiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCiMjIyMgQUJPVVQgWkFCQklYIFNOTVAgVFJBUCBSRUNFSVZFUiAjIyMjCiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCgojIFRoaXMgaXMgYW4gZW1iZWRkZWQgcGVybCBTTk1QIHRyYXBwZXIgcmVjZWl2ZXIgZGVzaWduZWQgZm9yIHNlbmRpbmcgZGF0YSB0byB0aGUgc2VydmVyLgojIFRoZSByZWNlaXZlciB3aWxsIHBhc3MgdGhlIHJlY2VpdmVkIFNOTVAgdHJhcHMgdG8gWmFiYml4IHNlcnZlciBvciBwcm94eSBydW5uaW5nIG9uIHRoZQojIHNhbWUgbWFjaGluZS4gUGxlYXNlIGNvbmZpZ3VyZSB0aGUgc2VydmVyL3Byb3h5IGFjY29yZGluZ2x5LgojCiMgUmVhZCBtb3JlIGFib3V0IHVzaW5nIGVtYmVkZGVkIHBlcmwgd2l0aCBOZXQtU05NUDoKIwlodHRwOi8vbmV0LXNubXAuc291cmNlZm9yZ2UubmV0L3dpa2kvaW5kZXgucGhwL1R1dDpFeHRlbmRpbmdfc25tcGRfdXNpbmdfcGVybAoKIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIwojIyMjIFpBQkJJWCBTTk1QIFRSQVAgUkVDRUlWRVIgQ09ORklHVVJBVElPTiAjIyMjCiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKCiMjIyBPcHRpb246IFNOTVBUcmFwcGVyRmlsZQojCVRlbXBvcmFyeSBmaWxlIHVzZWQgZm9yIHBhc3NpbmcgZGF0YSB0byB0aGUgc2VydmVyIChvciBwcm94eSkuIE11c3QgYmUgdGhlIHNhbWUKIwlhcyBpbiB0aGUgc2VydmVyIChvciBwcm94eSkgY29uZmlndXJhdGlvbiBmaWxlLgojCiMgTWFuZGF0b3J5OiB5ZXMKIyBEZWZhdWx0OgokU05NUFRyYXBwZXJGaWxlID0gJy90bXAvemFiYml4X3RyYXBzLnRtcCc7CgojIyMgT3B0aW9uOiBEYXRlVGltZUZvcm1hdAojCVRoZSBkYXRlIHRpbWUgZm9ybWF0IGluIHN0cmZ0aW1lKCkgZm9ybWF0LiBQbGVhc2UgbWFrZSBzdXJlIHRvIGhhdmUgYSBjb3JyZXNwb25kaW5nCiMJbG9nIHRpbWUgZm9ybWF0IGZvciB0aGUgU05NUCB0cmFwIGl0ZW1zLgojCiMgTWFuZGF0b3J5OiB5ZXMKIyBEZWZhdWx0OgokRGF0ZVRpbWVGb3JtYXQgPSAnJUg6JU06JVMgJVkvJW0vJWQnOwoKIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKIyMjIyBaQUJCSVggU05NUCBUUkFQIFJFQ0VJVkVSICMjIyMKIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKCnVzZSBGY250bCBxdyhPX1dST05MWSBPX0FQUEVORCBPX0NSRUFUKTsKdXNlIFBPU0lYIHF3KHN0cmZ0aW1lKTsKCnN1YiB6YWJiaXhfcmVjZWl2ZXIKewoJbXkgKCVwZHVfaW5mbykgPSAleyRfWzBdfTsKCW15IChAdmFyYmluZHMpID0gQHskX1sxXX07CgoJIyBvcGVuIHRoZSBvdXRwdXQgZmlsZQoJdW5sZXNzIChzeXNvcGVuKE9VVFBVVF9GSUxFLCAkU05NUFRyYXBwZXJGaWxlLCBPX1dST05MWXxPX0FQUEVORHxPX0NSRUFULCAwNjY2KSkKCXsKCQlwcmludCBTVERFUlIgIkNhbm5vdCBvcGVuIFskU05NUFRyYXBwZXJGaWxlXTogJCFcbiI7CgkJcmV0dXJuIE5FVFNOTVBUUkFQRF9IQU5ETEVSX0ZBSUw7Cgl9CgoJIyBnZXQgdGhlIGhvc3QgbmFtZQoJbXkgJGhvc3RuYW1lID0gJHBkdV9pbmZveydyZWNlaXZlZGZyb20nfSB8fCAndW5rbm93bic7CglpZiAoJGhvc3RuYW1lIG5lICd1bmtub3duJykKCXsKCQkkaG9zdG5hbWUgPX4gL1xbKC4qPylcXS4qLzsgICAgICAgICAgICAgICAgICAgICMgZm9ybWF0OiAiVURQOiBbMTI3LjAuMC4xXTo0MTA3MC0+WzEyNy4wLjAuMV0iCgkJJGhvc3RuYW1lID0gJDEgfHwgJ3Vua25vd24nOwoJfQoKCSMgcHJpbnQgdHJhcCBoZWFkZXIKCSMgICAgICAgdGltZXN0YW1wIG11c3QgYmUgcGxhY2VkIGF0IHRoZSBiZWdnaW5pbmcgb2YgdGhlIGZpcnN0IGxpbmUgKGNhbiBiZSBvbWl0dGVkKQoJIyAgICAgICB0aGUgZmlyc3QgbGluZSBtdXN0IGluY2x1ZGUgdGhlIGhlYWRlciAiWkJYVFJBUCBbSVAvRE5TIGFkZHJlc3NdICIKCSMgICAgICAgICAgICAgICogSVAvRE5TIGFkZHJlc3MgaXMgdGhlIHVzZWQgdG8gZmluZCB0aGUgY29ycmVzcG9uZGluZyBTTk1QIHRyYXAgaXRlbXMKCSMgICAgICAgICAgICAgICogdGhpcyBoZWFkZXIgd2lsbCBiZSBjdXQgZHVyaW5nIHByb2Nlc3NpbmcgKHdpbGwgbm90IGFwcGVhciBpbiB0aGUgaXRlbSB2YWx1ZSkKCXByaW50ZiBPVVRQVVRfRklMRSAiJXMgWkJYVFJBUCAlc1xuIiwgc3RyZnRpbWUoJERhdGVUaW1lRm9ybWF0LCBsb2NhbHRpbWUpLCAkaG9zdG5hbWU7CgoJIyBwcmludCB0aGUgUERVIGluZm8KCXByaW50IE9VVFBVVF9GSUxFICJQRFUgSU5GTzpcbiI7Cglmb3JlYWNoIG15ICRrZXkoa2V5cyglcGR1X2luZm8pKQoJewoJCWlmICgkcGR1X2luZm97JGtleX0gIX4gL15bWzpwcmludDpdXSokLykKCQl7CgkJCW15ICRPY3RldEFzSGV4ID0gdW5wYWNrKCdIKicsICRwZHVfaW5mb3ska2V5fSk7CSMgY29udmVydCBvY3RldCBzdHJpbmcgdG8gaGV4CgkJCSRwZHVfaW5mb3ska2V5fSA9ICIweCRPY3RldEFzSGV4IjsJCSMgYXBwbHkgMHggcHJlZml4IGZvciBjb25zaXN0ZW5jeQoJCX0KCgkJcHJpbnRmIE9VVFBVVF9GSUxFICIgICUtMzBzICVzXG4iLCAka2V5LCAkcGR1X2luZm97JGtleX07Cgl9CgoJIyBwcmludCB0aGUgdmFyaWFibGUgYmluZGluZ3M6CglwcmludCBPVVRQVVRfRklMRSAiVkFSQklORFM6XG4iOwoJZm9yZWFjaCBteSAkeCAoQHZhcmJpbmRzKQoJewoJCXByaW50ZiBPVVRQVVRfRklMRSAiICAlLTMwcyB0eXBlPSUtMmQgdmFsdWU9JXNcbiIsICR4LT5bMF0sICR4LT5bMl0sICR4LT5bMV07Cgl9CgoJY2xvc2UgKE9VVFBVVF9GSUxFKTsKCglyZXR1cm4gTkVUU05NUFRSQVBEX0hBTkRMRVJfT0s7Cn0KCk5ldFNOTVA6OlRyYXBSZWNlaXZlcjo6cmVnaXN0ZXIoImFsbCIsIFwmemFiYml4X3JlY2VpdmVyKSBvcgoJZGllICJmYWlsZWQgdG8gcmVnaXN0ZXIgWmFiYml4IFNOTVAgdHJhcCByZWNlaXZlclxuIjsKCnByaW50IFNURE9VVCAiTG9hZGVkIFphYmJpeCBTTk1QIHRyYXAgcmVjZWl2ZXJcbiI7Cg==" | base64 --decode > /usr/bin/zabbix_trap_receiver.pl
27 | chmod +x /usr/bin/zabbix_trap_receiver.pl
28 | cp /etc/snmp/{snmptrapd.conf,snmptrapd.conf.`date +%Y%m%d%H%M`}
29 | ls -l /etc/snmp/snmptrapd.conf*
30 | echo "authCommunity execute public"> /etc/snmp/snmptrapd.conf
31 | echo "perl do \"/usr/bin/zabbix_trap_receiver.pl\";">> /etc/snmp/snmptrapd.conf
32 | cat /etc/snmp/snmptrapd.conf
33 | grep "zabbix_traps.tmp" /usr/bin/zabbix_trap_receiver.pl
34 |
35 | # print proxy conf
36 | grep -v "^$\|#" /etc/zabbix/zabbix_proxy.conf
37 |
38 | # Restart SNMP trap daemon:
39 | systemctl restart snmptrapd
40 | systemctl status snmptrapd
41 |
42 | # Enable Zabbix Trapper in "zabbix_proxy.conf":
43 | conf=$(find / -name "zabbix_proxy.conf" | grep "/etc/")
44 | echo $conf
45 | cp $conf $conf.`date +%Y%m%d%H%M`
46 | ls -l $conf*
47 | sed -i "s|^.*StartSNMPTrapper=.*$|StartSNMPTrapper=1|" $conf
48 | sed -i "s|^SNMPTrapperFile=.*$|SNMPTrapperFile=\/tmp\/zabbix_traps.tmp|" $conf
49 | grep -v "^$\|^#" $conf
50 |
51 | # Restart Zabbix Server:
52 | systemctl restart zabbix-proxy
53 |
54 | # Check if there is any listener:
55 | ps -aux | grep [s]nmp
56 |
57 | # restart services
58 | systemctl restart snmptrapd
59 | systemctl restart zabbix-proxy
60 |
61 | # Check if services are up and running:
62 | systemctl status {snmptrapd,zabbix-proxy}
63 |
64 | # Ckeck if proxy trapper process is started:
65 | grep "snmp trapper" /var/log/zabbix/zabbix_proxy.log
66 |
67 | # Send a test trap:
68 | ls -l /tmp # note down the /tmp/zabbix_traps.tmp do not exist
69 |
70 | # send test trap
71 | snmptrap -v 1 -c public 127.0.0.1 '.1.3.6.1.6.3.1.1.5.4' '0.0.0.0' 6 33 '55' .1.3.6.1.6.3.1.1.5.4 s "eth0"
72 |
73 | # now the file must exist
74 | ls -l /tmp/zabbix_traps.tmp
75 |
76 | # note the permissions that 'others' can access this file
77 |
78 | snmptrap -v 1 -c public 127.0.0.1 '1.2.3.4.5.6' '192.193.194.195' 6 99 '55' 1.11.12.13.14.15 s "teststring"
79 |
80 | # After this command there should be instant content into:
81 | cat /tmp/zabbix_traps.tmp
82 |
83 | # Also the zabbix server log should contain this trap:
84 | cat /var/log/zabbix/zabbix_proxy.log
85 |
86 | # create [snmptrap.fallback]on the same proxy
87 |
88 | grep denied /var/log/audit/audit.log
89 | setenforce 0
90 |
91 |
--------------------------------------------------------------------------------
/mysql2postgres.rh8.sh:
--------------------------------------------------------------------------------
1 | # https://www.postgresql.org/download/linux/redhat/
2 | # https://pgloader.readthedocs.io/en/latest/
3 | # https://centos.pkgs.org/8/raven-x86_64/pgloader-3.6.2-1.el8.x86_64.rpm.html
4 | # https://docs.timescale.com/latest/getting-started/installation/rhel-centos/installation-yum
5 |
6 | # before creating a mysql dump for data dir, dissable actions because "nodata()" triggers may fire up after launching postgres database.
7 | # before making dump make sure there are no "query failed" messages in:
8 | grep "query failed" /var/log/zabbix/zabbix_server.log
9 |
10 |
11 | # Install PostgreSQL repository RPM:
12 | dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
13 |
14 | # Disable built-in PostgreSQL module:
15 | dnf -qy module disable postgresql
16 |
17 |
18 | # Install TimescaleDB repo
19 | sudo tee /etc/yum.repos.d/timescale_timescaledb.repo <> /var/lib/pgsql/12/data/postgresql.conf
51 |
52 | # observe current listening address
53 | grep listen_addresses /var/lib/pgsql/12/data/postgresql.conf
54 |
55 | # initialize database and enable automatic start:
56 | /usr/pgsql-12/bin/postgresql-12-setup initdb
57 | systemctl enable postgresql-12
58 | systemctl start postgresql-12
59 |
60 | # create new postgres database user 'zabbix', password will be prompted
61 | sudo -u postgres createuser --pwprompt zabbix
62 | sudo -u postgres createdb -O zabbix zabbix
63 |
64 | # a dependency for pgloader
65 | dnf -y install openssl-devel
66 |
67 | # install pgloader
68 | rpm -ivh https://pkgs.dyn.su/el8/base/x86_64/pgloader-3.6.2-1.el8.x86_64.rpm
69 |
70 | # download 5.0 source
71 | cd && curl -s "https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.5.tar.gz" -o zabbix-source.tar.gz && ls -lh zabbix-source.tar.gz
72 |
73 | # unpack archive
74 | gunzip zabbix-source.tar.gz && tar xvf zabbix-source.tar
75 |
76 | # for the migration we must configure to allow inserting data in postgres database without respecting contraints
77 | cd ~/zabbix-5.0.5/database/postgresql
78 | sed -n '/CREATE.*/,/INSERT.*$/p' schema.sql | head -n-1 > ~/create.sql
79 | grep ALTER schema.sql > ~/alter.sql
80 |
81 | # create pgloader migration profile. if password contains '@' then must type '@@'
82 | # if source database is different than 'zabbix_server' its required to change in two places:
83 | # 'from mysql..' and 'alter schema..'
84 | cd
85 | cat << 'EOF' > pgloader.conf
86 | LOAD DATABASE
87 | FROM mysql://root:XXXXXX@localhost:3306/zabbix_server
88 | INTO postgresql://zabbix:zabbix@127.0.0.1:5432/zabbix_server
89 | WITH include no drop,
90 | truncate,
91 | create no tables,
92 | create no indexes,
93 | no foreign keys,
94 | reset sequences,
95 | data only
96 | SET maintenance_work_mem TO '1024MB', work_mem to '256MB'
97 | ALTER SCHEMA 'zabbix_server' RENAME TO 'public'
98 | BEFORE LOAD EXECUTE create.sql
99 | AFTER LOAD EXECUTE alter.sql;
100 | EOF
101 |
102 | # using the username in pgloader.conf try to query some content:
103 | mysql -u'' -p'' zabbix_server
104 | select count(*) from items;
105 |
106 | # list size of biggest tables
107 | SELECT table_name,
108 | table_rows,
109 | data_length,
110 | index_length,
111 | round(((data_length + index_length) / 1024 / 1024 / 1024),2) "Size in GB"
112 | FROM information_schema.tables
113 | WHERE table_schema = "zabbix_server"
114 | ORDER BY round(((data_length + index_length) / 1024 / 1024 / 1024),2) DESC
115 | LIMIT 20;
116 |
117 |
118 | # test dry run
119 | pgloader --dry-run pgloader.conf
120 | # by default it generates information on screen and plus writes a log file '/tmp/pgloader/pgloader.log'
121 |
122 | # a successfull output looks like. 'Success' in 2 places:
123 | # pgloader --dry-run pgloader.conf
124 | # 2020-10-01T18:59:51.016000+06:00 LOG pgloader version "3.6.2"
125 | # 2020-10-01T18:59:51.081000+06:00 LOG DRY RUN, only checking connections.
126 | # 2020-10-01T18:59:51.082000+06:00 LOG Attempting to connect to #
127 | # 2020-10-01T18:59:51.158000+06:00 LOG Success, opened #.
128 | # 2020-10-01T18:59:51.159000+06:00 LOG Running a simple query: SELECT 1;
129 | # 2020-10-01T18:59:51.172000+06:00 LOG Attempting to connect to #
130 | # 2020-10-01T18:59:51.226000+06:00 LOG Success, opened #.
131 | # 2020-10-01T18:59:51.226000+06:00 LOG Running a simple query: SELECT 1;
132 | # 2020-10-01T18:59:51.229000+06:00 LOG report summary reset
133 | # table name errors rows bytes total time
134 | # ----------------- --------- --------- --------- --------------
135 | # ----------------- --------- --------- --------- --------------
136 |
137 | # install screens utility
138 | dnf install epel-release && dnf install screen
139 |
140 | # enter 'screen' mode
141 | screen
142 |
143 |
144 |
145 | sudo -u postgres dropdb zabbix_server
146 | sudo -u postgres createdb -O zabbix zabbix_server
147 |
148 |
149 | # clear log file from previous errors
150 | > /tmp/pgloader/pgloader.log
151 |
152 | # execute migration
153 | pgloader pgloader.conf
154 | # by default it writes a log file at '/tmp/pgloader/pgloader.log'
155 |
156 |
157 | 2020-10-29T16:03:25.012000+06:00 LOG pgloader version "3.6.2"
158 | 2020-10-29T16:03:26.693000+06:00 LOG Migrating from #
159 | 2020-10-29T16:03:26.693000+06:00 LOG Migrating into #
160 | KABOOM!
161 | FATAL error: pgloader failed to find schema "zabbix_server" in target catalog.
162 | An unhandled error condition has been signalled:
163 | pgloader failed to find schema "zabbix_server" in target catalog.
164 |
165 |
166 |
167 |
168 | What I am doing here?
169 |
170 | pgloader failed to find schema "zabbix_server" in target catalog.
171 |
172 |
173 |
174 | tail -99f /tmp/pgloader/pgloader.log
175 |
176 |
177 | grep WARNING /tmp/pgloader/pgloader.log
178 | grep ERROR /tmp/pgloader/pgloader.log
179 |
180 |
181 | # install additional package on frontend server
182 | yum install zabbix-web-pgsql
183 | # reload web server
184 | # enter setup.php to observe if web server understood postgres sql library
185 | # make an extra backup of /etc/zabbix/zabbix_server.conf
186 |
187 | # link frontend with new database server
188 | nano /etc/zabbix/web/zabbix.conf.php
189 | $DB['TYPE'] = 'POSTGRESQL';
190 | $DB['SERVER'] = '10.230.16.249';
191 | $DB['PORT'] = '5432';
192 | $DB['DATABASE'] = 'zabbix_server';
193 | $DB['USER'] = 'zabbix';
194 | $DB['PASSWORD'] = 'zabbix';
195 |
196 | # test if everything seems to be OK with frontend
197 |
198 | # check section "Administration"=>"Queue". It should produce error.
199 |
200 | # stop backend service
201 | systemctl stop zabbix-server
202 |
203 | # remove old backend packages with mysql
204 | yum remove zabbix-server-mysql
205 |
206 | # install backend package wiht pg
207 | yum install zabbix-server-pgsql
208 |
209 | # make sure service scheduled at bootup
210 | systemctl enable zabbix-server
211 |
212 | # start service
213 | systemctl start zabbix-server
214 |
215 | # check log
216 | tail -99f /var/log/zabbix/zabbix_server.log
217 |
218 | # at the frontend check "Administration"=>"Queue". It should work.
219 |
220 | # after running backend for 20 minutes enable back trigger based actions
221 |
222 |
223 |
224 | # create timescale extension
225 | echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix_server
226 | cp ~/zabbix-5.0.5/database/postgresql/timescaledb.sql /tmp
227 |
228 | su - postgres
229 |
230 | # test connection from postgres user 'zabbix'
231 | psql --host=127.0.0.1 --username=zabbix zabbix_server
232 | \d
233 | \q
234 |
235 | # apply timescale extension. make sure we are running via 'screen' utility
236 | cat /tmp/timescaledb.sql | psql --host=127.0.0.1 --username=zabbix zabbix
237 | # this will take few hours
238 |
--------------------------------------------------------------------------------
/Oracle-XE/oracle18c.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # RAM 1600MB minimum
4 |
5 | # https://docs.oracle.com/en/database/oracle/oracle-database/18/xeinl/procedure-installing-oracle-database-xe.html
6 |
7 | curl -o oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm
8 |
9 | yum -y localinstall oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm
10 |
11 | # https://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html
12 | # the following package will install for 10 minutes or something
13 | yum -y localinstall oracle-database-xe-18c-1.0-1.x86_64.rpm
14 |
15 | # Running transaction
16 | # [SEVERE] Oracle Database 18c Express Edition requires a minimum of 1GB of physical memory (RAM). This system has 739 MB of RAM and does not meet minimum requirements.
17 | #
18 | # error: %pre(oracle-database-xe-18c-1.0-1.x86_64) scriptlet failed, exit status 1
19 | # Error in PREIN scriptlet in rpm package oracle-database-xe-18c-1.0-1.x86_64
20 | # Verifying : oracle-database-xe-18c-1.0-1.x86_64 1/1
21 | #
22 | # Failed:
23 | # oracle-database-xe-18c.x86_64 0:1.0-1
24 |
25 | # increase RAM in this case
26 |
27 | # IN SUCCESS this will show
28 | # Installing : oracle-database-xe-18c-1.0-1.x86_64 1/1
29 | # [INFO] Executing post installation scripts...
30 | # [INFO] Oracle home installed successfully and ready to be configured.
31 | # To configure Oracle Database XE, optionally modify the parameters in '/etc/sysconfig/oracle-xe-18c.conf' and then execute '/etc/init.d/oracle-xe-18c configure' as root.
32 | # Verifying : oracle-database-xe-18c-1.0-1.x86_64 1/1
33 | #
34 | # Installed:
35 | # oracle-database-xe-18c.x86_64 0:1.0-1
36 |
37 | # to this point noone is listening on port 1521
38 | netstat -tulpn | grep 1521
39 |
40 | # see if free is 1.3GB
41 | free -h
42 |
43 | # lets configure oracle DB. This will take 22 minutes with 2 cores and 2500MB RAM. It will stuck on 47% for 15 minutes. that is normal
44 | time /etc/init.d/oracle-xe-18c configure
45 |
46 |
47 | # Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
48 |
49 | # 5sRj4GXspvDKsBXW
50 |
51 | # Confirm the password:
52 | # Configuring Oracle Listener.
53 | # Listener configuration succeeded.
54 | # Configuring Oracle Database XE.
55 | # [WARNING] [DBT-11205] Specified shared pool size does not meet the recommended minimum size requirement. This might cause database creation to fail.
56 | # ACTION: Specify at least (381 MB) for shared pool size.
57 | # Enter SYS user password:
58 | # *****************
59 | # Enter SYSTEM user password:
60 | # ******************
61 | # Enter PDBADMIN User Password:
62 | # *****************
63 | # Prepare for db operation
64 | # 7% complete
65 | # Copying database files
66 | # 8% complete
67 | # [WARNING] ORA-00821: Specified value of sga_target 320M is too small, needs to be at least 396M
68 | # ORA-01078: failure in processing system parameters
69 | #
70 | # 9% complete
71 | # [FATAL] ORA-01034: ORACLE not available
72 | #
73 | # 29% complete
74 | # 100% complete
75 | # [FATAL] ORA-01034: ORACLE not available
76 | #
77 | # 7% complete
78 | # 0% complete
79 | # Look at the log file "/opt/oracle/cfgtoollogs/dbca/XE/XE.log" for further details.
80 | #
81 | # Database configuration failed. Check logs under '/opt/oracle/cfgtoollogs/dbca'.
82 |
83 |
84 | cat /opt/oracle/cfgtoollogs/dbca/XE/XE.log
85 | # [ 2019-03-14 19:47:29.105 EET ] [WARNING] [DBT-11205] Specified shared pool size does not meet the recommended minimum size requirement. This might cause database creation to fail.
86 | # [ 2019-03-14 19:47:30.941 EET ] Prepare for db operation
87 | # DBCA_PROGRESS : 7%
88 | # [ 2019-03-14 19:47:31.607 EET ] Copying database files
89 | # DBCA_PROGRESS : 8%
90 | # [ 2019-03-14 19:47:34.335 EET ] [WARNING] ORA-00821: Specified value of sga_target 320M is too small, needs to be at least 396M
91 | # ORA-01078: failure in processing system parameters
92 | #
93 | # DBCA_PROGRESS : 9%
94 | # [ 2019-03-14 19:47:34.339 EET ] [FATAL] ORA-01034: ORACLE not available
95 | #
96 | # DBCA_PROGRESS : 29%
97 | # DBCA_PROGRESS : 100%
98 | # [ 2019-03-14 19:47:34.357 EET ] [FATAL] ORA-01034: ORACLE not available
99 | #
100 | # DBCA_PROGRESS : 7%
101 | # DBCA_PROGRESS : 0%
102 |
103 | # increasing memory to 1600MB should solve the case
104 |
105 | # Oracle Database instance XE is already configured.
106 | # > /etc/oratab
107 |
108 |
109 | #======= ON SUCCESS IT WILL SHOW OUTPUT
110 |
111 | # [root@oracle18c ~]# time /etc/init.d/oracle-xe-18c configure
112 | # Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 u ppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
113 | # Confirm the password:
114 | # Configuring Oracle Listener.
115 | # Listener configuration succeeded.
116 | # Configuring Oracle Database XE.
117 | # Enter SYS user password:
118 | # *****************
119 | # Enter SYSTEM user password:
120 | # ***************
121 | # Enter PDBADMIN User Password:
122 | # ***************
123 | # Prepare for db operation
124 | # 7% complete
125 | # Copying database files
126 | # 29% complete
127 | # Creating and starting Oracle instance
128 | # 30% complete
129 | # 31% complete
130 | # 34% complete
131 | # 38% complete
132 | # 41% complete
133 | # 43% complete
134 | # Completing Database Creation
135 | # 47% complete
136 | # 50% complete
137 | # Creating Pluggable Databases
138 | # 54% complete
139 | # 71% complete
140 | # Executing Post Configuration Actions
141 | # 93% complete
142 | # Running Custom Scripts
143 | # 100% complete
144 | # Database creation complete. For details check the logfiles at:
145 | # /opt/oracle/cfgtoollogs/dbca/XE.
146 | # Database Information:
147 | # Global Database Name:XE
148 | # System Identifier(SID):XE
149 | # Look at the log file "/opt/oracle/cfgtoollogs/dbca/XE/XE.log" for further details.
150 | #
151 | # Connect to Oracle Database using one of the connect strings:
152 | # Pluggable database: oracle18c/XEPDB1
153 | # Multitenant container database: oracle18c
154 | # Use https://localhost:5500/em to access Oracle Enterprise Manager for Oracle Database XE
155 | #
156 | # real 21m57.088s
157 | # user 1m5.216s
158 | # sys 0m6.781s
159 |
160 |
161 |
162 | # cat /opt/oracle/cfgtoollogs/dbca/XE/XE.log
163 | # [ 2019-03-14 20:41:52.413 EET ] Prepare for db operation
164 | # DBCA_PROGRESS : 7%
165 | # [ 2019-03-14 20:41:52.760 EET ] Copying database files
166 | # DBCA_PROGRESS : 29%
167 | # [ 2019-03-14 20:44:58.096 EET ] Creating and starting Oracle instance
168 | # DBCA_PROGRESS : 30%
169 | # DBCA_PROGRESS : 31%
170 | # DBCA_PROGRESS : 34%
171 | # DBCA_PROGRESS : 38%
172 | # DBCA_PROGRESS : 41%
173 | # DBCA_PROGRESS : 43%
174 | # [ 2019-03-14 20:52:47.935 EET ] Completing Database Creation
175 | # DBCA_PROGRESS : 47%
176 | # DBCA_PROGRESS : 50%
177 | # [ 2019-03-14 21:02:11.215 EET ] Creating Pluggable Databases
178 | # DBCA_PROGRESS : 54%
179 | # DBCA_PROGRESS : 71%
180 | # [ 2019-03-14 21:03:10.672 EET ] Executing Post Configuration Actions
181 | # DBCA_PROGRESS : 93%
182 | # [ 2019-03-14 21:03:10.676 EET ] Running Custom Scripts
183 | # DBCA_PROGRESS : 100%
184 | # [ 2019-03-14 21:03:16.553 EET ] Database creation complete. For details check the logfiles at:
185 | # /opt/oracle/cfgtoollogs/dbca/XE.
186 | # Database Information:
187 | # Global Database Name:XE
188 | # System Identifier(SID):XE
189 |
190 | # now oracle database listens on port 1521
191 | netstat -tulpn | grep 1521
192 |
193 | systemctl status oracle-xe-18c
194 | systemctl enable oracle-xe-18c
195 | systemctl start oracle-xe-18c
196 |
197 |
198 | # install instant client
199 | # https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
200 |
201 | # https://download.oracle.com/otn/linux/instantclient/183000/oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm?AuthParam=1552592336_1718665abe5b0c48d71858d5fa869dca
202 | # https://download.oracle.com/otn/linux/instantclient/183000/oracle-instantclient18.3-odbc-18.3.0.0.0-3.x86_64.rpm?AuthParam=1552592399_e99b60e7a2d44c2f7cb70961d6b1e2f9
203 |
204 |
205 | rpm -i oracle-instantclient18.3-basic-18.3.0.0.0-3.x86_64.rpm # required for odbc
206 | rpm -i oracle-instantclient18.3-odbc-18.3.0.0.0-3.x86_64.rpm # odbc connector. needed to use direct SQL statements
207 |
208 |
209 | echo "/u01/app/oracle/product/11.2.0/xe/lib" > /etc/ld.so.conf.d/oracle.conf
210 | chmod o+r /etc/ld.so.conf.d/oracle.conf
211 |
212 | ls -l /etc/ld.so.conf.d
213 | ls -l /usr/lib/oracle/18.3/client64/lib
214 | echo "/usr/lib/oracle/18.3/client64/lib" > /etc/ld.so.conf.d/oracle-client-18.3.conf
215 | ldconfig -v
216 | # chmod o+r /etc/ld.so.conf.d/oracle-client-18.3.conf
217 |
218 |
219 |
220 | cat <<'EOF'> /etc/profile.d/oracle18c.sh
221 | export ORACLE_SID=XE
222 | export ORAENV_ASK=NO
223 | . /opt/oracle/product/18c/dbhomeXE/bin/oraenv
224 | EOF
225 | chmod o+r /etc/profile.d/oracle18c.sh
226 |
227 | echo $ORACLE_HOME
228 | echo $LD_LIBRARY_PATH
229 | tnsping XE
230 |
231 |
232 | # prerequsites to compile proxy
233 | yum -y install gcc make net-snmp-devel libssh2-devel libcurl-devel unixODBC-devel bc net-tools vim unzip mlocate policycoreutils-python
234 |
235 |
236 | su - oracle
237 | echo $ORACLE_HOME
238 | echo $LD_LIBRARY_PATH
239 | tnsping XE
240 |
241 |
242 | # download zabbix source archive into oracle profile
243 | cd
244 | v=4.0.5
245 | curl -L "http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$v/zabbix-$v.tar.gz" -o zabbix-$v.tar.gz
246 | tar -vzxf zabbix-$v.tar.gz -C .
247 | cd ~/zabbix-$v/database/oracle
248 | cp *.sql ~
249 |
250 | # enter database administration with oracle super user
251 | sqlplus sys as sysdba
252 | # '5sRj4GXspvDKsBXW'
253 |
254 | # This should show:
255 | # Connected to:
256 | # Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
257 | # Version 18.4.0.0.0
258 |
259 |
260 | select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';
261 | # this should report
262 | # NLS_CHARACTERSET
263 | # AL32UTF8
264 |
265 | # NLS_NCHAR_CHARACTERSET
266 | # UTF8
267 |
268 | # if not then execute these commands:
269 |
270 | shutdown immediate
271 | startup mount
272 | alter system enable restricted session;
273 | alter system set job_queue_processes=0;
274 | alter system set aq_tm_processes=0;
275 | alter database open;
276 | ALTER DATABASE NATIONAL CHARACTER SET internal_use UTF8;
277 | shutdown immediate
278 | startup
279 |
280 | # check again
281 | select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';
282 |
283 | # test some status
284 | select * from v$sysstat;
285 | select cdb from v$database;
286 | select name from v$datafile;
287 |
288 |
289 | sqlplus / as sysdba
290 |
291 |
292 |
293 | # DROP TABLESPACE "ZABBIX_TS" INCLUDING CONTENTS AND DATAFILES;
294 |
295 |
296 |
297 | CREATE TABLESPACE "ZABBIX_TS" DATAFILE '/opt/oracle/oradata/XE/zabbix_ts.dbf' SIZE 100M AUTOEXTEND ON NEXT 536870912 MAXSIZE 20G LOGGING ONLINE PERMANENT BLOCKSIZE 8192 EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
298 | CREATE USER zabbix IDENTIFIED BY zabbix DEFAULT TABLESPACE ZABBIX_TS;
299 |
300 |
301 | CREATE USER zabbix
302 | IDENTIFIED BY zabbix
303 | DEFAULT TABLESPACE ZABBIX_TS
304 | QUOTA 10M ON ZABBIX_TS
305 | TEMPORARY TABLESPACE temp
306 | QUOTA 5M ON system
307 | PROFILE app_user
308 | PASSWORD EXPIRE;
309 |
310 |
311 |
312 | # ORA-65096: invalid common user or role name
313 |
314 | GRANT DBA TO zabbix WITH ADMIN OPTION;
315 | exit
316 |
317 |
318 | CREATE USER sidney
319 | IDENTIFIED BY out_standing1
320 | DEFAULT TABLESPACE example
321 | QUOTA 10M ON example
322 | TEMPORARY TABLESPACE temp
323 | QUOTA 5M ON system
324 | PROFILE app_user
325 | PASSWORD EXPIRE;
326 |
327 |
328 |
329 |
330 |
331 |
--------------------------------------------------------------------------------
/Oracle-XE/oracle-at-backend.sh:
--------------------------------------------------------------------------------
1 | # the goal of this instruction is to test oracle database monitoring through linuxODBC driver. So we will set up proxy with 'Oracle 11.2g express edition' so have something to monitor.
2 |
3 | # 2 GB of RAM must be persistent
4 |
5 | # install vagrant SSH key for future passwordless root access
6 | echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== imported-openssh-key" > ~/.ssh/authorized_keys
7 | chmod -R 600 ~/.ssh/authorized_keys
8 |
9 | # set hostname to 'oracle-be.lan' which stands for oracle back-end
10 | nmtui
11 | reboot
12 | # reboot computer so when you execute '/etc/init.d/oracle-xe configure' the oracle wizard will really take up the right hostname. Without reboot it will not work.
13 |
14 | # go to https://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html
15 | # download:
16 | # * oracle-xe-11.2.0-1.0.x86_64.rpm.zip
17 | # and place this file on /root
18 |
19 | # go to https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
20 | # download:
21 | # * oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
22 | # * oracle-instantclient11.2-odbc-11.2.0.4.0-1.x86_64.rpm
23 | # and place these files on /root
24 |
25 | # install prerequsites for everything
26 | yum -y install gcc make net-snmp-devel libssh2-devel libcurl-devel unixODBC-devel bc net-tools vim unzip mlocate policycoreutils-python
27 | # bc, net-tools are required for oracle setup
28 |
29 | # according to https://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCIFHBE some modifications must be adjusted to kernel parameters
30 | sysctl kernel.shmmax # check shmmax. must be 4294967295
31 | echo "kernel.shmmax = 4294967295" >> /etc/sysctl.conf # install shmmax=4294967295 globaly at the next boot
32 | sysctl -w kernel.shmmax=4294967295 # set shmmax=4294967295 now!
33 | sysctl kernel.shmmax # check again live shmmax value
34 |
35 | sysctl kernel.shmall # shmall must be 2097152
36 | echo "kernel.shmall = 2097152" >> /etc/sysctl.conf # install shmall=2097152 at the next boot
37 | sysctl -w kernel.shmall=2097152 # set shmall=2097152 now!
38 | sysctl kernel.shmall # check again live shmall value
39 |
40 | unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip && cd ~/Disk1 && rpm -i oracle-xe-11.2.0-1.0.x86_64.rpm && time /etc/init.d/oracle-xe configure
41 | # Let's set database password '5sRj4GXspvDKsBXW' for SYS and SYSTEM account
42 |
43 | # https://help.ubuntu.com/community/Oracle%20Instant%20Client
44 | # install oracle path globaly
45 | echo "/u01/app/oracle/product/11.2.0/xe/lib" > /etc/ld.so.conf.d/oracle.conf
46 | chmod o+r /etc/ld.so.conf.d/oracle.conf
47 | ldconfig -v
48 |
49 | cat <<'EOF'> /etc/profile.d/oracle.sh
50 | . /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
51 | export LD_LIBRARY_PATH=$ORACLE_HOME/lib
52 | EOF
53 | chmod o+r /etc/profile.d/oracle.sh
54 |
55 | su - oracle
56 | echo $ORACLE_HOME
57 | echo $LD_LIBRARY_PATH
58 | tnsping XE # try to ping TNSNAME. to this point it should retreive 'OK' at the last line
59 |
60 | # download zabbix source archive into oracle profile
61 | cd
62 | v=4.0.5
63 | curl -L "http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$v/zabbix-$v.tar.gz" -o zabbix-$v.tar.gz
64 | tar -vzxf zabbix-$v.tar.gz -C .
65 | cd ~/zabbix-$v/database/oracle
66 | cp *.sql ~
67 |
68 | # enter database administration with oracle super user
69 | sqlplus sys as sysdba
70 | # '5sRj4GXspvDKsBXW'
71 |
72 | # This should show:
73 | # Connected to:
74 | # Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
75 |
76 | select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';
77 | # this should report
78 | # NLS_CHARACTERSET
79 | # AL32UTF8
80 |
81 | # NLS_NCHAR_CHARACTERSET
82 | # UTF8
83 |
84 | # if not then execute these commands:
85 |
86 | shutdown immediate
87 | startup mount
88 | alter system enable restricted session;
89 | alter system set job_queue_processes=0;
90 | alter system set aq_tm_processes=0;
91 | alter database open;
92 | ALTER DATABASE NATIONAL CHARACTER SET internal_use UTF8;
93 | shutdown immediate
94 | startup
95 |
96 | # check again
97 | select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';
98 |
99 | # test some status
100 | select * from v$sysstat;
101 |
102 | # https://uberdev.wordpress.com/2011/12/07/zabbix-deployment-on-rhel-with-oracle/
103 | # create zabbix database (table space)
104 |
105 | # DROP TABLESPACE "ZABBIX_TS" INCLUDING CONTENTS AND DATAFILES;
106 |
107 |
108 | CREATE TABLESPACE "ZABBIX_TS" DATAFILE '/u01/app/oracle/oradata/XE/zabbix_ts.dbf' SIZE 100M AUTOEXTEND ON NEXT 536870912 MAXSIZE 20G LOGGING ONLINE PERMANENT BLOCKSIZE 8192 EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
109 | CREATE USER zabbix IDENTIFIED BY zabbix DEFAULT TABLESPACE ZABBIX_TS;
110 | GRANT DBA TO zabbix WITH ADMIN OPTION;
111 | exit
112 |
113 | # connect to database zabbix. this is a way how to authorize into database with one-liner
114 | sqlplus zabbix/zabbix
115 |
116 | # last check if the encoding is right
117 | select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';
118 | # this should report:
119 | # NLS_CHARACTERSET
120 | # AL32UTF8
121 | #
122 | # NLS_NCHAR_CHARACTERSET
123 | # UTF8
124 |
125 | SET DEFINE OFF
126 |
127 | @/u01/app/oracle/schema.sql
128 |
129 | # exit the database client
130 | exit
131 |
132 | # exit oracle user
133 | exit
134 |
135 | # download source of zabbix
136 | cd
137 | v=4.0.5
138 | curl -L "http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$v/zabbix-$v.tar.gz" -o zabbix-$v.tar.gz
139 | tar -vzxf zabbix-$v.tar.gz -C .
140 | cd ~/zabbix-$v
141 |
142 | # create user 'zabbix' and assign it to group 'zabbix'
143 | groupadd zabbix
144 | useradd -g zabbix zabbix
145 |
146 | # configure proxy with agent
147 | #./configure --enable-proxy --enable-agent --with-oracle --with-unixodbc --with-net-snmp --with-ssh2 --with-openssl --with-libcurl --sysconfdir=/etc/zabbix --prefix=/usr
148 |
149 | # maybe it is ok te manage the agent binary from repository.
150 | # only the proxy (without agent) will be maintained
151 | yum -y install libssh2-devel # configure: error: SSH2 library not found
152 | yum -y install libcurl-devel # configure: error: Curl library not found
153 |
154 | # check if everything is in place
155 | ./configure --enable-proxy --with-oracle --with-unixodbc --with-net-snmp --with-ssh2 --with-openssl --with-libcurl --sysconfdir=/etc/zabbix --prefix=/usr
156 |
157 | # compile
158 | time make
159 |
160 | # backup previous binary
161 | oldver=$(zabbix_proxy -V | grep zabbix_proxy | grep -E -o "[0-9\.]+")
162 | mkdir -p ~/$oldver
163 | cd /usr/sbin
164 | mkdir -p ~/$oldver$(pwd)
165 | cp /usr/sbin/zabbix_proxy ~/$oldver$(pwd)
166 |
167 | # stop existing binary
168 | systemctl stop zabbix-proxy
169 | tail -10 /var/log/zabbix/zabbix_proxy.log
170 |
171 | # check if proxy is in old version
172 | zabbix_proxy -V
173 |
174 | # install everything
175 | make install
176 |
177 | # check if proxy is in new version
178 | zabbix_proxy -V
179 |
180 | # start proxy
181 | systemctl start zabbix-proxy
182 | tail -10 /var/log/zabbix/zabbix_proxy.log
183 |
184 | grep -v "^$\|#" /etc/zabbix/zabbix_proxy.conf
185 | # modify the values to look similar to this
186 | Server=ec2-35-166-97-138.us-west-2.compute.amazonaws.com
187 | Hostname=BeeBoxProxY
188 | LogFile=/var/log/zabbix/zabbix_proxy.log
189 | DBName=XE
190 | DBUser=zabbix
191 | DBPassword=zabbix
192 | DBPort=1521
193 | Timeout=4
194 | LogSlowQueries=3000
195 |
196 | # OR you can overwrite the conf:
197 | cp /etc/zabbix/{zabbix_proxy.conf,original.zabbix_proxy.conf}
198 | # fast configuration install. overwrite original
199 | cat >/etc/zabbix/zabbix_proxy.conf<< EOL
200 | Server=ec2-35-166-97-138.us-west-2.compute.amazonaws.com
201 | Hostname=BeeBoxProxY
202 | LogFile=/var/log/zabbix/zabbix_proxy.log
203 | DBName=XE
204 | DBUser=zabbix
205 | DBPassword=zabbix
206 | DBPort=1521
207 | Timeout=4
208 | LogSlowQueries=3000
209 | EOL
210 |
211 | # check current TNS strings installed
212 | cat /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora
213 |
214 | # backup config
215 | cp /u01/app/oracle/product/11.2.0/xe/network/admin/{tnsnames.ora,original.tnsnames.ora}
216 |
217 | # let's replace whatever DNS name is used with 127.0.0.1
218 | sed -i "s|$(hostname)|127.0.0.1|g" /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora
219 | # for example if the hostname is like '4d61050b753b.sn.mynetname.net' then it won't work witch such long name. Don't know why.
220 |
221 | # see if changes has been installed
222 | cat /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora
223 |
224 | # test if proxy is working
225 | su - zabbix -s /bin/bash
226 | # zabbix_proxy: error while loading shared libraries: libclntsh.so.11.1: cannot open shared object file: No such file or directory
227 |
228 | # allow to communicate with oracle engine right now!
229 | export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
230 | export LD_LIBRARY_PATH=$ORACLE_HOME/lib
231 |
232 | # launch the proxy server now in foreground
233 | zabbix_proxy -f
234 |
235 | # Ctrl+C and exit zabbix user
236 | exit
237 |
238 | # open another session and check the logs or hit Ctrl+C in this session
239 | cat /tmp/zabbix_proxy.log
240 |
241 |
242 | # set up ODBC connection
243 | cd
244 |
245 | rpm -i oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm # required for odbc
246 | rpm -i oracle-instantclient11.2-odbc-11.2.0.4.0-1.x86_64.rpm # odbc connector. needed to use direct SQL statements
247 |
248 | # fix some error mentioned http://docs.adaptivecomputing.com/9-1-0/MWS/Content/topics/moabWorkloadManager/topics/databases/oracle.html
249 | updatedb && locate libodbcinst
250 | cd /usr/lib64
251 | ln -s libodbcinst.so.2 libodbcinst.so.1
252 | chmod 755 /usr/lib/oracle/11.2/client64/lib/lib*
253 | ldd /usr/lib/oracle/11.2/client64/lib/libsqora.so.11.1
254 |
255 | # check is [isql] utility is installed
256 | isql
257 |
258 | # backup original file which contains samples for MySQL and PostgreSQL
259 | cp /etc/{odbcinst.ini,original.odbcinst.ini}
260 |
261 | # install/overwrite new connection driver definition regarding to oracle 11.2 xe
262 | cat >/etc/odbcinst.ini<< EOL
263 | [Oracle 11g ODBC driver]
264 | Description = Oracle ODBC driver for Oracle 11g
265 | Driver = /usr/lib/oracle/11.2/client64/lib/libsqora.so.11.1
266 | Setup =
267 | FileUsage =
268 | CPTimeout =
269 | CPReuse =
270 | Driver Logging = 7
271 |
272 | [ODBC]
273 | Trace = Yes
274 | TraceFile = /tmp/odbc.log
275 | ForceTrace = Yes
276 | Pooling = No
277 | DEBUG = 1
278 | EOL
279 |
280 | # install connection details. note the the line with "DNS = XE". This is another place where hostname oracle-be.lan matters!
281 | cat >/etc/odbc.ini<< EOL
282 | [ODBC]
283 | Application Attributes = T
284 | Attributes = W
285 | BatchAutocommitMode = IfAllSuccessful
286 | BindAsFLOAT = F
287 | CloseCursor = F
288 | DisableDPM = F
289 | DisableMTS = T
290 | Driver = Oracle 11g ODBC driver
291 | DSN = XE
292 | EXECSchemaOpt =
293 | EXECSyntax = T
294 | Failover = T
295 | FailoverDelay = 10
296 | FailoverRetryCount = 10
297 | FetchBufferSize = 64000
298 | ForceWCHAR = F
299 | Lobs = T
300 | Longs = T
301 | MaxLargeData = 0
302 | MetadataIdDefault = F
303 | QueryTimeout = T
304 | ResultSets = T
305 | ServerName = 127.0.0.1
306 | SQLGetData extensions = F
307 | Translation DLL =
308 | Translation Option = 0
309 | DisableRULEHint = T
310 | UserID = zabbix
311 | Password = zabbix
312 | StatementCache=F
313 | CacheBufferSize=20
314 | UseOCIDescribeAny=F
315 | MaxTokenSize=8192
316 | EOL
317 |
318 | # move to zabbix user because it know (~/.bach_profile) how to communicate to oracle
319 | su - zabbix
320 |
321 | # test connection
322 | isql -v ODBC
323 | # this should report
324 | # +---------------------------------------+
325 | # | Connected! |
326 | # | |
327 | # | sql-statement |
328 | # | help [tablename] |
329 | # | quit |
330 | # | |
331 | # +---------------------------------------+
332 |
333 | #test some queries
334 | select count(*) "procnum" from gv$process
335 | select to_char((sysdate-startup_time)*86400, 'FM99999999999999990') retvalue from gv$instance
336 |
337 | # exit isql utility
338 | quit
339 |
340 | # attach the template inside zabbix
341 |
342 | # exit zabbix user
343 | exit
344 |
345 | # install init file. the difference between this and original is 'PIDFile=/tmp/zabbix_proxy.pid'
346 | # be careful when modify this script. dolar signs must be escaped.
347 | cat >/usr/lib/systemd/system/zabbix-proxy.service<< EOL
348 | [Unit]
349 | Description=Zabbix Proxy
350 | After=syslog.target
351 | After=network.target
352 |
353 | [Service]
354 | Environment="CONFFILE=/etc/zabbix/zabbix_proxy.conf"
355 | EnvironmentFile=-/etc/sysconfig/zabbix-proxy
356 | Type=forking
357 | Restart=on-failure
358 | PIDFile=/tmp/zabbix_proxy.pid
359 | KillMode=control-group
360 | ExecStart=/usr/sbin/zabbix_proxy -c \$CONFFILE
361 | ExecStop=/bin/kill -SIGTERM \$MAINPID
362 | RestartSec=10s
363 | TimeoutSec=0
364 |
365 | [Install]
366 | WantedBy=multi-user.target
367 | EOL
368 |
369 | # install environment file
370 | cat >/etc/sysconfig/zabbix-proxy<< EOL
371 | ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
372 | LD_LIBRARY_PATH=/usr/lib64:/u01/app/oracle/product/11.2.0/xe/lib
373 | ORACLE_SID=XE
374 | PATH=/bin:/usr/bin:/usr/sbin:/u01/app/oracle/product/11.2.0/xe/bin
375 |
376 | export ORACLE_HOME
377 | export LD_LIBRARY_PATH
378 | export ORACLE_SID
379 | export PATH
380 | EOL
381 |
382 | systemctl daemon-reload
383 | setenforce 0
384 | systemctl stop zabbix-proxy
385 |
386 | systemctl start zabbix-proxy
387 | # show 'grep's which components are involved, not allowed
388 | grep denied /var/log/audit/audit.log | sed "s/^.*denied /denied/g;s/ pid=[0-9]\+ \| ino=[0-9]\+//g;s/ name=.*scontext=\| path=.*scontext=/ /g" | sort | uniq | sed "s/^.*comm=.//g;s/. .*system_r:/.*/g;s/:.*//g" | sort|uniq | sed "s/^/grep \"comm.*/g;s/$/\" \/var\/log\/audit\/audit.log/g"
389 |
390 | # install missing
391 | grep "comm.*zabbix_proxy.*zabbix_t" /var/log/audit/audit.log | audit2allow -M comm_zabbix_proxy_zabbix_t
392 | semodule -i comm_zabbix_proxy_zabbix_t.pp
393 |
394 | systemctl stop zabbix-proxy
395 | setenforce 1
396 | systemctl start zabbix-proxy
397 | systemctl status zabbix-proxy
398 | systemctl enable zabbix-proxy
399 |
400 | # Problem:
401 | # This system does not meet the minimum requirements for swap space. Based on
402 | # the amount of physical memory available on the system, Oracle Database 11g
403 | # Express Edition requires 2048 MB of swap space. This system has 0 MB
404 | # of swap space. Configure more swap space on the system and retry the
405 | # installation.
406 | #
407 | # Solution:
408 | # dd if=/dev/zero of=/myswap bs=1M count=2048 && chmod 0600 /myswap && mkswap /myswap && swapon /myswap
409 |
410 | # Problem:
411 | # [01000][unixODBC][Driver Manager]Can't open lib '/usr/lib/oracle/11.2/client64/lib/libsqora.so.11.1' : file not found
412 | # [ISQL]ERROR: Could not SQLConnect
413 | # Solution:
414 | # echo ". /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh">> ~/.bash_profile
415 | # echo "export LD_LIBRARY_PATH=\$ORACLE_HOME/lib">> ~/.bash_profile
416 |
417 | # Problem:
418 | # ORA-12154: TNS:could not resolve the connect identifier specified
419 | # this may be related to long hostname. use 127.0.0.1 instead
420 |
--------------------------------------------------------------------------------
/postgreSQL12.RH8.sh:
--------------------------------------------------------------------------------
1 |
2 |
3 | # specific timescale and postgres version
4 | # docker run --name pg11ts132 -t -e POSTGRES_PASSWORD="zabbix" -e POSTGRES_DB="dummy_db" -p 17411:5432 -d timescale/timescaledb:1.3.2-pg11
5 |
6 |
7 |
8 | echo 1 | sudo tee /proc/sys/vm/overcommit_memory
9 | sudo dd if=/dev/zero of=/myswap1 bs=1M count=1024 && sudo chown root:root /myswap1 && sudo chmod 0600 /myswap1 && sudo mkswap /myswap1 && sudo swapon /myswap1 && free -m
10 | sudo dd if=/dev/zero of=/myswap2 bs=1M count=1024 && sudo chown root:root /myswap2 && sudo chmod 0600 /myswap2 && sudo mkswap /myswap2 && sudo swapon /myswap2 && free -m
11 |
12 | # install zabbix repo. to setup zabbix agent and use native postgres monitoring
13 | rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
14 |
15 | # https://www.postgresql.org/download/linux/redhat/
16 | # Install PostgreSQL repository RPM:
17 | dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
18 |
19 | # Install TimescaleDB repo
20 | sudo tee /etc/yum.repos.d/timescale_timescaledb.repo <> /var/lib/pgsql/12/data/postgresql.conf
50 |
51 | # specify/whiteliust the binding address so other remote machines can connect to server
52 | echo "listen_addresses = '0.0.0.0'" >> /var/lib/pgsql/12/data/postgresql.conf
53 |
54 | systemctl enable postgresql-12
55 | systemctl start postgresql-12
56 | systemctl status postgresql-12
57 |
58 | # check if postgres is listening on IP address
59 | ss --tcp --listen --numeric | grep 5432
60 | # it should not listen on '127.0.0.1'
61 |
62 | # navigate to posgres user (root for db engine)
63 | su - postgres
64 |
65 |
66 |
67 |
68 | # go to postgres
69 | su - postgres
70 |
71 | cd /tmp
72 |
73 | # on the cloud instance check size of events table
74 | SELECT pg_size_pretty(pg_total_relation_size('events'));
75 | # if it's less than 2G then continue
76 |
77 | # also show output:
78 | SELECT source,COUNT(*) FROM events GROUP BY source;
79 |
80 | # create a dump of cloud instance without historical data (no dots in the graphs)
81 | PGPASSWORD=zabbix \
82 | pg_dump \
83 | --host=10.133.112.87 \
84 | --port=7412 \
85 | --user=postgres \
86 | --exclude-schema=_timescaledb_internal \
87 | --exclude-schema=_timescaledb_cache \
88 | --exclude-schema=_timescaledb_catalog \
89 | --exclude-schema=_timescaledb_config \
90 | --exclude-table-data=history* \
91 | --exclude-table-data=trends* \
92 | --data-only \
93 | --dbname=z50 \
94 | --file=/tmp/data.sql
95 | # i think the dump will be completed in less than 10 minutes. It may lock an table 'events' for Zabbix application.
96 |
97 | # it will print:
98 | # pg_dump: warning: there are circular foreign-key constraints on this table:
99 | # pg_dump: application_prototype
100 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
101 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
102 | # pg_dump: warning: there are circular foreign-key constraints on this table:
103 | # pg_dump: graphs
104 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
105 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
106 | # pg_dump: warning: there are circular foreign-key constraints on this table:
107 | # pg_dump: group_prototype
108 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
109 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
110 | # pg_dump: warning: there are circular foreign-key constraints on this table:
111 | # pg_dump: hosts
112 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
113 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
114 | # pg_dump: warning: there are circular foreign-key constraints on this table:
115 | # pg_dump: httptest
116 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
117 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
118 | # pg_dump: warning: there are circular foreign-key constraints on this table:
119 | # pg_dump: items
120 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
121 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
122 | # pg_dump: warning: there are circular foreign-key constraints on this table:
123 | # pg_dump: triggers
124 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
125 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
126 |
127 |
128 | # destination
129 | # on a local postgres engine create user 'zabbix_user'
130 | PGHOST=10.133.112.87 PGPORT=17411 PGUSER=postgres PGPASSWORD=zabbix createuser --pwprompt zabbix_user
131 |
132 | # if there is an old database from previous tests - drop it
133 | # PGHOST=10.133.112.87 PGPORT=17411 PGUSER=postgres PGPASSWORD=zabbix dropdb zabbix_db
134 |
135 | # create database 'zabbix_db'
136 | PGHOST=10.133.112.87 PGPORT=17411 PGUSER=postgres PGPASSWORD=zabbix createdb -O zabbix_user zabbix_db
137 |
138 | # move to '/tmp' download zabbix source to get stock schema
139 | cd /tmp
140 | curl https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.5.tar.gz -o zabbix-source.tar.gz
141 | gunzip zabbix-source.tar.gz
142 | tar xvf zabbix-source.tar
143 | rm -rf zabbix-source.tar
144 |
145 | # insert stock schema inside database 'zabbix_db' under postgres user 'zabbix_user'
146 | cat /tmp/zabbix-5.0.5/database/postgresql/schema.sql | PGUSER=zabbix_user PGPASSWORD=zabbix PGHOST=127.0.0.1 psql zabbix_db > /tmp/data.insert.log 2>&1
147 | cat /tmp/zabbix-5.0.5/database/postgresql/schema.sql | \
148 | PGPASSWORD=zabbix \
149 | psql \
150 | --host=10.133.112.87 \
151 | --port=17411 \
152 | --user=zabbix_user \
153 | zabbix_db > /tmp/data.insert.log 2>&1
154 |
155 | # check log
156 | head -10 /tmp/data.insert.log
157 | tail -10 /tmp/data.insert.log
158 | # there should be no errors and warnings
159 | grep -i error /tmp/data.insert.log
160 | grep -i warning /tmp/data.insert.log
161 |
162 | # insert data from backup
163 | zcat /tmp/data.sql.gz | PGUSER=zabbix_user PGPASSWORD=zabbix PGHOST=127.0.0.1 psql zabbix_db > /tmp/data.insert2.log 2>&1
164 | grep -i error /tmp/data.insert2.log
165 | grep -i warning /tmp/data.insert2.log
166 |
167 | cat /tmp/data.sql | \
168 | PGPASSWORD=zabbix \
169 | psql \
170 | --host=10.133.112.87 \
171 | --port=17411 \
172 | --user=zabbix_user \
173 | zabbix_db >> /tmp/data.insert.log 2>&1
174 |
175 | # check log
176 | head -10 /tmp/data.insert.log
177 | tail -10 /tmp/data.insert.log
178 | # there should be no errors and warnings
179 | grep -i error /tmp/data.insert.log
180 | grep -i warning /tmp/data.insert.log
181 |
182 |
183 |
184 |
185 |
186 | # contact azure instance with most privilaged user 'postgres' and download structure of everything. It will be 2 megabyte file
187 | PGPASSWORD=zabbix \
188 | pg_dumpall \
189 | --host=HOSTNAME \
190 | --port=PORT \
191 | --username=postgres \
192 | --schema-only \
193 | --file=/tmp/azure.postgres.schema.only
194 |
195 | # exit 'postgres' user
196 | exit
197 |
198 |
199 |
200 | PGPASSWORD=zabbix \
201 | pg_dumpall \
202 | --host=10.133.112.87 \
203 | --port=7412 \
204 | --username=postgres \
205 | --schema-only \
206 | --file=/tmp/azure.postgres.schema.only
207 |
208 |
209 |
210 | --schema-only > /tmp/all.sql
211 |
212 |
213 | pg_dump \
214 | --host=10.133.112.87 \
215 | --port=7412 \
216 | --dbname=z44 \
217 | --username=zabbix \
218 | --password \
219 | --format=plain \
220 | --schema-only > /tmp/schema.sql
221 |
222 |
223 | # cat azure.postgres.schema.only | grep "^CREATE TABLE" | sort | uniq
224 |
225 | cat schema.sql | grep "^CREATE TABLE" | sort | uniq
226 |
227 | # default approach. must be used under 'postgres' user.
228 | PGPASSWORD=zabbix \
229 | pg_dump \
230 | --username=postgres \
231 | --schema-only \
232 | --dbname=zabbix \
233 | --file=schema.sql
234 |
235 | cat schema.sql | grep "^CREATE TABLE" | sort | uniq
236 |
237 |
238 | # approach 3. is working
239 | PGPASSWORD=zabbix \
240 | pg_dump \
241 | --username=postgres \
242 | --exclude-schema=_timescaledb_internal \
243 | --schema-only \
244 | --dbname=zabbix \
245 | --file=exclude.schema.timescaledb.internal.sql
246 | cat exclude.schema.timescaledb.internal.sql | grep "^CREATE TABLE" | sort | uniq
247 | cat exclude.schema.timescaledb.internal.sql | grep "^CREATE TABLE" | sort | uniq | wc -l
248 | grep "^CREATE TRIGGER" exclude.schema.timescaledb.internal.sql
249 |
250 |
251 |
252 | --see size of table events. this table is next biggest after raw historical data
253 | SELECT pg_size_pretty( pg_total_relation_size('events') );
254 |
255 |
256 | # download data. seems to be excluding everything timescale related
257 | PGPASSWORD=zabbix \
258 | pg_dump \
259 | --username=postgres \
260 | --exclude-schema=_timescaledb_internal \
261 | --exclude-schema=_timescaledb_cache \
262 | --exclude-schema=_timescaledb_catalog \
263 | --exclude-schema=_timescaledb_config \
264 | --exclude-table-data=history* \
265 | --exclude-table-data=trends* \
266 | --data-only \
267 | --dbname=zabbix \
268 | --file=data.sql
269 |
270 |
271 | # fetch data from cloud
272 |
273 | pg_dump \
274 | --exclude-schema=_timescaledb_internal \
275 | --exclude-schema=_timescaledb_cache \
276 | --exclude-schema=_timescaledb_catalog \
277 | --exclude-schema=_timescaledb_config \
278 | --exclude-table-data=history* \
279 | --exclude-table-data=trends* \
280 | --data-only \
281 | --dbname=z50 \
282 | --file=data.sql
283 |
284 |
285 | # detete all timescale related triggers
286 | sed -i "s|^CREATE TRIGGER ts_.*$||" exclude.schema.timescaledb.internal.sql
287 |
288 |
289 |
290 |
291 | # approach 4
292 | PGPASSWORD=zabbix \
293 | pg_dump \
294 | --username=postgres \
295 | --exclude-schema=_timescaledb_internal \
296 | --schema-only \
297 | --dbname=zabbix \
298 | --file=schema.sql
299 |
300 |
301 |
302 |
303 | --exclude-schema=pg_catalog \
304 | --exclude-schema=_timescaledb_catalog \
305 |
306 |
307 | PGPASSWORD=zabbix \
308 | pg_dump \
309 | --host=10.133.112.87 \
310 | --port=7412 \
311 | --username=postgres \
312 | --exclude-table='_hyper*chunk' \
313 | --schema-only \
314 | --dbname=z50 \
315 | --file=/tmp/azure.postgres.schema.only
316 |
317 |
318 |
319 | PGHOST=10.133.112.87 PGPORT=7412 PGPASSWORD=zabbix PGUSER=postgres \
320 | pg_dump \
321 | --data-only \
322 | --exclude-schema=_timescaledb_internal \
323 | --exclude-schema=_timescaledb_catalog \
324 | --exclude-schema=pg_catalog \
325 | --exclude-table-data=history* \
326 | --exclude-table-data=trends* \
327 | --format=plain \
328 | z50 | gzip --fast > /tmp/data.sql.gz
329 |
330 |
331 | --exclude-table
332 |
333 | --exclude-schema=_timescaledb_internal
334 |
335 | exit
336 |
337 |
338 | # create user
339 | createuser --pwprompt zabbix
340 |
341 | dropdb zabbix
342 | # create database 'zabbix' where owner is user 'zabbix'
343 | createdb -O zabbix zabbix
344 |
345 | # insert 5.0 schema
346 | cd ~/zabbix-5.0.4/database/postgresql/
347 | cat schema.sql | psql zabbix
348 | # insert sql under bash user zabbix which will be automatically correlated with SQL user 'zabbix' if exists
349 | cat schema.sql | sudo -u zabbix psql zabbix
350 |
351 | su - postgres
352 |
353 | # create timescaledb extenison. this must be done super user
354 | echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | psql zabbix
355 |
356 | # enable timescaledb definition how to chunk data for all 7 historical tables
357 | cat timescaledb.sql | psql zabbix
358 |
359 | zcat /usr/share/doc/zabbix-server-pgsql/timescaledb.sql.gz | psql zabbix
360 |
361 | cat timescaledb.sql | psql zabbix
362 |
363 |
364 | # cat images.sql data.sql | psql --port=5432 zabbix
365 |
366 | # make sure extension is there
367 | echo "SELECT * FROM pg_extension;" | psql zabbix
368 | # it should report timescaledb at least 1.7.4
369 |
370 | # observe hypertables
371 | echo "SELECT * FROM chunk_relation_size_pretty('trends');" | psql zabbix
372 | # it should empty table structure only. no hypertables are made yet
373 |
374 |
375 | # poll out data from old server. ignore historical data. ignore all hypertables comming from timescaledb
376 | cd
377 | PGHOST=10.133.112.87 PGPORT=7412 PGPASSWORD=zabbix PGUSER=postgres \
378 | pg_dump \
379 | --data-only \
380 | --exclude-schema=_timescaledb_internal \
381 | --exclude-schema=_timescaledb_catalog \
382 | --exclude-schema=pg_catalog \
383 | --exclude-table-data=history* \
384 | --exclude-table-data=trends* \
385 | --format=plain \
386 | z50 | gzip --fast > /tmp/data.sql.gz
387 |
388 | # this will print a message per tables 'triggers', 'items', 'httptest', 'hosts', 'group_prototype', 'graphs', 'application_prototype', 'chunk', 'hypertable':
389 | # pg_dump: warning: there are circular foreign-key constraints on this table:
390 | # pg_dump: httptest
391 | # pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
392 | # pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
393 |
394 |
395 | # restore data. dump does not contain hypertables
396 |
397 | zcat /tmp/data.sql.gz | sudo -u zabbix psql zabbix
398 |
399 |
400 | # ERROR: duplicate key value violates unique constraint "hypertable_pkey"
401 | # DETAIL: Key (id)=(1) already exists.
402 | # CONTEXT: COPY hypertable, line 1
403 | # COPY 544
404 | # ERROR: duplicate key value violates unique constraint "dimension_pkey"
405 | # DETAIL: Key (id)=(1) already exists.
406 | # CONTEXT: COPY dimension, line 1
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 | --exclude-table-data='*hypertable*' \
415 | --exclude-table-data='*chunk*' \
416 |
417 |
418 |
419 |
420 | PGHOST=10.133.112.87 PGPORT=7412 PGPASSWORD=zabbix PGUSER=postgres \
421 | pg_dump \
422 | --data-only \
423 | --exclude-schema=_timescaledb_internal \
424 | --exclude-table='*history*' \
425 | --exclude-table='*trends*' \
426 | --format=plain \
427 | z50 | gzip --fast > /tmp/data.sql.gz
428 |
429 | # dump individual table
430 | PGHOST=10.133.112.87 PGPORT=7412 PGPASSWORD=zabbix PGUSER=postgres \
431 | pg_dump \
432 | --data-only \
433 | --table=history \
434 | --format=plain \
435 | z50 | gzip --fast > /tmp/history.sql.gz
436 |
437 | --exclude-table=table
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 | # restore data. dump does not contain hypertables
448 | zcat /tmp/data.sql.gz | psql zabbix
449 |
450 |
451 | echo "host all all 10.133.253.43/32 md5" | sude tee -a /var/lib/pgsql/12/data/pg_hba.conf
452 |
453 | systemctl restart postgresql-12
454 |
455 | vi /var/lib/pgsql/12/data/pg_hba.conf
456 |
457 |
458 | --Create traditional trend tables as the old definitions with different names.
459 | CREATE TABLE history_uint_new (LIKE history_uint INCLUDING ALL);
460 |
461 | --Then you can migrate old data into new one if needed. This is optional.
462 | --Be sure that you have enough storage to duplicate the tables.
463 | insert into history_uint_new select * from history_uint;
464 |
465 | --Be sure that, new tables has the right data. Check the counts.
466 | select count(itemid) from history_uint;
467 | select count(itemid) from history_uint_new;
468 |
469 | --Now you can drop old timescaled tables.
470 | drop table history_uint;
471 |
472 | --Lastly, rename new traditional tables as needed.
473 | alter table history_uint_new rename to history_uint;
474 |
475 |
476 | # https://docs.timescale.com/latest/using-timescaledb/backup
477 |
478 |
--------------------------------------------------------------------------------
/ubuntu/proxy5ubuntu20arm64.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 |
4 | maj=5.0
5 | min=2
6 |
7 | cd /dev/shm
8 |
9 | curl -L "https://cdn.zabbix.com/zabbix/sources/stable/$maj/zabbix-$maj.$min.tar.gz" -o zabbix-$maj.$min.tar.gz
10 |
11 | tar -vzxf zabbix-$maj.$min.tar.gz
12 |
13 | cd zabbix-$maj.$min
14 |
15 | ./configure --enable-agent
16 |
17 | make install > /dev/shm/out.log
18 |
19 | # --bindir=DIR user executables [EPREFIX/bin]
20 | # --sbindir=DIR system admin executables [EPREFIX/sbin]
21 | # --libexecdir=DIR program executables [EPREFIX/libexec]
22 | # --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
23 |
24 | ./configure --sysconfdir=/etc/zabbix --prefix=/usr --enable-proxy --enable-agent --with-sqlite3 --with-libcurl --with-libxml2 --with-ssh2 --with-net-snmp --with-openssl --with-unixodbc
25 |
26 | ./configure --sysconfdir=/etc/zabbix --prefix=/usr --enable-proxy --enable-agent --enable-agent2 --with-sqlite3 --with-libcurl --with-libxml2 --with-ssh2 --with-net-snmp --with-openssl --with-unixodbc
27 |
28 | ./configure --sysconfdir=/etc/zabbix --prefix=/usr --enable-proxy --enable-agent --enable-agent2 --with-sqlite3 --with-libcurl --with-libxml2 --with-ssh2 --with-net-snmp --with-openssl --with-unixodbc --enable-java
29 |
30 | # configure: error: no acceptable C compiler found in $PATH
31 | sudo apt -y install build-essential
32 |
33 | # configure: error: SQLite3 library not found
34 | sudo apt -y install libsqlite3-dev
35 |
36 | # configure: error: LIBXML2 library not found
37 | sudo apt -y install libxml2-dev pkg-config
38 |
39 | # configure: error: unixODBC library not found
40 | sudo apt -y install unixodbc-dev
41 |
42 | # configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
43 | sudo apt -y install libsnmp-dev
44 |
45 | # configure: error: SSH2 library not found
46 | sudo apt -y install libssh2-1-dev
47 |
48 | # configure: error: Unable to use libevent (libevent check failed)
49 | sudo apt -y install libevent-dev
50 |
51 | # configure: error: Curl library not found
52 | sudo apt -y install libcurl4-openssl-dev
53 |
54 | # configure: error: Unable to use libpcre (libpcre check failed)
55 | sudo apt -y install libpcre3-dev
56 |
57 | # configure: error: Unable to find "go" executable in path
58 | sudo apt -y install golang
59 |
60 | # configure: error: Unable to find "javac" executable in path
61 | sudo apt -y install openjdk-8-jdk
62 |
63 |
64 | # install services
65 | # http://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix/zabbix-proxy-sqlite3_5.0.2-1%2Bfocal_amd64.deb
66 |
67 |
68 | # instll init.d
69 | cd /etc/init.d
70 | cat << 'EOF' > zabbix-proxy
71 | #! /bin/sh
72 | ### BEGIN INIT INFO
73 | # Provides: zabbix-proxy
74 | # Required-Start: $remote_fs $network
75 | # Required-Stop: $remote_fs
76 | # Default-Start: 2 3 4 5
77 | # Default-Stop: 0 1 6
78 | # Short-Description: Start zabbix-proxy daemon
79 | ### END INIT INFO
80 |
81 | set -e
82 |
83 | NAME=zabbix_proxy
84 | DAEMON=/usr/sbin/$NAME
85 | DESC="Zabbix proxy daemon"
86 |
87 | test -x $DAEMON || exit 0
88 |
89 | DIR=/run/zabbix
90 | PID=$DIR/$NAME.pid
91 | RETRY=15
92 |
93 | if test ! -d "$DIR"; then
94 | mkdir -p "$DIR"
95 | chown -R zabbix:zabbix "$DIR"
96 | fi
97 |
98 | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
99 |
100 | # define LSB log_* functions.
101 | . /lib/lsb/init-functions
102 |
103 | if [ -r "/etc/default/zabbix-proxy" ]; then
104 | . /etc/default/zabbix-proxy
105 | fi
106 |
107 | case "$1" in
108 | start)
109 | log_daemon_msg "Starting $DESC" "$NAME"
110 | start-stop-daemon --oknodo --start --pidfile $PID \
111 | --exec $DAEMON >/dev/null 2>&1
112 | case "$?" in
113 | 0) log_end_msg 0 ;;
114 | *) log_end_msg 1; exit 1 ;;
115 | esac
116 | ;;
117 | stop)
118 | log_daemon_msg "Stopping $DESC" "$NAME"
119 | start-stop-daemon --oknodo --stop --pidfile $PID --retry $RETRY
120 | case "$?" in
121 | 0) log_end_msg 0 ;;
122 | *) log_end_msg 1; exit 1 ;;
123 | esac
124 | ;;
125 | status)
126 | status_of_proc -p "$PID" "$DAEMON" "$NAME" && exit 0 || exit $?
127 | ;;
128 | restart|force-reload)
129 | $0 stop
130 | $0 start
131 | ;;
132 | *)
133 | echo "Usage: $0 {start|stop|restart|force-reload}" >&2
134 | exit 1
135 | ;;
136 | esac
137 |
138 | exit 0
139 |
140 | EOF
141 |
142 | # or
143 | # echo "IyEgL2Jpbi9zaAojIyMgQkVHSU4gSU5JVCBJTkZPCiMgUHJvdmlkZXM6ICAgICAgICAgIHphYmJpeC1wcm94eQojIFJlcXVpcmVkLVN0YXJ0OiAgICAkcmVtb3RlX2ZzICRuZXR3b3JrIAojIFJlcXVpcmVkLVN0b3A6ICAgICAkcmVtb3RlX2ZzCiMgRGVmYXVsdC1TdGFydDogICAgIDIgMyA0IDUKIyBEZWZhdWx0LVN0b3A6ICAgICAgMCAxIDYKIyBTaG9ydC1EZXNjcmlwdGlvbjogU3RhcnQgemFiYml4LXByb3h5IGRhZW1vbgojIyMgRU5EIElOSVQgSU5GTwoKc2V0IC1lCgpOQU1FPXphYmJpeF9wcm94eQpEQUVNT049L3Vzci9zYmluLyROQU1FCkRFU0M9IlphYmJpeCBwcm94eSBkYWVtb24iCgp0ZXN0IC14ICREQUVNT04gfHwgZXhpdCAwCgpESVI9L3J1bi96YWJiaXgKUElEPSRESVIvJE5BTUUucGlkClJFVFJZPTE1CgppZiB0ZXN0ICEgLWQgIiRESVIiOyB0aGVuCiAgbWtkaXIgLXAgIiRESVIiCiAgY2hvd24gLVIgemFiYml4OnphYmJpeCAiJERJUiIKZmkKCmV4cG9ydCBQQVRIPSIke1BBVEg6KyRQQVRIOn0vdXNyL3NiaW46L3NiaW4iCgojIGRlZmluZSBMU0IgbG9nXyogZnVuY3Rpb25zLgouIC9saWIvbHNiL2luaXQtZnVuY3Rpb25zCgppZiBbIC1yICIvZXRjL2RlZmF1bHQvemFiYml4LXByb3h5IiBdOyB0aGVuCiAgICAuIC9ldGMvZGVmYXVsdC96YWJiaXgtcHJveHkKZmkKCmNhc2UgIiQxIiBpbgogIHN0YXJ0KQogICAgbG9nX2RhZW1vbl9tc2cgIlN0YXJ0aW5nICRERVNDIiAiJE5BTUUiCiAgICBzdGFydC1zdG9wLWRhZW1vbiAtLW9rbm9kbyAtLXN0YXJ0IC0tcGlkZmlsZSAkUElEIFwKICAgICAgLS1leGVjICREQUVNT04gPi9kZXYvbnVsbCAyPiYxCiAgICBjYXNlICIkPyIgaW4KICAgICAgICAwKSBsb2dfZW5kX21zZyAwIDs7CiAgICAgICAgKikgbG9nX2VuZF9tc2cgMTsgZXhpdCAxIDs7CiAgICBlc2FjCiAgICA7OwogIHN0b3ApCiAgICBsb2dfZGFlbW9uX21zZyAiU3RvcHBpbmcgJERFU0MiICIkTkFNRSIKICAgIHN0YXJ0LXN0b3AtZGFlbW9uIC0tb2tub2RvIC0tc3RvcCAtLXBpZGZpbGUgJFBJRCAtLXJldHJ5ICRSRVRSWQogICAgY2FzZSAiJD8iIGluCiAgICAgICAgMCkgbG9nX2VuZF9tc2cgMCA7OwogICAgICAgICopIGxvZ19lbmRfbXNnIDE7IGV4aXQgMSA7OwogICAgZXNhYwogICAgOzsKICBzdGF0dXMpCiAgICBzdGF0dXNfb2ZfcHJvYyAtcCAiJFBJRCIgIiREQUVNT04iICIkTkFNRSIgJiYgZXhpdCAwIHx8IGV4aXQgJD8KICAgIDs7CiAgcmVzdGFydHxmb3JjZS1yZWxvYWQpCiAgICAkMCBzdG9wCiAgICAkMCBzdGFydAogICAgOzsKICAqKQogICAgZWNobyAiVXNhZ2U6ICQwIHtzdGFydHxzdG9wfHJlc3RhcnR8Zm9yY2UtcmVsb2FkfSIgPiYyCiAgICBleGl0IDEKICAgIDs7CmVzYWMKCmV4aXQgMAo=" | base64 --decode > /etc/init.d/zabbix-proxy
144 | chmod 755 /etc/init.d/zabbix-proxy
145 |
146 |
147 |
148 | cd /lib/systemd/system
149 | cat << 'EOF' > zabbix-proxy.service
150 | [Unit]
151 | Description=Zabbix Proxy
152 | After=syslog.target
153 | After=network.target
154 |
155 | [Service]
156 | Environment="CONFFILE=/etc/zabbix/zabbix_proxy.conf"
157 | EnvironmentFile=-/etc/default/zabbix-proxy
158 | Type=forking
159 | Restart=on-failure
160 | PIDFile=/run/zabbix/zabbix_proxy.pid
161 | KillMode=control-group
162 | ExecStart=/usr/sbin/zabbix_proxy -c $CONFFILE
163 | ExecStop=/bin/kill -SIGTERM $MAINPID
164 | RestartSec=10s
165 | TimeoutSec=infinity
166 |
167 | [Install]
168 | WantedBy=multi-user.target
169 |
170 | EOF
171 |
172 | # or
173 | # echo "W1VuaXRdCkRlc2NyaXB0aW9uPVphYmJpeCBQcm94eQpBZnRlcj1zeXNsb2cudGFyZ2V0CkFmdGVyPW5ldHdvcmsudGFyZ2V0CgpbU2VydmljZV0KRW52aXJvbm1lbnQ9IkNPTkZGSUxFPS9ldGMvemFiYml4L3phYmJpeF9wcm94eS5jb25mIgpFbnZpcm9ubWVudEZpbGU9LS9ldGMvZGVmYXVsdC96YWJiaXgtcHJveHkKVHlwZT1mb3JraW5nClJlc3RhcnQ9b24tZmFpbHVyZQpQSURGaWxlPS9ydW4vemFiYml4L3phYmJpeF9wcm94eS5waWQKS2lsbE1vZGU9Y29udHJvbC1ncm91cApFeGVjU3RhcnQ9L3Vzci9zYmluL3phYmJpeF9wcm94eSAtYyAkQ09ORkZJTEUKRXhlY1N0b3A9L2Jpbi9raWxsIC1TSUdURVJNICRNQUlOUElEClJlc3RhcnRTZWM9MTBzClRpbWVvdXRTZWM9aW5maW5pdHkKCltJbnN0YWxsXQpXYW50ZWRCeT1tdWx0aS11c2VyLnRhcmdldAo=" | base64 --decode > /lib/systemd/system/zabbix-proxy.service
174 |
175 | # reload systemd cache
176 | systemctl daemon-reload
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 | # instll init.d
185 | cd /etc/init.d
186 | cat << 'EOF' > zabbix-agent
187 | #! /bin/sh
188 | ### BEGIN INIT INFO
189 | # Provides: zabbix-agent
190 | # Required-Start: $remote_fs $network
191 | # Required-Stop: $remote_fs
192 | # Default-Start: 2 3 4 5
193 | # Default-Stop: 0 1 6
194 | # Short-Description: Start zabbix-agent daemon
195 | ### END INIT INFO
196 |
197 | set -e
198 |
199 | NAME=zabbix_agentd
200 | DAEMON=/usr/sbin/$NAME
201 | DESC="Zabbix agent"
202 |
203 | test -x $DAEMON || exit 0
204 |
205 | DIR=/run/zabbix
206 | PID=$DIR/$NAME.pid
207 | RETRY=15
208 |
209 | if test ! -d "$DIR"; then
210 | mkdir -p "$DIR"
211 | chown -R zabbix:zabbix "$DIR"
212 | fi
213 |
214 | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
215 |
216 | # define LSB log_* functions.
217 | . /lib/lsb/init-functions
218 |
219 | if [ -r "/etc/default/zabbix-agent" ]; then
220 | . /etc/default/zabbix-agent
221 | fi
222 |
223 | case "$1" in
224 | start)
225 | log_daemon_msg "Starting $DESC" "$NAME"
226 | start-stop-daemon --oknodo --start --pidfile $PID --exec $DAEMON >/dev/null 2>&1
227 | case "$?" in
228 | 0) log_end_msg 0 ;;
229 | *) log_end_msg 1; exit 1 ;;
230 | esac
231 | ;;
232 | stop)
233 | log_daemon_msg "Stopping $DESC" "$NAME"
234 | start-stop-daemon --oknodo --stop --pidfile $PID --retry $RETRY
235 | case "$?" in
236 | 0) log_end_msg 0 ;;
237 | *) log_end_msg 1; exit 1 ;;
238 | esac
239 | ;;
240 | status)
241 | status_of_proc -p "$PID" "$DAEMON" "$NAME" && exit 0 || exit $?
242 | ;;
243 | restart|force-reload)
244 | $0 stop
245 | $0 start
246 | ;;
247 | *)
248 | echo "Usage: $0 {start|stop|restart|force-reload}" >&2
249 | exit 1
250 | ;;
251 | esac
252 |
253 | exit 0
254 |
255 | EOF
256 |
257 | # or
258 | # echo "IyEgL2Jpbi9zaAojIyMgQkVHSU4gSU5JVCBJTkZPCiMgUHJvdmlkZXM6ICAgICAgICAgIHphYmJpeC1hZ2VudAojIFJlcXVpcmVkLVN0YXJ0OiAgICAkcmVtb3RlX2ZzICRuZXR3b3JrIAojIFJlcXVpcmVkLVN0b3A6ICAgICAkcmVtb3RlX2ZzCiMgRGVmYXVsdC1TdGFydDogICAgIDIgMyA0IDUKIyBEZWZhdWx0LVN0b3A6ICAgICAgMCAxIDYKIyBTaG9ydC1EZXNjcmlwdGlvbjogU3RhcnQgemFiYml4LWFnZW50IGRhZW1vbgojIyMgRU5EIElOSVQgSU5GTwoKc2V0IC1lCgpOQU1FPXphYmJpeF9hZ2VudGQKREFFTU9OPS91c3Ivc2Jpbi8kTkFNRQpERVNDPSJaYWJiaXggYWdlbnQiCgp0ZXN0IC14ICREQUVNT04gfHwgZXhpdCAwCgpESVI9L3J1bi96YWJiaXgKUElEPSRESVIvJE5BTUUucGlkClJFVFJZPTE1CgppZiB0ZXN0ICEgLWQgIiRESVIiOyB0aGVuCiAgbWtkaXIgLXAgIiRESVIiCiAgY2hvd24gLVIgemFiYml4OnphYmJpeCAiJERJUiIKZmkKCmV4cG9ydCBQQVRIPSIke1BBVEg6KyRQQVRIOn0vdXNyL3NiaW46L3NiaW4iCgojIGRlZmluZSBMU0IgbG9nXyogZnVuY3Rpb25zLgouIC9saWIvbHNiL2luaXQtZnVuY3Rpb25zCgppZiBbIC1yICIvZXRjL2RlZmF1bHQvemFiYml4LWFnZW50IiBdOyB0aGVuCiAgICAuIC9ldGMvZGVmYXVsdC96YWJiaXgtYWdlbnQKZmkKCmNhc2UgIiQxIiBpbgogIHN0YXJ0KQogICAgbG9nX2RhZW1vbl9tc2cgIlN0YXJ0aW5nICRERVNDIiAiJE5BTUUiCiAgICBzdGFydC1zdG9wLWRhZW1vbiAtLW9rbm9kbyAtLXN0YXJ0IC0tcGlkZmlsZSAkUElEIC0tZXhlYyAkREFFTU9OID4vZGV2L251bGwgMj4mMQogICAgY2FzZSAiJD8iIGluCiAgICAgICAgMCkgbG9nX2VuZF9tc2cgMCA7OwogICAgICAgICopIGxvZ19lbmRfbXNnIDE7IGV4aXQgMSA7OwogICAgZXNhYwogICAgOzsKICBzdG9wKQogICAgbG9nX2RhZW1vbl9tc2cgIlN0b3BwaW5nICRERVNDIiAiJE5BTUUiCiAgICBzdGFydC1zdG9wLWRhZW1vbiAtLW9rbm9kbyAtLXN0b3AgLS1waWRmaWxlICRQSUQgLS1yZXRyeSAkUkVUUlkKICAgIGNhc2UgIiQ/IiBpbgogICAgICAgIDApIGxvZ19lbmRfbXNnIDAgOzsKICAgICAgICAqKSBsb2dfZW5kX21zZyAxOyBleGl0IDEgOzsKICAgIGVzYWMKICAgIDs7CiAgc3RhdHVzKQogICAgc3RhdHVzX29mX3Byb2MgLXAgIiRQSUQiICIkREFFTU9OIiAiJE5BTUUiICYmIGV4aXQgMCB8fCBleGl0ICQ/CiAgICA7OwogIHJlc3RhcnR8Zm9yY2UtcmVsb2FkKQogICAgJDAgc3RvcAogICAgJDAgc3RhcnQKICAgIDs7CiAgKikKICAgIGVjaG8gIlVzYWdlOiAkMCB7c3RhcnR8c3RvcHxyZXN0YXJ0fGZvcmNlLXJlbG9hZH0iID4mMgogICAgZXhpdCAxCiAgICA7Owplc2FjCgpleGl0IDAK" | base64 --decode > /etc/init.d/zabbix-agent
259 | chmod 755 /etc/init.d/zabbix-agent
260 |
261 |
262 |
263 |
264 | cd /lib/systemd/system
265 | cat << 'EOF' > zabbix-agent.service
266 | [Unit]
267 | Description=Zabbix Agent
268 | After=syslog.target
269 | After=network.target
270 |
271 | [Service]
272 | Environment="CONFFILE=/etc/zabbix/zabbix_agentd.conf"
273 | EnvironmentFile=-/etc/default/zabbix-agent
274 | Type=forking
275 | Restart=on-failure
276 | PIDFile=/run/zabbix/zabbix_agentd.pid
277 | KillMode=control-group
278 | ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE
279 | ExecStop=/bin/kill -SIGTERM $MAINPID
280 | RestartSec=10s
281 | User=zabbix
282 | Group=zabbix
283 |
284 | [Install]
285 | WantedBy=multi-user.target
286 |
287 | EOF
288 |
289 | # or
290 | # echo "W1VuaXRdCkRlc2NyaXB0aW9uPVphYmJpeCBBZ2VudApBZnRlcj1zeXNsb2cudGFyZ2V0CkFmdGVyPW5ldHdvcmsudGFyZ2V0CgpbU2VydmljZV0KRW52aXJvbm1lbnQ9IkNPTkZGSUxFPS9ldGMvemFiYml4L3phYmJpeF9hZ2VudGQuY29uZiIKRW52aXJvbm1lbnRGaWxlPS0vZXRjL2RlZmF1bHQvemFiYml4LWFnZW50ClR5cGU9Zm9ya2luZwpSZXN0YXJ0PW9uLWZhaWx1cmUKUElERmlsZT0vcnVuL3phYmJpeC96YWJiaXhfYWdlbnRkLnBpZApLaWxsTW9kZT1jb250cm9sLWdyb3VwCkV4ZWNTdGFydD0vdXNyL3NiaW4vemFiYml4X2FnZW50ZCAtYyAkQ09ORkZJTEUKRXhlY1N0b3A9L2Jpbi9raWxsIC1TSUdURVJNICRNQUlOUElEClJlc3RhcnRTZWM9MTBzClVzZXI9emFiYml4Ckdyb3VwPXphYmJpeAoKW0luc3RhbGxdCldhbnRlZEJ5PW11bHRpLXVzZXIudGFyZ2V0Cg==" | base64 --decode > /lib/systemd/system/zabbix-agent.service
291 |
292 | # reload systemd cache
293 | systemctl daemon-reload
294 |
295 |
296 |
297 | # instll init.d
298 | cd /etc/init.d
299 | cat << 'EOF' > zabbix-agent2
300 | #! /bin/sh
301 | ### BEGIN INIT INFO
302 | # Provides: zabbix-agent2
303 | # Required-Start: $remote_fs $network
304 | # Required-Stop: $remote_fs
305 | # Default-Start: 2 3 4 5
306 | # Default-Stop: 0 1 6
307 | # Short-Description: Start zabbix-agent2 daemon
308 | ### END INIT INFO
309 |
310 | set -e
311 |
312 | NAME=zabbix_agent2
313 | DAEMON=/usr/sbin/$NAME
314 | DESC="Zabbix agent"
315 |
316 | test -x $DAEMON || exit 0
317 |
318 | DIR=/run/zabbix
319 | PID=$DIR/$NAME.pid
320 | RETRY=15
321 |
322 | if test ! -d "$DIR"; then
323 | mkdir -p "$DIR"
324 | chown -R zabbix:zabbix "$DIR"
325 | fi
326 |
327 | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
328 |
329 | # define LSB log_* functions.
330 | . /lib/lsb/init-functions
331 |
332 | if [ -r "/etc/default/zabbix-agent2" ]; then
333 | . /etc/default/zabbix-agent2
334 | fi
335 |
336 | case "$1" in
337 | start)
338 | log_daemon_msg "Starting $DESC" "$NAME"
339 | start-stop-daemon --oknodo --start --pidfile $PID --exec $DAEMON >/dev/null 2>&1
340 | case "$?" in
341 | 0) log_end_msg 0 ;;
342 | *) log_end_msg 1; exit 1 ;;
343 | esac
344 | ;;
345 | stop)
346 | log_daemon_msg "Stopping $DESC" "$NAME"
347 | start-stop-daemon --oknodo --stop --pidfile $PID --retry $RETRY
348 | case "$?" in
349 | 0) log_end_msg 0 ;;
350 | *) log_end_msg 1; exit 1 ;;
351 | esac
352 | ;;
353 | status)
354 | status_of_proc -p "$PID" "$DAEMON" "$NAME" && exit 0 || exit $?
355 | ;;
356 | restart|force-reload)
357 | $0 stop
358 | $0 start
359 | ;;
360 | *)
361 | echo "Usage: $0 {start|stop|restart|force-reload}" >&2
362 | exit 1
363 | ;;
364 | esac
365 |
366 | exit 0
367 |
368 | EOF
369 |
370 | # or
371 | # echo "IyEgL2Jpbi9zaAojIyMgQkVHSU4gSU5JVCBJTkZPCiMgUHJvdmlkZXM6ICAgICAgICAgIHphYmJpeC1hZ2VudDIKIyBSZXF1aXJlZC1TdGFydDogICAgJHJlbW90ZV9mcyAkbmV0d29yayAKIyBSZXF1aXJlZC1TdG9wOiAgICAgJHJlbW90ZV9mcwojIERlZmF1bHQtU3RhcnQ6ICAgICAyIDMgNCA1CiMgRGVmYXVsdC1TdG9wOiAgICAgIDAgMSA2CiMgU2hvcnQtRGVzY3JpcHRpb246IFN0YXJ0IHphYmJpeC1hZ2VudDIgZGFlbW9uCiMjIyBFTkQgSU5JVCBJTkZPCgpzZXQgLWUKCk5BTUU9emFiYml4X2FnZW50MgpEQUVNT049L3Vzci9zYmluLyROQU1FCkRFU0M9IlphYmJpeCBhZ2VudCIKCnRlc3QgLXggJERBRU1PTiB8fCBleGl0IDAKCkRJUj0vcnVuL3phYmJpeApQSUQ9JERJUi8kTkFNRS5waWQKUkVUUlk9MTUKCmlmIHRlc3QgISAtZCAiJERJUiI7IHRoZW4KICBta2RpciAtcCAiJERJUiIKICBjaG93biAtUiB6YWJiaXg6emFiYml4ICIkRElSIgpmaQoKZXhwb3J0IFBBVEg9IiR7UEFUSDorJFBBVEg6fS91c3Ivc2Jpbjovc2JpbiIKCiMgZGVmaW5lIExTQiBsb2dfKiBmdW5jdGlvbnMuCi4gL2xpYi9sc2IvaW5pdC1mdW5jdGlvbnMKCmlmIFsgLXIgIi9ldGMvZGVmYXVsdC96YWJiaXgtYWdlbnQyIiBdOyB0aGVuCiAgICAuIC9ldGMvZGVmYXVsdC96YWJiaXgtYWdlbnQyCmZpCgpjYXNlICIkMSIgaW4KICBzdGFydCkKICAgIGxvZ19kYWVtb25fbXNnICJTdGFydGluZyAkREVTQyIgIiROQU1FIgogICAgc3RhcnQtc3RvcC1kYWVtb24gLS1va25vZG8gLS1zdGFydCAtLXBpZGZpbGUgJFBJRCAtLWV4ZWMgJERBRU1PTiA+L2Rldi9udWxsIDI+JjEKICAgIGNhc2UgIiQ/IiBpbgogICAgICAgIDApIGxvZ19lbmRfbXNnIDAgOzsKICAgICAgICAqKSBsb2dfZW5kX21zZyAxOyBleGl0IDEgOzsKICAgIGVzYWMKICAgIDs7CiAgc3RvcCkKICAgIGxvZ19kYWVtb25fbXNnICJTdG9wcGluZyAkREVTQyIgIiROQU1FIgogICAgc3RhcnQtc3RvcC1kYWVtb24gLS1va25vZG8gLS1zdG9wIC0tcGlkZmlsZSAkUElEIC0tcmV0cnkgJFJFVFJZCiAgICBjYXNlICIkPyIgaW4KICAgICAgICAwKSBsb2dfZW5kX21zZyAwIDs7CiAgICAgICAgKikgbG9nX2VuZF9tc2cgMTsgZXhpdCAxIDs7CiAgICBlc2FjCiAgICA7OwogIHN0YXR1cykKICAgIHN0YXR1c19vZl9wcm9jIC1wICIkUElEIiAiJERBRU1PTiIgIiROQU1FIiAmJiBleGl0IDAgfHwgZXhpdCAkPwogICAgOzsKICByZXN0YXJ0fGZvcmNlLXJlbG9hZCkKICAgICQwIHN0b3AKICAgICQwIHN0YXJ0CiAgICA7OwogICopCiAgICBlY2hvICJVc2FnZTogJDAge3N0YXJ0fHN0b3B8cmVzdGFydHxmb3JjZS1yZWxvYWR9IiA+JjIKICAgIGV4aXQgMQogICAgOzsKZXNhYwoKZXhpdCAwCg==" | base64 --decode > /etc/init.d/zabbix-agent2
372 | chmod 755 /etc/init.d/zabbix-agent2
373 |
374 |
375 |
376 |
377 | cd /lib/systemd/system
378 | cat << 'EOF' > zabbix-agent2.service
379 | [Unit]
380 | Description=Zabbix Agent 2
381 | After=syslog.target
382 | After=network.target
383 |
384 | [Service]
385 | Environment="CONFFILE=/etc/zabbix/zabbix_agent2.conf"
386 | EnvironmentFile=-/etc/default/zabbix-agent2
387 | Type=simple
388 | Restart=on-failure
389 | PIDFile=/run/zabbix/zabbix_agent2.pid
390 | KillMode=control-group
391 | ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE
392 | ExecStop=/bin/kill -SIGTERM $MAINPID
393 | RestartSec=10s
394 | User=zabbix
395 | Group=zabbix
396 |
397 | [Install]
398 | WantedBy=multi-user.target
399 |
400 | EOF
401 |
402 | # or
403 | # echo "W1VuaXRdCkRlc2NyaXB0aW9uPVphYmJpeCBBZ2VudCAyCkFmdGVyPXN5c2xvZy50YXJnZXQKQWZ0ZXI9bmV0d29yay50YXJnZXQKCltTZXJ2aWNlXQpFbnZpcm9ubWVudD0iQ09ORkZJTEU9L2V0Yy96YWJiaXgvemFiYml4X2FnZW50Mi5jb25mIgpFbnZpcm9ubWVudEZpbGU9LS9ldGMvZGVmYXVsdC96YWJiaXgtYWdlbnQyClR5cGU9c2ltcGxlClJlc3RhcnQ9b24tZmFpbHVyZQpQSURGaWxlPS9ydW4vemFiYml4L3phYmJpeF9hZ2VudDIucGlkCktpbGxNb2RlPWNvbnRyb2wtZ3JvdXAKRXhlY1N0YXJ0PS91c3Ivc2Jpbi96YWJiaXhfYWdlbnQyIC1jICRDT05GRklMRQpFeGVjU3RvcD0vYmluL2tpbGwgLVNJR1RFUk0gJE1BSU5QSUQKUmVzdGFydFNlYz0xMHMKVXNlcj16YWJiaXgKR3JvdXA9emFiYml4CgpbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQK" | base64 --decode > /lib/systemd/system/zabbix-agent2.service
404 |
405 | # reload systemd cache
406 | systemctl daemon-reload
407 |
408 |
409 |
--------------------------------------------------------------------------------