zabbix一键安装脚本

一、lnmp一键安装脚本

注: /root/目下下需要准备好nginx-1.10.2.tar.gz和php-5.5.38.tar.gz软件包

#!/bin/bash

#==============================================================================================
#NGINX安装

yum groupinstall "Development tools" -y  
yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

groupadd nginx
useradd -r -g nginx nginx

tar axf /root/nginx-1.10.2.tar.gz  
cd /root/nginx-1.10.2
mkdir -pv /var/tmp/nginx/client
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --user=nginx --group=nginx --with-pcre --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-threads --with-stream --with-stream_ssl_module
make && make install

cp /etc/nginx/nginx.conf.default  /etc/nginx/nginx.conf
/usr/sbin/nginx

#===============================================================================================
#MySQL安装

yum -y install mariadb mariadb-server mariadb-devel
systemctl start mariadb
mysqladmin -uroot password 123456

#===============================================================================================
#PHP安装

yum  -y install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel  ncurses ncurses-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel krb5 krb5-devel libidn libidn-devel e2fsprogs e2fsprogs-deve libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers net-snmp net-snmp-devel libevent-devel libjpeg-devel  libmcrypt-devel
tar axf /root/php-5.5.38.tar.gz
cd /root/php-5.5.38
./configure --prefix=/usr/local/php --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc  --with-mysqli=/usr/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-openssl -enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-bz2 --with-curl --enable-bcmath --with-gettext --with-pcre-regex --enable-xml --enable-fpm --with-imap-ssl --with-mhash --with-xmlrpc --with-gd
make && make install

cp /root/php-5.5.38/php.ini-production  /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php.ini

cp /root/php-5.5.38/sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

/etc/init.d/php-fpm start

二、zabbix-server安装前操作命令

创建zabbix库及权限,导入zabbix元数据
mysql -uroot -p123456 -e "create database zabbix default charset utf8"
mysql -uroot -p123456 -e "grant all privileges on zabbix.* to 'zabbix'@'47.98.97.124' identified by 'zabbix'"
tar axf /root/zabbix-3.4.2.tar.gz
cd /root/zabbix-3.4.2
mysql -u root -p123456 zabbix < /root/zabbix-3.4.2/database/mysql/schema.sql
mysql -u root -p123456 zabbix < /root/zabbix-3.4.2/database/mysql/images.sql
mysql -u root -p123456 zabbix < /root/zabbix-3.4.2/database/mysql/data.sql


添加nginx对fastcgi的支持
[root@host-10-101-16-202 ~]# vi /etc/nginx/nginx.conf
        location ~ \.php$ {
        root           /usr/local/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
        include        fastcgi_params;
    }

[root@host-10-10-16-20 ~]# nginx  -s reload
在/usr/local/nginx/html/新建index.php的测试页面,内容如下:
<?php phpinfo();?>

三、zabbix-server一键安装脚本

注:在/root目录下准备好zabbix-3.4.2.tar.gz软件包,如果是server端安装agentd则不需要解压软家包,如果是在另外一台安装agentd则需要准备好zabbix-3.4.2.tar.gz并且解压。

#!/bin/bash

groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin

[ -d /root/zabbix-3.4.2 ]&& cd /root/zabbix-3.4.2
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/lib64/mysql/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make && make install
chown zabbix:zabbix /usr/local/zabbix/ -R

sed -i 's/# DBPassword=/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/# DBHost=localhost/DBHost=47.98.97.124/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's@# DBSocket=/tmp/mysql.sock@DBSocket=/var/lib/mysql/mysql.sock@g' /usr/local/zabbix/etc/zabbix_server.conf

mkdir /usr/local/zabbix/scripts
chown -R zabbix:zabbix scripts/
sed -i 's@# AlertScriptsPath=${datadir}/zabbix/alertscripts@AlertScriptsPath=/usr/local/zabbix/scripts@g' /usr/local/zabbix/etc/zabbix_server.conf

cp -r  /root/zabbix-3.4.2/frontends/php/*  /usr/local/nginx/html/
cp /usr/local/nginx/html/conf/zabbix.conf.php.example  /usr/local/nginx/html/conf/zabbix.conf.php

四、手动配置zabbix.conf.php

[root@host-47-98-97-124 ~]# vi /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
$DB['TYPE']                             = 'MYSQL';
$DB['SERVER']                   = '47.98.97.124';
$DB['PORT']                             = '3306';
$DB['DATABASE']                 = 'zabbix';
$DB['USER']                             = 'zabbix';
$DB['PASSWORD']                 = 'zabbix';

五、启动zabbix-server服务

[root@host-47-98-97-124 ~]# /usr/local/zabbix/sbin/zabbix_server

六、zabbix-agentd安装脚本

[root@host-39-108-217-12 ~]# cat zabbix-agentd-install.sh 
#!/bin/bash

#!/bin/bash

#安装依赖包
yum install gcc* pcre* -y

#解压编译安装
tar axf /root/zabbix-3.4.2.tar.gz
cd /root/zabbix-3.4.2
./configure --prefix=/usr/local/zabbix --enable-agent
make &&  make install

#属主和属组
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
chown -R zabbix:zabbix /usr/local/zabbix

#zabbix-agentd端配置
cp /root/zabbix-3.4.2/misc/init.d/tru64/zabbix_agentd  /etc/init.d/zabbix_agentd
sed -i 's#DAEMON=/usr/local/sbin/zabbix_agentd#DAEMON=/usr/local/zabbix/sbin/zabbix_agentd#g'  /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_agentd
sed -i 's#Server=127.0.0.1#Server=47.98.97.124#g' /usr/local/zabbix/etc/zabbix_agentd.conf                 #47.98.97.124是server端的IP
sed -i 's#Hostname=Zabbix server#Hostname=host-39-108-217-12#g' /usr/local/zabbix/etc/zabbix_agentd.conf   #Hostname是agentd端的主机名
sed -i 's/ServerActive=127.0.0.1/#ServerActive=127.0.0.1/g'  /usr/local/zabbix/etc/zabbix_agentd.conf

#启动zabbix-agentd
/etc/init.d/zabbix_agentd start
  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东城绝神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值