centos7源码编译安装zabbix3
前言
zabbix简介
-
zabbix 由2部分构成:zabbix server 与可选组件zabbix agent。
zabbix server 可以通过SNMP,zabbix agent ,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平台之上。
zabbix agent 需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent 可以运行在Linux ,Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows 2000/2003/XP/Vista)等系统之上。
zabbix server 可以单独监视远程服务器的服务状态;同时也可以与zabbix agent 配合,可以轮询zabbix agent 主动接收监视数据(trapping方式),同时还可被动接收zabbix agent 发送的数据(trapping方式)。另外zabbix server 还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
zabbix的主要特点:
安装与配置简单,学习成本低
支持多语言(包括中文)
免费开源
自动发现服务器与网络设备
分布式监视以及WEB集中管理功能
可以无agent监视
用户安全认证和柔软的授权方式
通过WEB界面设置或查看监视结果
email等通知功能,等等
zabbix在centos7上的安装部署
系统配置和必要的安装包
yum -y install epel-release
yum clean all && yum makecache
yum groupinstall "Development tools" "Server Platform Development" -y
yum install ntpdate -y
$(which ntpdate) pool.ntp.org && echo "*/5 * * * * $(which ntpdate) pool.ntp.org >/dev/null 2>&1" >> /var/spool/cron/root
编译安装nginx
前戏准备
mkdir /opt/soft && cd /opt/soft
wget -c http://mirrors.dwhd.org/Nginx/nginx-1.9.14.tar.gz
tar xf nginx-1.9.14.tar.gz && cd nginx-1.9.14/
adduser -r -s /sbin/nologin -c 'Web Server' -M www
mkdir -p /data/{wwwlogs/nginx,wwwroot}
chown -R www.www /data/{wwwlogs/nginx,wwwroot}
yum -y install pcre-devel openssl-devel
开始编译
./configure --prefix=/usr/local/nginx/ \
--user=www --group=www \
--error-log-path=/tmp/nginx/error.log \
--http-log-path=/tmp/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-pcre \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-client-body-temp-path=/usr/local/nginx/client/ \
--http-proxy-temp-path=/usr/local/nginx/proxy/ \
--http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi
开始安装
make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
echo "export PATH=/usr/local/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
. /etc/profile.d/nginx.sh
zabbix虚拟主机创建
-
vim /usr/local/nginx/conf/vhost/zabbix.ds.com.conf
server {
listen 80;
server_name zabbix.ds.com;
access_log /data/wwwlogs/nginx/zabbix.ds.com_access.log combined;
index index.html index.php index.html;
root /data/wwwroot/zabbix.ds.com/;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+.php)(.*)$ {
fastcgi_split_path_info ^(.+.php)(.*)$;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
编译安装php
前戏准备
cd /opt/soft
yum -y install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel
wget -c http://cn2.php.net/get/php-5.6.20.tar.xz/from/this/mirror -O php-5.6.20.tar.xz
tar xf php-5.6.20.tar.xz
cd php-5.6.20/
开始编译
./configure --prefix=/usr/local/php/ \
--with-config-file-path=/usr/local/php/etc \
--with-bz2 --with-curl --enable-ftp \
--enable-dom --enable-xml --enable-fpm \
--enable-ipv6 --enable-bcmath --enable-sockets \
--enable-mbstring --enable-calendar \
--enable-gd-native-ttf --with-gd --with-zlib \
--with-gettext --with-libdir=lib64 \
--with-mysql=mysqlnd --with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd --with-png-dir=/usr/local \
--with-jpeg-dir=/usr/local --with-iconv-dir=/usr/local \
--with-libxml-dir=/usr/local --with-freetype-dir=/usr/local
开始安装
make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
php配置
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php.ini
sed -ri 's/^(max_execution_time = ).*/\1300/' /usr/local/php/etc/php.ini
sed -ri 's/^(memory_limit = ).*/\1128M/' /usr/local/php/etc/php.ini
sed -ri 's/^(post_max_size = ).*/\116M/' /usr/local/php/etc/php.ini
sed -ri 's/^(upload_max_filesize = ).*/\12M/' /usr/local/php/etc/php.ini
sed -ri 's/^(max_input_time = ).*/\1300/' /usr/local/php/etc/php.ini
sed -ri '/date.timezone =/a date.timezone = PRC' /usr/local/php/etc/php.ini
sed -ri 's/.*(always_populate_raw_post_data .*)/\1/' /usr/local/php/etc/php.ini
chmod +x /etc/init.d/php-fpm
service php-fpm start #启动服务
cd ../..
echo "export PATH=/usr/local/php/bin:\$PATH" > /etc/profile.d/php.sh
. /etc/profile.d/php.sh
php -v
安装MariaDB
前戏准备
cd /opt/soft
adduser -r -m -d /data/mariadb -k no -s /sbin/nologin -c 'Mariadb Database' mysql
chown -R mysql.mysql /data/mariadb
wget http://mirrors.dwhd.org/SQL/MariaDB/mariadb-10.0.23/source/mariadb-10.0.23.tar.gz
tar xf mariadb-10.1.13.tar.gz
cd mariadb-10.1.13/
yum -y install cmake ncurses-devel
开始编译
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/data/mariadb \
-DWITH_SSL=system -DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 -DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATEDX_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 -DWITH_READLINE=1 -DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8
开始安装
make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
配置mariadb
cd /usr/local/mariadb
wget http://www.dwhd.org/script/mysql_my.cnf -cO- >/etc/my.cnf
/usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
service mysqld start
curl -s http://www.dwhd.org/script/mysql_zabbix_init.sql >/tmp/mysql_zabbix_init.sql
-
mysql -uroot -e “source /tmp/mysql_zabbix_init.sql;”
+--------+-------------------------------------------+---------------------------+
| USER | PASSWORD | HOST |
+--------+-------------------------------------------+---------------------------+
| root | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | localhost |
| root | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | ds-vm-node251.cluster.com |
| root | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 127.0.0.1 |
| root | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | ::1 |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | localhost |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 127.0.0.1 |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | ::1 |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 192.168.%.% |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 172.16.%.% |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 10.%.%.% |
+--------+-------------------------------------------+---------------------------+
安装JDK
前戏准备
yum install http://mirrors.ds.com/tar_source/JDK/jdk-8u77-linux-x64.rpm -y
配置jdk环境
cat > /etc/profile.d/java.sh << EOF
JAVA_HOME=/usr/java/latest
PATH=\$JAVA_HOME/bin:\$PATH
export JAVA_HOME PATH
EOF
. /etc/profile.d/java.sh
-
java -version #查看版本
安装Zabbix3.0
前戏准备
useradd -r -s /sbin/nologin -M -d /data/wwwroor/zabbix.ds.com -c 'Zabbix Server' zabbix
cd /opt/soft
wget -c http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.1/zabbix-3.0.1.tar.gz
tar xf zabbix-3.0.1.tar.gz
cd zabbix-3.0.1/
yum install -y net-snmp-devel OpenIPMI OpenIPMI-devel perl-ZMQ-LibZMQ3 curl-devel libxml2-devel
开始编译
./configure --prefix=/usr/local/zabbix/ \
--sysconfdir=/etc/zabbix \
--enable-server \
--enable-proxy \
--enable-agent \
--enable-ipv6 \
--enable-java \
--with-mysql=/usr/local/mariadb/bin/mysql_config \
--with-net-snmp \
--with-libcurl \
--with-openipmi \
--with-libxml2
开始安装
make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
echo "export PATH=/usr/local/zabbix/sbin:\$PATH" > /etc/profile.d/zabbix.sh
. /etc/profile.d/zabbix.sh
开始配置
for i in schema.sql images.sql data.sql; do mysql -uroot -plookback zabbix < ./database/mysql/$i;done
sed -ri '/^DBName=/d' /etc/zabbix/zabbix_server.conf
sed -ri '/^DBUser=/d' /etc/zabbix/zabbix_server.conf
sed -ri '/^DBPassword=/d' /etc/zabbix/zabbix_server.conf
sed -ri "s/(DBName=)/&\n\1zabbix/" /etc/zabbix/zabbix_server.conf
sed -ri "s/(DBUser=)/&\n\1zabbix/" /etc/zabbix/zabbix_server.conf
sed -ri "s/.*(DBPassword=).{0,}/&\n\1lookback/" /etc/zabbix/zabbix_server.conf
sed -i '/JavaGateway=/a JavaGateway=127.0.0.1\nJavaGatewayPort=10052\nStartJavaPollers=5' /etc/zabbix/zabbix_server.conf
sed -i '/LISTEN_IP="0.0.0.0"/a LISTEN_IP="0.0.0.0"' /usr/local/zabbix/sbin/zabbix_java/settings.sh
sed -i '/LISTEN_PORT=10052/a LISTEN_PORT=10052' /usr/local/zabbix/sbin/zabbix_java/settings.sh
sed -i '/START_POLLERS=5/a START_POLLERS=5' /usr/local/zabbix/sbin/zabbix_java/settings.sh
ln -sv /usr/local/mariadb/lib/libmysqlclient.so.18 /usr/lib64/
"/usr/lib64/libmysqlclient.so.18" -> "/usr/local/mariadb/lib/libmysqlclient.so.18"
ln -sv /usr/local/mariadb/lib/libmysqlclient.so.18 /usr/lib64/
"/usr/lib64/libmysqlclient.so.18" -> "/usr/local/mariadb/lib/libmysqlclient.so.18"
ldconfig
cat >> /etc/services << EOF
zabbix-agent 10050/tcp #ZabbixAgent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #ZabbixTrapper
zabbix-trapper 10051/udp #Zabbix Trapper
EOF
web配置
mkdir -p /data/wwwroot/zabbix.ds.com
sed -i '/zh_CN/{s/false/true/}' ./frontends/php/include/locales.inc.php
sed -i 's/DejaVuSans/simkai/g' ./frontends/php/include/defines.inc.php
cp -rp ./frontends/php/* /data/wwwroot/zabbix.ds.com/
wget https://www.dwhd.org/wp-content/uploads/2015/05/simkai.ttf -O /data/wwwroot/zabbix.ds.com/fonts/simkai.ttf
chown -R www.www /data/wwwroot/zabbix.ds.com
cp -a ./misc/init.d/fedora/core/zabbix_server /etc/init.d/
cp -a ./misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_server
sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
service zabbix_server start
service zabbix_agentd start
-
iptables -A -p tcp -m tcp –dport 80 -j ACCEPT
原创文章,作者:wanghui,如若转载,请注明出处:http://www.178linux.com/60747