| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | #!/bin/shecho -e '\033[35m _____         __    __    _/__  /  ____ _/ /_  / /_  (_)  __  / /  / __ `/ __ \/ __ \/ / |/_/ / /__/ /_/ / /_/ / /_/ / />  </____/\__,_/_.___/_.___/_/_/|_|\033[0m'if [ "$EUID" -ne 0 ]; then  echo "Please run as root"  exitfi# get the current position_cwd="$(pwd)"# check for assets forlder_assets="$_cwd/assets"if [ ! -d "$_assets" ]; then  _assets="$_cwd/../assets"  if [ ! -d "$_assets" ]; then    echo "!! can't find assets directory !!"    exit  fifiwget -P /tmp/ http://repo.zabbix.com/zabbix/3.4/debian/pool/main/z/zabbix-release/zabbix-release_3.4-1+stretch_all.debdpkg -i /tmp/zabbix-release_3.4-1+stretch_all.debapt-get update -yapt-get install zabbix-agent -y# configureecho -n "Please provide the current server's public ip : "read _cur_ipecho -n "Please provide the zabbix-server's ip : "read _ipecho -n "Please provide the hostname of this agent : "read _host_nameecho -n "Please provide the mysql root password : "read _root_mysql_passwd_agent_conf_d="/etc/zabbix/zabbix_agentd.d" # for debian 8if [ ! -d "$_agent_conf_d" ]; then  _agent_conf_d="/etc/zabbix/zabbix_agentd.conf.d" # for debian 9fi# configure zabbix agentsed -i "s#Server=127.0.0.1#Server=$_ip#g" /etc/zabbix/zabbix_agentd.confsed -i "s#ServerActive=127.0.0.1#ServerActive=$_ip#g" /etc/zabbix/zabbix_agentd.confsed -i "s#Hostname=Zabbix server#Hostname=$_host_name#g" /etc/zabbix/zabbix_agentd.conf# APT# check for debian security updates# not working : https://www.osso.nl/blog/zabbix-counting-security-updates# https://github.com/theranger/zabbix-apt# enable automatic update of aptcp "$_assets"/zabbix/misc/02periodic /etc/apt/apt.conf.d/cp "$_assets"/zabbix/apt.conf "$_agent_conf_d"/# MYSQL# https://serverfault.com/questions/737018/zabbix-user-parameter-mysql-status-setting-home# create zabbix user homemkdir /var/lib/zabbix# generate random password for zabbix mysql user_passwd="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12)"# add mysql credentials to zabbix homeprintf "[client]\nuser=zabbix\npassword=$_passwd" > /var/lib/zabbix/.my.cnf# create zabbix mysql usermysql -uroot -p"$_root_mysql_passwd" -e "CREATE USER 'zabbix' IDENTIFIED BY '$_passwd';"mysql -uroot -p"$_root_mysql_passwd" -e "GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY '$_passwd';"# add zabbix-agent parametercp "$_assets"/zabbix/userparameter_mysql.conf "$_agent_conf_d"/# NGINX# https://github.com/sfuerte/zbx-nginx# nginxconf already included in default.nginxconf assetsed -i "s/# allow CURRENT-SERVER-IP/allow $_cur_ip/g" /etc/nginx/sites-available/defaultcp "$_assets"/zabbix/userparameter_nginx.conf "$_agent_conf_d"/mkdir /etc/zabbix/zabbix_agentd.scriptscp "$_assets"/zabbix/scripts/nginx-stat.py /etc/zabbix/zabbix_agentd.scripts/chmod +x /etc/zabbix/zabbix_agentd.scripts/nginx-stat.pyecho -n "This is box is a proxmox CT? [Y|n] "read ynyn=${yn:-y}if [ "$yn" = "Y" ] || [ "$yn" = "y" ]; then  cp "$_assets"/zabbix/proxmox-ct.conf "$_agent_conf_d"/fi# SYSTEMDcp "$_assets"/zabbix/userparameter_systemd_services.conf "$_agent_conf_d"/# TODO add modules path to agent ??# allow comm. port with zabbix-serverufw allow from "$_ip" to any port 10050ufw allow from "$_ip" to any port 22# ufw allow from "$_ip" to any port 10051# iptables -A INPUT -p tcp -m tcp --dport 10050 -j ACCEPTsystemctl restart zabbix-agentsystemctl enable zabbix-agentecho -e "\033[92;1mZabbix-agent installed and configured, please add the host $_host_name in your zabbix-server \033[Om"echo -e "\033[92;1mAnd import requested templates in assets/zabbix/templates/ \033[Om"echo -e "\033[92;1mzabbix user mysql password is $_passwd \033[Om"
 |