One-click implementation of basic installation of zabbix based on LNMP architecture
#! / bin/bash# easy installation zabbix+LNMP#lnmp () {# disable firewall & core security features systemctl stop firewalld.servicesystemctl disable firewalld.service & > / dev/nullsetenforce 0sed-I "7cSELINUX=disabled" / etc/sysconfig/selinux#yum install nginxwget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm# manually create nginx installation source (centos can be replaced according to different systems Later versions are the same) echo "[nginx] name=nginx repobaseurl= http://nginx.org/packages/centos/7/\$basearch/gpgcheck=0enabled=1" > / etc/yum.repos.d/nginx.repoyum install nginx-y # launch nginxsystemctl start nginxsystemctl enable nginx# install mysql 5.7and launch yum install-y mariadb-server mariadb expectsystemctl enable mariadb.servicesystemctl start mariadb.service# to set database initial password / usr/bin/expect / dev/nullif [$?-ne 0] Then yum install-y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysqlelse breakfidone# modifies the fpm module to support nginxsed-I-e "8cuser = nginx"-e "10cgroup = nginx" / etc/php-fpm.d/www.conf# changes the nginx configuration file so that it can recognize the php dynamic file sed-I "10s/index.html/index.html index.php/" / etc/nginx/conf.d/default.confsed-I-e "30rem 36s / # / "- e" 31s/html/\ / usr\ / share\ / nginx\ / html/ "- e" 34s/\ / scripts/\ $document_root/ "/ etc/nginx/conf.d/default.conf# configuration PHPsed-I-e" 359s/On/Off/ "- e" 202s/Off/On/ "/ etc/php.ini# restart Service systemctl start php-fpmsystemctl enable php-fpmsystemctl restart nginx} # check whether the LNMP architecture has been installed Bi systemctl restart nginx & > / dev/nullservice mysqld restart & > / dev/nullsystemctl restart mariadb & > / dev/nullnetstat-atnp | egrep'(nginx | 3306)'& > / dev/nullif [$?-ne 0] Then lnmpfi# configures PHP to accommodate zabbixsed-I-e "368s/30/300/"-e "378s/60/300/"-e "656s/8/16/"-e "799aalways_populate_raw_post_data =-1"-e "877cdate.timezone = Asia/Shanghai" / etc/php.inisystemctl restart php-fpm# to establish zabbix database and manage user mysql-uroot-p123123-e "CREATE DATABASE zabbix character set utf8 collate utf8_bin "mysql-uroot-p123123-e" GRANT all privileges ON *. * TO 'zabbix'@'%' IDENTIFIED BY' zhy94666'; "mysql-uroot-p123123-e" flush privileges; "# solves the local login problem mysql-uroot-p123123-e" drop user'@ localhost; "mysql-uroot-p123123-e" drop user''@ localhost.localdomain "mysql-uroot-p123123-e" flush privileges "# installs zabbixrpm-I https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpmfor ((kumb1 ne k > 0 ne +)); do rpm-Q zabbix-agent & > / dev/null if [$?-ne 0] Then yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent-y else break fidone# generates database file zcat / usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql-uzabbix-pzhy94666 zabbix# modifies zabbix server configuration file sed-I-e "91s/# / /"-e "125cDBPassword=zhy94666" / etc/zabbix/zabbix_server.conf# rights cp-r / usr/share/zabbix/ / Usr/share/nginx/html/chown-R zabbix:zabbix / etc/zabbix/chown-R zabbix:zabbix / usr/share/nginx/chown-R zabbix:zabbix / usr/lib/zabbix/chmod-R 755 / etc/zabbix/web/chmod-R 777 / var/lib/php/session/# activate zabbixsystemctl start zabbix-server.servicesystemctl enable zabbix-server.servicesystemctl start zabbix-agent.servicesystemctl enable zabbix-agent.service# all services restart systemctl restart php-fpm nginx mariadb zabbix-server zabbix-agent# check Whether the service starts test= `netstat-atnp | egrep'(nginx | 3306 | 10051 | 10050)'| grep-v "TIME_WAIT" | wc-l`if [$test-ge 5] Then echo "zabbix server setup completed" fidizhi= `ifconfig ens33 | awk 'NR==2 {print $2}' `echo "Please use the browser to log in to ${dizhi} / zabbix/ to install the default login user name is: Admin default login password is: zabbix"