编译安装zabbix
1,部署LNMP环境
1)nginx_instal.sh
#!/bin/bash mkdir -p /server/tools cd /server/tools pkill nginx wget http://nginx.org/download/nginx-1.10.2.tar.gz yum install -y pcre-devel openssl-devel useradd nginx -s /sbin/nologin -u 808 -M rm -f /application/nginx-1.10.2 tar xf nginx-1.10.2.tar.gz cd /server/tools/nginx-1.10.2 ./configure \ --prefix=/application/nginx-1.10.2 \ --user=www \ --group=www \ --with-http_stub_status_module \ --with-http_ssl_module make make install ln -s /application/nginx-1.10.2 /application/nginx cd /application/nginx/conf/ egrep -v "#|^$" nginx.conf.default >nginx.conf /application/nginx/sbin/nginx netstat -tlnp |grep 80
2)编译mysql-5.6.40
安装依赖包:
yum install -y ncurses-devel libaio-devel
安装依赖工具:cmake
yum install cmake -y
创建mysql管理用户:
useradd -s /sbin/nologin -M mysql -u1000
下载mysql软件包,解压
mkdir -p /server/tools
cd /server/tools
wget -q http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.40.tar.gz
tar xf mysql-5.6.40.tar.gz
进入查询目录,使用cmake进行编译,安装,创建软连接,过程时间较长。
cd mysql-5.6.40
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 \
-DMYSQL_DATADIR=/application/mysql-5.6.40/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
make && make install
复制数据库配置文件
cp /application/mysql/support-files/my-default.cnf /etc/my.cnf
防错
mkdir /application/mysql/tmp
初始化数据库
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
修改mysql数据属主,属组
chown -R mysql.mysql /application/mysql/data
配置启动文件
cd /server/tools/mysql-5.6.40
cp support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
加载路径:
echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
mysql
3)php_install.sh
#!/bin/bash
pkill php-fpm
#安装所需要的包
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y
cd /server/tools
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure \ --prefix=/application/php-5.6.37 \ --with-mysql=/application/mysql \ --with-mysqli=/application/mysql/bin/mysql_config \ --with-iconv-dir=/usr/local/libiconv \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --with-mcrypt \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-soap \ --enable-short-tags \ --enable-static \ --with-xsl \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-ftp \ --enable-opcache=no \ --with-gettext
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
make && make install
ln -s /application/php-5.6.37 /application/php
cd /server/tools/php-5.6.37
cp php.ini-production /application/php/lib/php.ini
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.conf
/application/php/sbin/php-fpm
整合nginx+php
echo "<?php phpinfo(); ?>" >index.php
vim /application/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
location ~* .*\.(php|php5)?$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
至此lnmp部署环境已经搭好
3.创建zabbix用户:
useradd zabbix -M -s /sbin/nologin -u 800
4.创建zabbix数据库及授权用户
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
5.下载zabbix源码包编译安装
yum install libdbi-dbd-mysql mysql-devel net-snmp-devel libxml2-devel libcurl-deve libevent libevent-devel
下载zabbix:
wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.14/zabbix-3.4.14.tar.gz
编译:
zabbix-3.4.0
./configure --prefix=/application/zabbix --enable-server --enable-agent --with-mysql=/application/mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make && make install
ln -sf /application/zabbix-2.2.20 /application/zabbix
6.将zabbix数据导入到数据库中
cd /server/tools/zabbix-3.4.13/database/mysql/
[root@syk mysql]# mysql -uzabbix -p123456 zabbix <schema.sql
[root@syk mysql]# mysql -uzabbix -p123456 zabbix <images.sql
[root@syk mysql]# mysql -uzabbix -p123456 zabbix <data.sql
7.定义服务端口:
vim /etc/services ##末尾添加以下内容
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/udp # Zabbix Trapper
zabbix-trapper 10051/tcp # Zabbix Trapper
8.修改zabbix_server的配置文件
vim /application/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=10.0.0.60
DBName=zabbix
DBUser=zabbix
DBPassword=123456
9.复制启动脚本:
cd /server/tools/zabbix-2.2.22
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix -a
10.修改启动脚本:
vim /etc/init.d/zabbix_server
BASEDIR=/application/zabbix //zabbix的安装位置
CONFILE=$BASEDIR/etc/zabbix_server.conf //定义zabbix配置文件位置
##搜索 start这一项,修改启动选项
# functions
start() {
if [ $RUNNING -eq 1 ]
then
echo "$0 $ARG: $BINARY_NAME (pid $PID) already running"
else
action $"Starting $BINARY_NAME: " $FULLPATH -c $CONFILE //这一行添加-c $CONFILE
touch /var/lock/subsys/$BINARY_NAME
fi
}
# 将服务写入开机自启动
echo "/etc/init.d/zabbix start" >> /etc/rc.local
11.复制web代码到站点目录
mkdir -p /application/nginx/html/zabbix
cp -a /server/tools/zabbix-2.2.22/frontends/php/* /application/nginx/html/zabbix/
12.启动zabbix服务
[root@syk zabbix-2.2.22]# /etc/init.d/zabbix start
Starting zabbix_server: [确定]
13.修改php配置文件:
cd /application/php/lib/
sed -i '/^;default_charset/a\default_charset = "UTF-8"' php.ini
sed -i '/^expose_php/expose_php = Off' /etc/php.ini
sed -i '/max_execution_time/max_execution_time = 300' php.ini
sed -i '/^max_input_time/max_input_time = 300' php.ini
sed -i '/^memory_limit/memory_limit = 256M' php.ini
sed -i '/^post_max_size/post_max_size = 32M' php.ini
sed -i '/^upload_max_filesize/upload_max_filesize = 300M' php.ini
sed -i '/^max_file_uploads/max_file_uploads = 30' php.ini
sed -i '/^;date.timezone/date.timezone = "Asia/Shanghai
"'
修改网php配置文件后,重启php服务
为了避免出现zabbix 安装可能会出现的问题 always-populate-raw-post-data = -1
解决方案:
vim /目录/zabbix/include/classes/setup/CFrontendSetup.php
找到下面代码、关于always-populate-raw-post-data;
添加 $current = -1;
public function checkPhpAlwaysPopulateRawPostData() {
$current = ini_get('always_populate_raw_post_data');
$current = -1;
return array(
'name' => _('PHP always_populate_raw_post_data'),
'current' => ($current != -1) ? _('on') : _('off'),
'required' => _('off'),
'result' => ($current != -1) ? self::CHECK_FATAL : self::CHECK_OK,
'error' => _('PHP always_populate_raw_post_data must be set to -1.')
);
}
14.进入软件配置 :http://10.0.0.20/zabbix/setup.php
PHP LDAP 离 警告 解决办法:参考下面博文:
https://www.cnblogs.com/bigdevilking/p/9440098.html
参考文档:https://www.cnblogs.com/rusking/p/4471503.html
https://www.iyunv.com/thread-430536-1-1.html
https://blog.csdn.net/c571121319/article/details/50931265
http://blog.51cto.com/very1024/1722902
https://www.cnblogs.com/clsn/p/8038964.html
agent客户端安装配置。
这里我们将agent端并没有安装在同一台服务器上
1)解压编译安装
tar xf zabbix-3.4.13.tar.gz
cd zabbix-3.4.13
./configure --prefix=/application/zabbix_agent --enable-agent
make
make instal
2)配置:
Server=10.0.0.20 #指定zabbix_server服务器端ip
ServerActive=10.0.0.20 #服务器端的ip
Hostname=web02 #本地端主机名
3)将zabbix_agentd启动脚本加入到/etc/init.d/目录下来管理,zabbix_agentd默认监听10050端口
修改命令如下:
cp /server/tools/zabbix-3.4.13/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd -a
chmod +x /etc/init.d/zabbix_agentd
编辑:vim /etc/init.d/zabbix_agentd 修改内容如下:
BASEDIR=/application/zabbix_agent #agent安装路径
CONFILE=$BASEDIR/etc/zabbix_agentd.conf #主配置文件路径
# 搜素start
# functions
start() {
if [ $RUNNING -eq 1 ]
then
echo "$0 $ARG: $BINARY_NAME (pid $PID) already running"
else
action $"Starting $BINARY_NAME: " $FULLPATH -c $CONFILE #添加: -c $CONFILE
touch /var/lock/subsys/$BINARY_NAME
fi
}
4)启动:
[root@web02 zabbix_agent]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd: zabbix_agentd [9030]: user zabbix does not exist
zabbix_agentd [9030]: cannot run as root!
[失败]
启动失败:还没有建立zabbix账号有关
[root@web02 zabbix_agent]# id zabbix
id: zabbix:无此用户
[root@web02 zabbix_agent]# useradd zabbix -s /sbin/nologin -M
[root@web02 zabbix_agent]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd: [确定]
配置监控项请参考博文:http://www.zsythink.net/archives/519
参考博文:https://blog.csdn.net/mr_rsq/article/details/78457587
安装php显示:
yum [Errno 14] problem making ssl connection CentOs
解决方法:https://blog.csdn.net/chao_1990/article/details/76959691