Last active
March 3, 2017 16:08
-
-
Save jn0/98d6c2588ed71dc29b9d70985d5662cc to your computer and use it in GitHub Desktop.
Install zabbix 3.0.7 with PostgreSQL 9.5 on a CentOS 7 host in "almost automatic" mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script is supposed to be ran on the TARGET machine as "root" user. | |
# | |
# this one was useful: https://gist.github.com/sebastianwebber/5f7dd76d0b7eabb1d388fbfdcbafebda | |
# | |
# NB: It will DROP the existing database and create a fresh one! | |
# NB: It will losen access restrictions to dumb passwords, etc. | |
# | |
set -e # fail on any error! | |
test -w /etc/passwd | |
#-------------------------------------------------------------------------------------------------- | |
echo 'Install PostgreSQL 9.5 first' | |
if yum -y -q repolist | grep -i postgres; then | |
echo pg repo already here | |
else | |
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm | |
yum -y update | |
fi | |
if [ -z "$(type -p psql)" ]; then | |
yum -y install postgresql95-server postgresql95 postgresql95-contrib | |
/usr/pgsql-9.5/bin/postgresql95-setup initdb | |
test -d /var/lib/pgsql/9.5/data/. | |
cp /var/lib/pgsql/9.5/data/pg_hba.conf /var/lib/pgsql/9.5/data/pg_hba.conf.save | |
sed -e '1,$s/^\([^#]\+\)[ \t]\+[a-z]\+$/\1 trust/' -i /var/lib/pgsql/9.5/data/pg_hba.conf | |
systemctl start postgresql-9.5 | |
systemctl enable postgresql-9.5 | |
fi | |
#-------------------------------------------------------------------------------------------------- | |
echo 'Install PHP comes then' | |
yum -y install php php-cli php-common php-devel php-pear php-gd php-mbstring php-pgsql php-xml | |
#-------------------------------------------------------------------------------------------------- | |
echo "Now it's time for zabbix" | |
if yum -y -q repolist | grep -i zabbix; then | |
echo php repo already here | |
else | |
rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX | |
rpm -ivh 'http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm' | |
yum -y update | |
fi | |
yum -y install zabbix-server-pgsql zabbix-web-pgsql zabbix-agent zabbix-java-gateway zabbix-get | |
echo "..configure zabbix DB" | |
if su -s /bin/bash -c 'echo \\du|psql -U postgres -A' postgres | grep '^zabbix'; then | |
echo ....zabbix pg user already exists | |
else | |
echo ....creating zabbix pg user | |
su -s /bin/bash -c 'echo create user zabbix\;|psql -U postgres -A' postgres | |
fi | |
if su -s /bin/bash -c 'psql -U postgres -lA' postgres | grep '^zabbix'; then | |
echo ....zabbix DB already there -- dropping | |
systemctl stop zabbix-agent | |
systemctl stop zabbix-server | |
su -s /bin/bash -c 'echo drop database zabbix\; | psql -U postgres' postgres | |
fi | |
echo ..creating zabbix db... | |
su -s /bin/bash -c 'echo create database zabbix owner zabbix\; | psql -U postgres' postgres | |
gzip -dc /usr/share/doc/zabbix-server-pgsql-3.0.*/create.sql.gz \ | |
| su -s /bin/bash -c "psql -U zabbix zabbix" zabbix 2>/tmp/pgsetup.log | |
echo /etc/zabbix/zabbix_server.conf | |
test -f /etc/zabbix/zabbix_server.conf | |
ls -l /etc/zabbix/zabbix_server.conf | |
sed -e '1,$s/^[# \t]*DBHost=.*$/DBHost=localhost/' \ | |
-e '1,$s/^[# \t]*DBName=.*$/DBName=zabbix/' \ | |
-e '1,$s/^[# \t]*DBUser=.*$/DBUser=zabbix/' \ | |
-e '1,$s/^[# \t]*DBPassword=.*$/DBPassword=xibbaz/' \ | |
-i /etc/zabbix/zabbix_server.conf | |
grep -v '^#' /etc/zabbix/zabbix_server.conf | grep -v '^[ \t]*$' | cat -An | |
systemctl start zabbix-server | |
systemctl enable zabbix-server | |
systemctl start zabbix-agent | |
systemctl enable zabbix-agent | |
systemctl restart httpd | |
echo /etc/httpd/conf.d/zabbix.conf | |
test -f /etc/httpd/conf.d/zabbix.conf | |
sed -e '1,$s/# php_value date.timezone .*$/php_value date.timezone Europe\/Moscow/g' \ | |
-i /etc/httpd/conf.d/zabbix.conf | |
grep -v '^#' /etc/httpd/conf.d/zabbix.conf | grep -v '^[ \t]*$' | cat -An | |
systemctl restart httpd | |
firewall-cmd --permanent --add-port=10050/tcp | |
firewall-cmd --permanent --add-port=10051/tcp | |
systemctl restart firewalld | |
if [ "$(getenforce)" = 'Enforcing' ]; then | |
setsebool -P httpd_can_connect_zabbix on | |
setsebool -P httpd_can_network_connect_db on | |
systemctl restart httpd | |
fi | |
#-------------------------------------------------------------------------------------------------- | |
echo "====================================================" | |
echo "NOW CONFIGURE ZABBIX WEB FRONTEND VIA BROWSER USING:" | |
grep -v '^#' /etc/zabbix/zabbix_server.conf | grep -v '^[ \t]*$' | cat -An | |
echo "====================================================" | |
# EOF # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment