Centos7一键编译安装zabbix-4.0.2
##只针对centos7的系统有效,centos6无效,mysql zabbix用户:zabbix,密码:zabbix;建议用全新的centos7服务器
软件版本: (nginx-1.14.2、php-7.2.13、zabbix-4.0.2、mariadb-5.5.60、jdk-1.8.0_131),算是比较新的一个版本了
#!/bin/bash
#安装zabbix4.0脚本
err_echo(){
echo -e "\033[41;37m[Error]: $1 \033[0m"
exit
} info_echo(){
echo -e "\033[42;37m[Info]: $1 \033[0m"
} check_file_is_exists(){
if [ ! -f "/usr/local/src/$1" ];then
info_echo "$1开始下载"
fi
} check_exit(){
if [ $? -ne ]; then
err_echo "$1"
exit
fi
} check_success(){
if [ $? -eq ];then
info_echo "$1"
fi
} [ $(id -u) != "" ] && err_echo "please run this script as root user." && exit function init_servers(){ info_echo "开始初始化服务器"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce
systemctl stop firewalld.service
systemctl disable firewalld.service info_echo "更换阿里源"
yum install wget -y
cp /etc/yum.repos.d/* /tmp
rm -f /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all } function install_package(){ info_echo "开始安装系统必备依赖包"
yum install ntpdate gcc gcc-c++ wget lsof lrzsz -y info_echo "开始安装php所需依赖包"
yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
yum install -y systemd-devel mysql-devel
yum install -y openjpeg-devel info_echo "开始安装nginx所需依赖包" yum install -y pcre pcre-devel zlib zlib-devel
} function download_install_package(){ if [ ! -f "/usr/local/src/nginx-1.14.2.tar.gz" ];then
info_echo "开始下载nginx-1.14.2.tar.gz"
wget -P /usr/local/src https://nginx.org/download/nginx-1.14.2.tar.gz
check_success "nginx-1.14.2.tar.gz已下载至/usr/local/src目录"
else
info_echo "nginx-1.14.2.tar.gz已存在,不需要下载"
fi
if [ ! -f "/usr/local/src/php-7.2.13.tar.gz" ];then
info_echo "开始下载php-7.2.13.tar.gz"
wget -P /usr/local/src http://cn2.php.net/distributions/php-7.2.13.tar.gz
check_success "php-7.2.13.tar.gz已下载至/usr/local/src目录"
else
info_echo "php-7.2.13.tar.gz已存在,不需要下载"
fi if [ ! -f "/usr/local/src/zabbix-4.0.2.tar.gz" ];then
info_echo "开始下载zabbix-4.0.2.tar.gz"
wget -P /usr/local/src https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz
check_success "zabbix-4.0.2.tar.gz已下载至/usr/local/src目录"
else
info_echo "zabbix-4.0.2.tar.gz已存在,不需要下载"
fi if [ ! -f "/usr/local/src/jdk-8u131-linux-x64.tar.gz" ];then
info_echo "开始下载jdk-8u131-linux-x64.tar.gz"
wget -P /usr/local/src -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
check_success "jdk-8u131-linux-x64.tar.gz已下载至/usr/local/src目录"
else
info_echo "jdk-8u131-linux-x64.tar.gz已存在,不需要下载"
fi } function install_php(){ info_echo "开始安装php-7.2.13"
sleep 2s
groupadd php-fpm && useradd -s /sbin/nologin -g php-fpm -M php-fpm
groupadd zabbix && useradd -g zabbix zabbix
cd /usr/local/src
tar xvf /usr/local/src/php-7.2.13.tar.gz
cd /usr/local/src/php-7.2.13
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo
check_exit "configure php-7.2.13失败"
make && make install
check_exit "make php-7.2.13失败" info_echo "开始配置php-7.2.13" cp /usr/local/src/php-7.2.13/php.ini-production /usr/local/php/etc/php.ini && cd /usr/local/php/etc && cp php-fpm.conf.default php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/src/php-7.2.13/sapi/fpm/php-fpm.service /usr/lib/systemd/system sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /usr/local/php/etc/php.ini
sed -i "s#`grep max_execution_time /usr/local/php/etc/php.ini`#max_execution_time = 300#g" /usr/local/php/etc/php.ini
sed -i "s#`grep post_max_size /usr/local/php/etc/php.ini`#post_max_size = 32M#g" /usr/local/php/etc/php.ini
sed -i "s#`grep max_input_time\ = /usr/local/php/etc/php.ini`#max_input_time = 300#g" /usr/local/php/etc/php.ini
sed -i "s#`grep memory_limit /usr/local/php/etc/php.ini`#memory_limit = 128M#g" /usr/local/php/etc/php.ini
sed -i "s#`grep post_max_size /usr/local/php/etc/php.ini`#post_max_size = 32M#g" /usr/local/php/etc/php.ini sed -i "s/user = php-fpm/user = zabbix/g" /usr/local/php/etc/php-fpm.d/www.conf
sed -i "s/group = php-fpm/group = zabbix/g" /usr/local/php/etc/php-fpm.d/www.conf systemctl start php-fpm
systemctl enable php-fpm
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
info_echo "php-fpm启动成功"
else
err_echo "php-fpm未启动成功,请检查"
exit 1
fi }
function install_nginx(){ info_echo "开始安装nginx-1.14.2"
sleep 2s
useradd nginx -s /sbin/nologin -M
cd /usr/local/src && tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2 && ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-cc-opt=-O3 --with-stream
check_exit "configure nginx-1.14.2失败"
make && make install
check_exit "make nginx-1.14.2失败"
info_echo "开始配置nginx-1.14.2"
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
echo "" >/usr/local/nginx/conf/nginx.conf
mkdir -p /usr/local/nginx/conf/servers && mkdir -p /data/logs/nginx-zabbix && mkdir -p /data/home/www/zabbix
cat <<"EOF" > /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
error_log logs/error.log crit;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
multi_accept on;
accept_mutex_delay 50ms;
worker_connections 40960;
}
http {
include mime.types;
#default_type application/octet-stream;
default_type text/html;
client_max_body_size 50m;
server_tokens off; server_names_hash_bucket_size 512; sendfile on;
#keepalive_timeout 65;
keepalive_timeout 600; gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/shtml application/xml applicaton/javascript text/javascript;
charset utf-8;
log_format main '$http_x_forwarded_for $remote_addr $remote_user [$time_local] "$request" $http_host $status $upstream_status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_addr $request_time $upstream_response_time';
log_format mine '$http_x_forwarded_for" - $upstream_addr - $upstream_cache_status - $upstream_status - $upstream_http_host - $request_time - [$time_local] - $request';
include servers/*;
}
EOF cat <<"EOF" > /usr/local/nginx/conf/servers/zabbix.conf
server {
listen 80;
server_name zabbix; location / {
root /data/home/www/zabbix;
index index.php; }
location ~ \.php$ { root /data/home/www/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} access_log /data/logs/nginx-zabbix/zabbix-access.log main;
access_log /data/logs/nginx-zabbix/zabbix_mine.log mine; }
EOF info_echo "开启启动nginx"
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx
STAT=`echo $?`
PORT=`netstat -lntup|grep nginx|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
info_echo "nginx启动成功"
else
err_echo "nginx未启动成功,请检查"
fi } function install_mysql(){ info_echo "开始安装mysql"
sleep 2s
yum install mariadb-server -y
check_exit "安装mysql失败"
systemctl start mariadb
STAT=`echo $?`
PORT=`netstat -lntup|grep mysql|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
info_echo "mysql启动成功"
else
err_echo "mysql未启动成功,请检查"
fi info_echo "开始创建zabbix账号和授权"
sleep 2s
mysql -uroot -e "create database zabbix character set utf8;"
mysql -uroot -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';"
mysql -uroot -e "flush privileges;"
mysql -uroot -e "show databases;" } function install_jdk(){ info_echo "开始安装jdk-8u131-linux-x64.tar.gz"
sleep 2s
mkdir -p /usr/local/java
tar xvf /usr/local/src/jdk-8u131-linux-x64.tar.gz -C /usr/local/java
cp /etc/profiel /etc/profile.bak cat <<"EOF" >> /etc/profile
JAVA_HOME=/usr/local/java/jdk1.8.0_131
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH
EOF info_echo "验证jdk是否安装成功"
source /etc/profile
java -version
} function install_zabbix(){ info_echo "开始安装zabbix-4.0.2"
sleep 2s
yum install OpenIPMI-devel libevent-devel net-snmp-devel -y
cd /usr/local/src/ && tar xvf zabbix-4.0.2.tar.gz
cd /usr/local/src/zabbix-4.0.2
./configure \
--prefix=/usr/local/zabbix \
--enable-server --enable-agent \
--enable-proxy --enable-java \
--with-mysql --with-net-snmp \
--with-libcurl --with-libxml2 \
--with-openipmi \
--enable-proxy
check_exit "configure zabbix-4.0.2失败"
make && make install
check_exit "make zabbix-4.0.2失败"
info_echo "开始配置zabbix-4.0.2"
cp -R /usr/local/src/zabbix-4.0.2/frontends/php/* /data/home/www/zabbix
chown -R zabbix.zabbix /data/home/www/zabbix
chown -R zabbix.zabbix /usr/local/zabbix
cp /usr/local/src/zabbix-4.0.2/misc/init.d/fedora/core5/* /etc/init.d/
sed -i "s#/usr/local/sbin/zabbix_server#/usr/local/zabbix/sbin/zabbix_server#g" /etc/init.d/zabbix_server
sed -i "s#/usr/local/sbin/zabbix_agentd#/usr/local/zabbix/sbin/zabbix_agentd#g" /etc/init.d/zabbix_agentd
cp /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak
echo "" >/usr/local/zabbix/etc/zabbix_server.conf cat <<"EOF" > /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
Timeout=30
EOF info_echo "开始导入mysql数据"
mysql -uzabbix -pzabbix zabbix < /usr/local/src/zabbix-4.0.2/database/mysql/schema.sql
mysql -uzabbix -pzabbix zabbix < /usr/local/src/zabbix-4.0.2/database/mysql/images.sql
mysql -uzabbix -pzabbix zabbix < /usr/local/src/zabbix-4.0.2/database/mysql/data.sql info_echo "开始启动zabbix_server"
sleep 2s
/etc/init.d/zabbix_server start
STAT=`echo $?`
PORT=`netstat -lntup|grep zabbix_server|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
info_echo "zabbix_server启动成功"
else
err_echo "zabbix_server,请检查"
fi
} function main(){ init_servers
install_package
download_install_package
install_php
install_nginx
install_mysql
install_jdk
install_zabbix } main
Centos7一键编译安装zabbix-4.0.2的更多相关文章
- 编译安装zabbix 3.0及分开部署配置详解
实验系统:CentOS 6.6_x86_64 实验前提:提前准备好编译环境,防火墙和selinux都关闭 实验说明:本实验共有4台主机,IP及角色分配如拓扑 下载地址:试验中用到mariadb软件的下 ...
- centos7下编译安装nginx-1.16.0
一.下载nginx源码 http://nginx.org/en/download.html 如:nginx-1.16.0.tar.gz 二.创建用户和组,并解压 groupadd www userad ...
- Centos7下安装zabbix 3.0.19
参考网站: https://www.cnblogs.com/xiewenming/p/7732144.html https://www.cnblogs.com/clsn/p/7885990.html ...
- CentOS7.x编译安装zabbix4.0
编译安装zabbix Zabbix简介 Zabbix 是一个企业级的分布式开源监控方案. Zabbix是一款能够监控各种网络参数以及服务器健康性和完整性的软件.Zabbix使用灵活的通知机制,允许用户 ...
- centos7下编译安装php-7.0.15(PHP-FPM)
centos7下编译安装php-7.0.15(PHP-FPM) 一.下载php7源码包 http://php.net/downloads.php 如:php-7.0.15.tar.gz 二.安装所需依 ...
- 一键安装 zabbix 3.0 版本 脚本
原文地址: http://blog.csdn.net/u012449196/article/details/53859068 本文修改了原文中的部分错误,此脚本适用于zabbix 2.0 或 3.0 ...
- 一键安装 zabbix 2.0 版本 脚本
原文地址: http://blog.csdn.net/u012449196/article/details/53859068 本文修改了原文中的部分错误,此脚本适用于zabbix 2.0 版本,以版本 ...
- centos7.2编译安装zabbix-3.0.4
安装zabbix-3.0.4 #安装必备的包 yum -y install gcc* make php php-gd php-mysql php-bcmath php-mbstring php-xml ...
- Linux Centos7.2 编译安装PHP7.0.2
操作环境: 1.系统:Centos7.2 2.服务:Nginx 1.下载PHP7.0.2的安装包解压,编译,安装: $ cd /usr/src/ $ wget http://cn2.php.net/d ...
随机推荐
- 关于mybatis的思考(3)——ResultMaps的使用
ResultMap元素在mybatis中非常重要,目的是告诉mybatis将从结果集中取出的数据转换为开发者需要的对象. UserMapping.xml <!-- selectAll操作 ...
- Windows上MyEclipse2017 CI7 安装、破解以及配置
一.安装环境与安装包 操作系统:win7 MyEclipse2017 CI7下载地址:链接:https://pan.baidu.com/s/1TWkwntF9i5lOys3Z96mpLQ MyEcli ...
- debug阶段贡献分
组名: 新蜂 组长: 武志远 组员: 宫成荣 谢孝淼 杨柳 李峤 项目名称: java俄罗斯方块NEO 发布时间:11.29 武志远 武志远 武志远 武志远 武志远 宫成荣 宫成荣 杨柳 宫成荣 宫成 ...
- Java乐观锁、悲观锁
乐观锁 乐观锁(Optimistic Lock), 顾名思义,就是很乐观,每次去拿数据的时候都认为别人不会修改,所以不会上锁,但是在更新的时候会判断一下在此期间别人有没有去更新这个数据,可以使用版本号 ...
- iOS 数据库sqlite完整增删改查操作
1: 创建数据库表格 1.1 — 表格创建使用一个数据库软件快速创建:软件大小14.3M; 下载地址:http://pan.baidu.com/s/1qWOgGoc; 表格创建-> 打开软件,点 ...
- 一些常用的基础Linux操作指令
复习的时候顺便分享我学的知识,虽不是什么牛的技术分享,只是一些基础,基础打好了技术慢慢就提高了!一起加油一起共勉! 具体的vi和vim命令集太多了,以后的随笔我也会分享出来,没必要全记住,记住常用的就 ...
- vyos 基础配置
vyos 基础配置 http://www.lowefamily.com.au/2015/11/29/using-a-vyos-router-with-hyper-v/1/http://thomasvo ...
- 出错:ORA-20000: ORU-10028: line length overflow, limit of 255 bytes per line?
起因:DBMS_OUTPUT.put(V_SQL) 提示太长错误,设置了buffer=>null 和set 长度都不行 解决方法如下: testxx.debug_print(V_SQL); -- ...
- BZOJ5305 [Haoi2018]苹果树 【组合数学】
题目链接 BZOJ5305 题解 妙啊 要求的是所有可能的树形的所有点对距离和 直接考虑点的贡献肯定想不出,这样的所有点对距离问题通常转化为边的贡献 考虑一条边会产生多少贡献 我们枚举\(i\)节点的 ...
- 洛谷 P1357 花园 解题报告
P1357 花园 题目描述 小\(L\)有一座环形花园,沿花园的顺时针方向,他把各个花圃编号为\(1~N(2<=N<=10^{15})\).他的环形花园每天都会换一个新花样,但他的花园都不 ...