Zabbix3.0环境搭建(Centos6.5) 博客分类: Zabbix zabbix
程序员文章站
2024-03-18 15:34:34
...
第一章 环境准备
1.1 SELINUX关闭
[root@apm install]# vi /etc/selinux/config
SELINUX=disabled
[root@apm install]# setenforce permissive
1.2 MySQL5.5安装及配置
1.2.1 安装mysql5.5
(1) 安装编译环境:
所需依赖包:
cmake-3.6.0.tar.gz
ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
kernel-headers-2.6.32-431.el6.x86_64.rpm --系统已装
glibc-headers-2.12-1.132.el6.x86_64.rpm --系统已装
glibc-devel-2.12-1.132.el6.x86_64.rpm --系统已装
ppl-0.10.2-11.el6.x86_64.rpm
cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
mpfr-2.4.1-6.el6.x86_64.rpm
cpp-4.4.7-4.el6.x86_64.rpm
gcc-4.4.7-4.el6.x86_64.rpm
libstdc++-devel-4.4.7-4.el6.x86_64.rpm
gcc-c++-4.4.7-4.el6.x86_64.rpm
源码安装cmake:
[root@apm install]# cd /opt/apm/install/
[root@apm install]# tar zxvf cmake-3.6.0.tar.gz
[root@apm install]# cd cmake-3.6.0
[root@apm cmake-3.6.0]# ./configure
[root@apm cmake-3.6.0]# gmake
[root@apm cmake-3.6.0]# make&&make install
创建软连接:
[root@apm cmake-3.6.0]# ln -s /usr/local/bin/cmake /usr/bin/cmake
将系统iso镜像挂载到/media目录下,使用yum本地安装:
[root@apm ~]# mount /dev/cdrom /media
[root@apm cmake-3.6.0]# yum localinstall /media/Packages/ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
按照顺序安装gcc:
[root@apm install]# rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm --step1
[root@apm install]# rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm -step2
[root@apm install]# rpm -ivh mpfr-2.4.1-6.el6.x86_64.rpm --step 3
[root@apm install]# rpm -ivh cpp-4.4.7-4.el6.x86_64.rpm --step 4
[root@apm install]# rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm --step 5
[root@apm install]# rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm --step6
按照顺序安装gcc-c++:
[root@apm install]# rpm -ivh libstdc++-devel-4.4.7-4.el6.x86_64.rpm --step 1
[root@apm install]# rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm --step 2
(2)创建用户、用户组、mysql数据存储目录、mysql文件存储目录:
[root@apm install]# groupadd mysql
[root@apm install]# useradd -g mysql mysql -s /bin/false
[root@apm install]# mkdir -p /data/mysql
[root@apm install]# chown -R mysql:mysql /data/mysql
[root@apm install]# mkdir -p /usr/local/mysql
(3)源码编译安装MySQL:
[root@apm install]# tar zxvf mysql-5.5.50.tar.gz
[root@apm install]# cd mysql-5.5.50
[root@apm mysql-5.5.50]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=/data/mysql
[root@apm mysql-5.5.50]# make && make install
1.2.2 配置
(1)修改配置文件:
[root@apm local]# chown -R mysql:mysql /usr/local/mysql/
[root@apm mysql]# cp ./support-files/my-huge.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? yes
[root@apm mysql]# vi /etc/my.cnf
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
datadir = /data/mysql
character-set-server = utf8
max_allowed_packet = 16M
#default-storage-engine = MyISAM
max_connections = 512
event_scheduler = ON #(mysql主从库,主库开启,从库关闭)
lower_case_table_names=1
(2) 修改启动文件,设置开机自启动
修改启动文件:
[root@apm mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@apm mysql]# chmod 755 /etc/rc.d/init.d/mysqld
[root@apm mysql]# vi /etc/rc.d/init.d/mysqld
46行、47行
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/data/mysql
设置开机自启动:
[root@apm mysql]# chkconfig mysqld on
(3)启动
[root@apm mysql]# ./scripts/mysql_install_db --user=mysql
[root@apm mysql]# service mysqld start
(4)编辑环境变量
[root@apm mysql]# vi /etc/profile
在文件最后一行上添加:
unset i
unset -f pathmunge
export TZ=Asia/Shanghai
export JAVA_HOME=/opt/apm/jdk1.8.0_11
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/mysql/bin
[root@apm mysql]# source /etc/profile
(5)设置root密码
设置用户root,密码root
[root@apm mysql]# mysqladmin -u root password "root"
(6)删除匿名用户
[root@apm mysql]# mysql -u root -p
Enter password: root
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Database changed
mysql>select Host,User,Password from user; ---查看当前用户
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| apm.test | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| apm.test | | |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> delete from mysql.user where user=""; --删除匿名用户
Query OK, 2 rows affected (0.00 sec)
mysql> update user set password=PASSWORD('root') where user='root'; -其它root用户设置密码为root
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
(7)创建zabbix数据库
用户名: zabbix 密码:zabbix
[root@apm mysql]# mysql -u root -p
Enter password: root
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
1.3 Apache安装及配置
1.3.1 安装Apache
(1)系统已装
检查系统是否已经安装httpd,发现Centos6.5 已经默认安装httpd2.2.15:
[root@apm httpd-2.4.25]# rpm -qa | grep httpd
httpd-tools-2.2.15-29.el6.centos.x86_64
httpd-2.2.15-29.el6.centos.x86_64
但是缺少aspx命令,对应以下软件包及依赖包:
apr-devel-1.3.9-5.el6_2.x86_64.rpm --step 1
expat-devel-2.0.1-11.el6_2.x86_64.rpm --step 2
cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64.rpm step 3
openldap-devel-2.4.23-32.el6_4.1.x86_64.rpm --step 4
apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm --step 5
httpd-devel-2.2.15-29.el6.centos.x86_64.rpm --step 6 aspx命令在此包中,上述其他包为依赖包
挂载系统iso镜像,在iso系统镜像中,找到依赖包,用yum方式来本地安装:
[root@apm Packages]# yum localinstall /media/Packages/apr-devel-1.3.9-5.el6_2.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/expat-devel-2.0.1-11.el6_2.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/openldap-devel-2.4.23-32.el6_4.1.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/httpd-devel-2.2.15-29.el6.centos.x86_64.rpm
(2)源码安装
源码安装:安装httpd2.4版本时,需要先添加依赖包,解决依赖关系
[root@apm install]# cd /opt/apm/install/
解压:
[root@apm install]# tar zxvf httpd-2.4.25.tar.gz
[root@apm install]# tar zxvf apr-1.5.2.tar.gz
[root@apm install]# tar zxvf apr-util-1.5.4.tar.gz
解决依赖关系:
[root@apm install]# mv apr-1.5.2 httpd-2.4.25/srclib/apr
[root@apm install]# mv apr-util-1.5.4 httpd-2.4.25/srclib/apr-util
[root@apm install]# cd httpd-2.4.25
编译:
[root@apm httpd-2.4.25]# ./configure --prefix=/opt/apm/httpd2.4.25 --sysconfdir=/etc/httpd --with-z --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
编译参数详解:
--prefix:#安装路径
--sysconfdir:#指定配置文件路径
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可实现https访问 需已安装openssl-devel
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能,URL重写
--enable-deflate:#支持压缩功能
--with-zlib:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找 需已安装pcre-devel
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-mpms-shared:#支持动态加载的MPM模块,可选参数:all
--with-mpm:#设置默认启用的MPM模式,{prefork|worker|event}
--enable-modules:#支持动态启用的模块,可选参数:all,most,few,reallyall
#编译之前可使用./configure --help查看各项参数
安装:
[root@apm httpd-2.4.25]# make&& make install
安装完成,启动服务:
[root@apm httpd-2.4.25]# cd /opt/apm/httpd2.4.25
[root@apm httpd-2.4.25]# ./apachectl start
查看80端口是否被监听:
[root@apm httpd-2.4.25]# netstat -ntl | grep 80
可选操作:
1、为了方便命令使用需要添加环境变量,编辑二进制程序如何让系统找到:
# cat /etc/profile.d/apache.sh
PATH=/usr/local/apache/bin:$PATH
export PATH
2、头文件输出给系统:
#ln -sv /usr/local/apache/include /usr/local/include/httpd
3、让系统重新生成库文件路径缓存
#ldconfig -v |grep "^[^[:space:]]"
4、启动apache服务:
# apachectl start
1.3.2 配置
(1)相关文件存放目录:
Apache用户及用户组:apache.apache
Apache站点目录:/var/www/html
httpd命令目录: /etc/init.d/httpd
httpd配置文件目录:/etc/httpd/conf/httpd.conf
[root@apm httpd-2.4.25]# vi /etc/httpd/conf/httpd.conf
135 #Listen 12.34.56.78:80
136 Listen 80 --监听的端口号
137
138 #
273 # You will have to access it by its address anyway, and this will make
274 # redirections work in a sensible way.
275 #
276 #ServerName www.example.com:80
277 ServerName 192.168.120.134:80 --服务器的地址
278 #
290 # symbolic links and aliases may be used to point to other locations.
291 #
292 DocumentRoot "/var/www/html" --网页文件的存放目录
(2)httpd启停命令:
[root@apm httpd-2.4.25]# cd /etc/init.d
[root@apm init.d]# ./httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for apm.test
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@apm init.d]# ./httpd stop --停止httpd服务
Stopping httpd: [ OK ]
第二种启停方式:
[root@apm ~]# apachectl start
[root@apm ~]# apachectl stop
1.4 PHP5.5安装及配置
1.4.1 安装PHP5.5
按如下顺序依次安装缺少的依赖包:
libxml2-2.7.6-14.el6.x86_64.rpm
zlib-devel-1.2.3-29.el6.x86_64.rpm
libxml2-devel-2.7.6-14.el6.x86_64.rpm
openssl-1.0.1e-15.el6.x86_64.rpm
keyutils-libs-devel-1.4-4.el6.x86_64.rpm
libcom_err-devel-1.41.12-18.el6.x86_64.rpm
libsepol-2.0.41-4.el6.x86_64.rpm
pkgconfig-0.23-9.1.el6.x86_64.rpm
libsepol-devel-2.0.41-4.el6.x86_64.rpm
libselinux-devel-2.0.94-5.3.el6_4.1.x86_64.rpm
krb5-devel-1.10.3-10.el6_4.6.x86_64.rpm
openssl-devel-1.0.1e-15.el6.x86_64.rpm
bzip2-devel-1.0.5-7.el6_0.x86_64.rpm
libidn-devel-1.18-2.el6.x86_64.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-4.el6.noarch.rpm
libcurl-devel-7.19.7-37.el6_4.x86_64.rpm
libjpeg-turbo-devel-1.2.1-1.el6.x86_64.rpm
libpng-devel-1.2.49-1.el6_2.x86_64.rpm
freetype-devel-2.3.11-14.el6_3.1.x86_64.rpm
将系统iso镜像挂载到/media目录下:
[root@apm ~]# mount /dev/cdrom /media
[root@apm ~]# cd /media/Packages
使用yum本地安装,依次安装缺少的依赖包:
[root@apm Packages]# yum localinstall /media/Packages/ libxml2-2.7.6-14.el6.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/zlib-devel-1.2.3-29.el6.x86_64.rpm
…
说明:若系统中已安装某软件包,安装后会显示“nothing to do”字样,则忽略此软件包即可。
源码编译安装PHP:
[root@apm install]# tar zxvf php-5.5.37.tar.gz
[root@apm install]# cd php-5.5.37
[root@apm php-5.5.37]#
./configure --prefix=/opt/apm/php5.5 --with-config-file-path=/opt/apm/php5.5/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-dir --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir --with-zlib --with-mysql-sock=/tmp/mysql.sock --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --enable-bcmath --with-apxs2=/usr/sbin/apxs --with-openssl
参数说明:
--prefix PHP安装文件存储目录
--with-config-file-path PHP配置文件存放目录
--with-gettext-mysql MySQL数据库安装文件目录
--with-mysql-sock MySQL sock文件存放目录,可vi MySQL的配置文件,查看目录,即 vi /etc/my.cnf
--with-apxs2 apxs命令存放目录, 可用which apxs 来查看目录
[root@apm php-5.5.37]# make && make install
1.4.2 配置
创建并修改php配置文件:
[root@apm php-5.5.37]# cp php.ini-development /opt/apm/php5.5/etc/php.ini
[root@apm php5.5]# vi /opt/apm/php5.5/etc/php.ini
添加内容:910行:
907 [Date]
908 ; Defines the default timezone used by the date functions
909 ; http://php.net/date.timezone
910 date.timezone = Asia/Shanghai
修改内容:372行:
369 ; Maximum execution time of each script, in seconds
370 ; http://php.net/max-execution-time
371 ; Note: This directive is hardcoded to 0 for the CLI SAPI
372 max_execution_time = 300
373
修改内容,660行:
656 ; Maximum size of POST data that PHP will accept.
657 ; Its value may be 0 to disable the limit. It is ignored if POST data reading
658 ; is disabled through enable_post_data_reading.
659 ; http://php.net/post-max-size
660 post_max_size = 16M
661
修改内容,382行:
374 ; Maximum amount of time each script may spend parsing request data. It's a good
375 ; idea to limit this time on productions servers in order to eliminate unexpectedly
376 ; long running scripts.
377 ; Note: This directive is hardcoded to -1 for the CLI SAPI
378 ; Default Value: -1 (Unlimited)
379 ; Development Value: 60 (60 seconds)
380 ; Production Value: 60 (60 seconds)
381 ; http://php.net/max-input-time
382 max_input_time = 300
修改内容,393行:
391 ; Maximum amount of memory a script may consume (128MB)
392 ; http://php.net/memory-limit
393 memory_limit = 128M
添加内容,1743行:
1733 ; overload(replace) single byte functions by mbstring functions.
1734 ; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
1735 ; etc. Possible values are 0,1,2,4 or combination of them.
1736 ; For example, 7 for overload everything.
1737 ; 0: No overload
1738 ; 1: Overload mail() function
1739 ; 2: Overload str*() functions
1740 ; 4: Overload ereg*() functions
1741 ; http://php.net/mbstring.func-overload
1742 ;mbstring.func_overload = 0
1743 mbstring.func_overload = 0
修改Apache服务器配置文件:
[root@apm php-5.5.37]# vi /etc/httpd/conf/httpd.conf
添加内容:403行;
403 DirectoryIndex index.html index.php index.html.var
添加内容:782行;
780 AddType application/x-compress .Z
781 AddType application/x-gzip .gz .tgz
782 Addtype application/x-httpd-php .php .phtml
1.5升级curl --未操作
CentOS6.5 curl默认版本为curl 7.19.7 , CURL升级为了SMTP Authentication,如果不升级则zabbix服务启动时:/var/log/zabbix/zabbix-server.log则显示:
39715:20160729:144131.510 SMTP authentication: NO
升级curl所需软件包:
curl-7.29.0-25.el6.x86_64.rpm
libcurl-7.29.0-25.el6.x86_64.rpm
libcurl-devel-7.29.0-25.el6.x86_64.rpm
安装:
#rpm -Uvh curl-7.29.0-25.el6.x86_64.rpm libcurl-7.29.0-25.el6.x86_64.rpm libcurl-devel-7.29.0-25.el6.x86_64.rpm
#curl –V
curl 7.29.0
二、安装zabbix
创建用户和用户组:
[root@apm ~]# groupadd zabbix
[root@apm ~]# useradd -g zabbix zabbix
源码编译安装(包括Server和Agent):
[root@apm ~]# cd /opt/apm/install
[root@apm install]# tar zxvf zabbix-3.0.4.tar.gz
[root@apm install]# cd zabbix-3.0.4
[root@apm zabbix-3.0.4]# ./configure --prefix=/opt/apm/zabbix/zabbix3 --sysconfdir=/opt/apm/zabbix/zabbix3/etc --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-libcurl
--enable-server #安装Server端
--enable-agent #安装Agent
[root@apm zabbix-3.0.4]# make && make install
SQL文件导入MySQL数据库:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4/database/mysql
[root@apm mysql]# mysql -u zabbix -p zabbix < schema.sql
Enter password: zabbix
[root@apm mysql]# mysql -u zabbix -p zabbix < images.sql
Enter password: zabbix
[root@apm mysql]# mysql -u zabbix -p zabbix < data.sql
Enter password: zabbix
添加系统软连接:
[root@apm install]# ln -s /opt/apm/zabbix/zabbix3/sbin/* /usr/local/sbin/
[root@apm install]# ln -s /opt/apm/zabbix/zabbix3/bin/* /usr/local/bin/
添加MySQL软连接,防止出现server启动失败的情况:
[root@apm lib]# ln -s /usr/local/mysql/lib/* /lib64/
[root@apm lib]# ln -s /usr/local/mysql/lib/* /usr/local/lib64
添加zabbix服务(默认已存在,无需操作):
vi /etc/services #编辑,在最后添加以下代码
# Zabbix
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
:wq! #保存退出
2.1 配置Server:
配置Server启动文件zabbix_server:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4/misc/init.d/fedora/core
[root@apm core]# cp zabbix_server /etc/init.d/
[root@apm core]# cd /etc/init.d/
修改zabbix文件目录,22行:
[root@apm init.d]# vi zabbix_server
21 # Zabbix-Directory
22 BASEDIR=/opt/apm/zabbix/zabbix3
23
修改Server配置文件zabbix_server.conf:
[root@apm init.d]# cd /opt/apm/zabbix/zabbix3/etc/
[root@apm etc]# vi zabbix_server.conf
常用参数列举:
31 ### Option: LogFile
32 # Log file name for LogType 'file' parameter.
33 #
34 # Mandatory: no
35 # Default:
36 # LogFile=
37
38 LogFile=/tmp/zabbix_server.log --日志文件目录
40 ### Option: LogFileSize
41 # Maximum size of log file in MB.
42 # 0 - disable automatic log rotation.
43 #
44 # Mandatory: no
45 # Range: 0-1024
46 # Default:
47 # LogFileSize=1
48 LogFileSize=100 --日志文件大小
70 ### Option: DBHost
71 # Database host name.
72 # If set to localhost, socket is used for MySQL.
73 # If set to empty string, socket is used for PostgreSQL.
74 #
75 # Mandatory: no
76 # Default:
77 # DBHost=localhost
78 DBHost=localhost --数据库地址
63 ### Option: PidFile
64 # Name of PID file.
65 #
66 # Mandatory: no
67 # Default:
68 # PidFile=/tmp/zabbix_server.pid
69 PidFile=/tmp/zabbix_server.pid --pid进程文件目录
79 ### Option: DBName
80 # Database name.
81 # For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored.
82 #
83 # Mandatory: yes
84 # Default:
85 # DBName=
86
87 DBName=zabbix --数据库名称
96 ### Option: DBUser
97 # Database user. Ignored for SQLite.
98 #
99 # Mandatory: no
100 # Default:
101 # DBUser=
102
103 DBUser=zabbix --数据库用户
105 ### Option: DBPassword
106 # Database password. Ignored for SQLite.
107 # Comment this line if no password is used.
108 #
109 # Mandatory: no
110 # Default:
111 # DBPassword=
112 DBPassword=zabbix --数据库密码
113 ### Option: DBSocket
114 # Path to MySQL socket.
115 #
116 # Mandatory: no
117 # Default:
118 # DBSocket=/tmp/mysql.sock
119 DBSocket=/tmp/mysql.sock --数据库socket文件目录
120 ### Option: DBPort
121 # Database port when not using local socket. Ignored for SQLite.
122 #
123 # Mandatory: no
124 # Range: 1024-65535
125 # Default (for MySQL):
126 # DBPort=3306
127 DBPort=3306 --数据库端口号
AlertScriptsPath=/opt/apm/zabbix/zabbix3/alertscripts #可选参数,自定义脚本存放路径
常用的参数配置:
#vi /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log --日志文件目录
LogFileSize=100 --日志文件大小
PidFile=/var/run/zabbix/zabbix_server.pid --pid进程
DBHost=localhost --数据库ip地址
DBName=zabbix --数据库名称
DBUser=zabbix --数据库用户名
DBPassword=zabbix --数据库密码
DBSocket=/tmp/mysql.sock --数据库socket文件目录
DBPort=3306 --数据库端口号
StartTrappers=5
StartPingers=1
StartDiscoverers=1
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
HousekeepingFrequency=1
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
创建zabbix访问站点,并授权:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4
将源码文件中的zabbix-3.0.4/frontends/php目录复制到Apache服务器的站点目录下并修改名称为zabbix:
[root@apm zabbix-3.0.4]# cp -r frontends/php /var/www/html/zabbix
将页面文件属组改为apache.apache
[root@apm zabbix-3.0.4]#chown -R apache.apache /var/www/html/zabbix
设置zabbix_server开机启动:
[root@apm html]# chkconfig zabbix_server on
启动Apache服务器:
[root@apm html]# apachectl start
启动zabbix_server:
[root@apm html]# service zabbix_server start
访问web继续配置:
浏览器访问:http://192.168.120.134/zabbix/setup.php
点击Next step:
显示全部OK即可,点击Next step:
修改数据库端口为3306,密码为zabbix,点击Next step:
设置zabbix Server名称为apm,点击Next step:
信息确认无误,点击Next step:
显示安装成功,点击Finish,跳转到登录界面,默认用户名密码:Admin/zabbix
点击Sign in,登录进入主页面:
2.2 配置Agent:
配置Agent启动文件, zabbix_agentd:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4/misc/init.d/fedora/core
[root@apm core]# cp zabbix_agentd /etc/init.d/
[root@apm core]# cd /etc/init.d/
[root@apm init.d]# vi zabbix_agentd
21 # Zabbix-Directory
22 BASEDIR=/opt/apm/zabbix/zabbix3
创建日志文件存放路径:
mkdir -p /opt/APM/zabbix/zabbix3-agent/log
修改目录权限:
useradd zabbix -s /sbin/nologin
chown zabbix:zabbix /opt/APM/zabbix/zabbix3-agent -R
修改zabbix_agent配置文件,cd到安装目录修改配置文件
vi /opt/apm/zabbix/zabbix3/etc/zabbix_agentd.conf
修改下面内容:
LogFile=/opt/apm/zabbix/zabbix3/log/zabbix_agentd.log #日志文件路径,不存在,需要创建
Server=192.168.120.134 #允许那台SERVER来获取数据
ServerActive=192.168.120.134:10051 #主动向那台SERVER传输数据
Hostname=DeliAPM01 #主机名与WEB界面新增主机时的主机名一致
Include= /opt/apm/zabbix/zabbix3/etc /zabbix_agentd.conf.d/ #额外配置文件路径
UnsafeUserParameters=1 #开启自定义KEY
修改host文件,主机名映射真实ip地址,如:192.168.1.81 APM-Master6,(可选操作,若服务器已配置好,则无需操作)
vi /etc/hosts
192.168.1.81 APM-Master6
启动agent
# service zabbix_agentd start
设置开机启动:
# chkconfig --level 345 zabbix_agentd on
--level <等级代号> 指定读系统服务要在哪一个执行等级中开启或关闭。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
第二种启动方式:
/etc/init.d/zabbix_agentd start
验证:
netstat -anp | grep 10050 #agent对server端端口
ps -elf|grep zabbix #查看是否有进程
1.1 SELINUX关闭
[root@apm install]# vi /etc/selinux/config
SELINUX=disabled
[root@apm install]# setenforce permissive
1.2 MySQL5.5安装及配置
1.2.1 安装mysql5.5
(1) 安装编译环境:
所需依赖包:
cmake-3.6.0.tar.gz
ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
kernel-headers-2.6.32-431.el6.x86_64.rpm --系统已装
glibc-headers-2.12-1.132.el6.x86_64.rpm --系统已装
glibc-devel-2.12-1.132.el6.x86_64.rpm --系统已装
ppl-0.10.2-11.el6.x86_64.rpm
cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
mpfr-2.4.1-6.el6.x86_64.rpm
cpp-4.4.7-4.el6.x86_64.rpm
gcc-4.4.7-4.el6.x86_64.rpm
libstdc++-devel-4.4.7-4.el6.x86_64.rpm
gcc-c++-4.4.7-4.el6.x86_64.rpm
源码安装cmake:
[root@apm install]# cd /opt/apm/install/
[root@apm install]# tar zxvf cmake-3.6.0.tar.gz
[root@apm install]# cd cmake-3.6.0
[root@apm cmake-3.6.0]# ./configure
[root@apm cmake-3.6.0]# gmake
[root@apm cmake-3.6.0]# make&&make install
创建软连接:
[root@apm cmake-3.6.0]# ln -s /usr/local/bin/cmake /usr/bin/cmake
将系统iso镜像挂载到/media目录下,使用yum本地安装:
[root@apm ~]# mount /dev/cdrom /media
[root@apm cmake-3.6.0]# yum localinstall /media/Packages/ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
按照顺序安装gcc:
[root@apm install]# rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm --step1
[root@apm install]# rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm -step2
[root@apm install]# rpm -ivh mpfr-2.4.1-6.el6.x86_64.rpm --step 3
[root@apm install]# rpm -ivh cpp-4.4.7-4.el6.x86_64.rpm --step 4
[root@apm install]# rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm --step 5
[root@apm install]# rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm --step6
按照顺序安装gcc-c++:
[root@apm install]# rpm -ivh libstdc++-devel-4.4.7-4.el6.x86_64.rpm --step 1
[root@apm install]# rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm --step 2
(2)创建用户、用户组、mysql数据存储目录、mysql文件存储目录:
[root@apm install]# groupadd mysql
[root@apm install]# useradd -g mysql mysql -s /bin/false
[root@apm install]# mkdir -p /data/mysql
[root@apm install]# chown -R mysql:mysql /data/mysql
[root@apm install]# mkdir -p /usr/local/mysql
(3)源码编译安装MySQL:
[root@apm install]# tar zxvf mysql-5.5.50.tar.gz
[root@apm install]# cd mysql-5.5.50
[root@apm mysql-5.5.50]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=/data/mysql
[root@apm mysql-5.5.50]# make && make install
1.2.2 配置
(1)修改配置文件:
[root@apm local]# chown -R mysql:mysql /usr/local/mysql/
[root@apm mysql]# cp ./support-files/my-huge.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? yes
[root@apm mysql]# vi /etc/my.cnf
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
datadir = /data/mysql
character-set-server = utf8
max_allowed_packet = 16M
#default-storage-engine = MyISAM
max_connections = 512
event_scheduler = ON #(mysql主从库,主库开启,从库关闭)
lower_case_table_names=1
(2) 修改启动文件,设置开机自启动
修改启动文件:
[root@apm mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@apm mysql]# chmod 755 /etc/rc.d/init.d/mysqld
[root@apm mysql]# vi /etc/rc.d/init.d/mysqld
46行、47行
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/data/mysql
设置开机自启动:
[root@apm mysql]# chkconfig mysqld on
(3)启动
[root@apm mysql]# ./scripts/mysql_install_db --user=mysql
[root@apm mysql]# service mysqld start
(4)编辑环境变量
[root@apm mysql]# vi /etc/profile
在文件最后一行上添加:
unset i
unset -f pathmunge
export TZ=Asia/Shanghai
export JAVA_HOME=/opt/apm/jdk1.8.0_11
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/mysql/bin
[root@apm mysql]# source /etc/profile
(5)设置root密码
设置用户root,密码root
[root@apm mysql]# mysqladmin -u root password "root"
(6)删除匿名用户
[root@apm mysql]# mysql -u root -p
Enter password: root
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Database changed
mysql>select Host,User,Password from user; ---查看当前用户
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| apm.test | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| apm.test | | |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> delete from mysql.user where user=""; --删除匿名用户
Query OK, 2 rows affected (0.00 sec)
mysql> update user set password=PASSWORD('root') where user='root'; -其它root用户设置密码为root
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
(7)创建zabbix数据库
用户名: zabbix 密码:zabbix
[root@apm mysql]# mysql -u root -p
Enter password: root
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
1.3 Apache安装及配置
1.3.1 安装Apache
(1)系统已装
检查系统是否已经安装httpd,发现Centos6.5 已经默认安装httpd2.2.15:
[root@apm httpd-2.4.25]# rpm -qa | grep httpd
httpd-tools-2.2.15-29.el6.centos.x86_64
httpd-2.2.15-29.el6.centos.x86_64
但是缺少aspx命令,对应以下软件包及依赖包:
apr-devel-1.3.9-5.el6_2.x86_64.rpm --step 1
expat-devel-2.0.1-11.el6_2.x86_64.rpm --step 2
cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64.rpm step 3
openldap-devel-2.4.23-32.el6_4.1.x86_64.rpm --step 4
apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm --step 5
httpd-devel-2.2.15-29.el6.centos.x86_64.rpm --step 6 aspx命令在此包中,上述其他包为依赖包
挂载系统iso镜像,在iso系统镜像中,找到依赖包,用yum方式来本地安装:
[root@apm Packages]# yum localinstall /media/Packages/apr-devel-1.3.9-5.el6_2.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/expat-devel-2.0.1-11.el6_2.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/openldap-devel-2.4.23-32.el6_4.1.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/httpd-devel-2.2.15-29.el6.centos.x86_64.rpm
(2)源码安装
源码安装:安装httpd2.4版本时,需要先添加依赖包,解决依赖关系
[root@apm install]# cd /opt/apm/install/
解压:
[root@apm install]# tar zxvf httpd-2.4.25.tar.gz
[root@apm install]# tar zxvf apr-1.5.2.tar.gz
[root@apm install]# tar zxvf apr-util-1.5.4.tar.gz
解决依赖关系:
[root@apm install]# mv apr-1.5.2 httpd-2.4.25/srclib/apr
[root@apm install]# mv apr-util-1.5.4 httpd-2.4.25/srclib/apr-util
[root@apm install]# cd httpd-2.4.25
编译:
[root@apm httpd-2.4.25]# ./configure --prefix=/opt/apm/httpd2.4.25 --sysconfdir=/etc/httpd --with-z --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
编译参数详解:
--prefix:#安装路径
--sysconfdir:#指定配置文件路径
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可实现https访问 需已安装openssl-devel
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能,URL重写
--enable-deflate:#支持压缩功能
--with-zlib:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找 需已安装pcre-devel
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-mpms-shared:#支持动态加载的MPM模块,可选参数:all
--with-mpm:#设置默认启用的MPM模式,{prefork|worker|event}
--enable-modules:#支持动态启用的模块,可选参数:all,most,few,reallyall
#编译之前可使用./configure --help查看各项参数
安装:
[root@apm httpd-2.4.25]# make&& make install
安装完成,启动服务:
[root@apm httpd-2.4.25]# cd /opt/apm/httpd2.4.25
[root@apm httpd-2.4.25]# ./apachectl start
查看80端口是否被监听:
[root@apm httpd-2.4.25]# netstat -ntl | grep 80
可选操作:
1、为了方便命令使用需要添加环境变量,编辑二进制程序如何让系统找到:
# cat /etc/profile.d/apache.sh
PATH=/usr/local/apache/bin:$PATH
export PATH
2、头文件输出给系统:
#ln -sv /usr/local/apache/include /usr/local/include/httpd
3、让系统重新生成库文件路径缓存
#ldconfig -v |grep "^[^[:space:]]"
4、启动apache服务:
# apachectl start
1.3.2 配置
(1)相关文件存放目录:
Apache用户及用户组:apache.apache
Apache站点目录:/var/www/html
httpd命令目录: /etc/init.d/httpd
httpd配置文件目录:/etc/httpd/conf/httpd.conf
[root@apm httpd-2.4.25]# vi /etc/httpd/conf/httpd.conf
135 #Listen 12.34.56.78:80
136 Listen 80 --监听的端口号
137
138 #
273 # You will have to access it by its address anyway, and this will make
274 # redirections work in a sensible way.
275 #
276 #ServerName www.example.com:80
277 ServerName 192.168.120.134:80 --服务器的地址
278 #
290 # symbolic links and aliases may be used to point to other locations.
291 #
292 DocumentRoot "/var/www/html" --网页文件的存放目录
(2)httpd启停命令:
[root@apm httpd-2.4.25]# cd /etc/init.d
[root@apm init.d]# ./httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for apm.test
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@apm init.d]# ./httpd stop --停止httpd服务
Stopping httpd: [ OK ]
第二种启停方式:
[root@apm ~]# apachectl start
[root@apm ~]# apachectl stop
1.4 PHP5.5安装及配置
1.4.1 安装PHP5.5
按如下顺序依次安装缺少的依赖包:
libxml2-2.7.6-14.el6.x86_64.rpm
zlib-devel-1.2.3-29.el6.x86_64.rpm
libxml2-devel-2.7.6-14.el6.x86_64.rpm
openssl-1.0.1e-15.el6.x86_64.rpm
keyutils-libs-devel-1.4-4.el6.x86_64.rpm
libcom_err-devel-1.41.12-18.el6.x86_64.rpm
libsepol-2.0.41-4.el6.x86_64.rpm
pkgconfig-0.23-9.1.el6.x86_64.rpm
libsepol-devel-2.0.41-4.el6.x86_64.rpm
libselinux-devel-2.0.94-5.3.el6_4.1.x86_64.rpm
krb5-devel-1.10.3-10.el6_4.6.x86_64.rpm
openssl-devel-1.0.1e-15.el6.x86_64.rpm
bzip2-devel-1.0.5-7.el6_0.x86_64.rpm
libidn-devel-1.18-2.el6.x86_64.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-4.el6.noarch.rpm
libcurl-devel-7.19.7-37.el6_4.x86_64.rpm
libjpeg-turbo-devel-1.2.1-1.el6.x86_64.rpm
libpng-devel-1.2.49-1.el6_2.x86_64.rpm
freetype-devel-2.3.11-14.el6_3.1.x86_64.rpm
将系统iso镜像挂载到/media目录下:
[root@apm ~]# mount /dev/cdrom /media
[root@apm ~]# cd /media/Packages
使用yum本地安装,依次安装缺少的依赖包:
[root@apm Packages]# yum localinstall /media/Packages/ libxml2-2.7.6-14.el6.x86_64.rpm
[root@apm Packages]# yum localinstall /media/Packages/zlib-devel-1.2.3-29.el6.x86_64.rpm
…
说明:若系统中已安装某软件包,安装后会显示“nothing to do”字样,则忽略此软件包即可。
源码编译安装PHP:
[root@apm install]# tar zxvf php-5.5.37.tar.gz
[root@apm install]# cd php-5.5.37
[root@apm php-5.5.37]#
./configure --prefix=/opt/apm/php5.5 --with-config-file-path=/opt/apm/php5.5/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-dir --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir --with-zlib --with-mysql-sock=/tmp/mysql.sock --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --enable-bcmath --with-apxs2=/usr/sbin/apxs --with-openssl
参数说明:
--prefix PHP安装文件存储目录
--with-config-file-path PHP配置文件存放目录
--with-gettext-mysql MySQL数据库安装文件目录
--with-mysql-sock MySQL sock文件存放目录,可vi MySQL的配置文件,查看目录,即 vi /etc/my.cnf
--with-apxs2 apxs命令存放目录, 可用which apxs 来查看目录
[root@apm php-5.5.37]# make && make install
1.4.2 配置
创建并修改php配置文件:
[root@apm php-5.5.37]# cp php.ini-development /opt/apm/php5.5/etc/php.ini
[root@apm php5.5]# vi /opt/apm/php5.5/etc/php.ini
添加内容:910行:
907 [Date]
908 ; Defines the default timezone used by the date functions
909 ; http://php.net/date.timezone
910 date.timezone = Asia/Shanghai
修改内容:372行:
369 ; Maximum execution time of each script, in seconds
370 ; http://php.net/max-execution-time
371 ; Note: This directive is hardcoded to 0 for the CLI SAPI
372 max_execution_time = 300
373
修改内容,660行:
656 ; Maximum size of POST data that PHP will accept.
657 ; Its value may be 0 to disable the limit. It is ignored if POST data reading
658 ; is disabled through enable_post_data_reading.
659 ; http://php.net/post-max-size
660 post_max_size = 16M
661
修改内容,382行:
374 ; Maximum amount of time each script may spend parsing request data. It's a good
375 ; idea to limit this time on productions servers in order to eliminate unexpectedly
376 ; long running scripts.
377 ; Note: This directive is hardcoded to -1 for the CLI SAPI
378 ; Default Value: -1 (Unlimited)
379 ; Development Value: 60 (60 seconds)
380 ; Production Value: 60 (60 seconds)
381 ; http://php.net/max-input-time
382 max_input_time = 300
修改内容,393行:
391 ; Maximum amount of memory a script may consume (128MB)
392 ; http://php.net/memory-limit
393 memory_limit = 128M
添加内容,1743行:
1733 ; overload(replace) single byte functions by mbstring functions.
1734 ; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
1735 ; etc. Possible values are 0,1,2,4 or combination of them.
1736 ; For example, 7 for overload everything.
1737 ; 0: No overload
1738 ; 1: Overload mail() function
1739 ; 2: Overload str*() functions
1740 ; 4: Overload ereg*() functions
1741 ; http://php.net/mbstring.func-overload
1742 ;mbstring.func_overload = 0
1743 mbstring.func_overload = 0
修改Apache服务器配置文件:
[root@apm php-5.5.37]# vi /etc/httpd/conf/httpd.conf
添加内容:403行;
403 DirectoryIndex index.html index.php index.html.var
添加内容:782行;
780 AddType application/x-compress .Z
781 AddType application/x-gzip .gz .tgz
782 Addtype application/x-httpd-php .php .phtml
1.5升级curl --未操作
CentOS6.5 curl默认版本为curl 7.19.7 , CURL升级为了SMTP Authentication,如果不升级则zabbix服务启动时:/var/log/zabbix/zabbix-server.log则显示:
39715:20160729:144131.510 SMTP authentication: NO
升级curl所需软件包:
curl-7.29.0-25.el6.x86_64.rpm
libcurl-7.29.0-25.el6.x86_64.rpm
libcurl-devel-7.29.0-25.el6.x86_64.rpm
安装:
#rpm -Uvh curl-7.29.0-25.el6.x86_64.rpm libcurl-7.29.0-25.el6.x86_64.rpm libcurl-devel-7.29.0-25.el6.x86_64.rpm
#curl –V
curl 7.29.0
二、安装zabbix
创建用户和用户组:
[root@apm ~]# groupadd zabbix
[root@apm ~]# useradd -g zabbix zabbix
源码编译安装(包括Server和Agent):
[root@apm ~]# cd /opt/apm/install
[root@apm install]# tar zxvf zabbix-3.0.4.tar.gz
[root@apm install]# cd zabbix-3.0.4
[root@apm zabbix-3.0.4]# ./configure --prefix=/opt/apm/zabbix/zabbix3 --sysconfdir=/opt/apm/zabbix/zabbix3/etc --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-libcurl
--enable-server #安装Server端
--enable-agent #安装Agent
[root@apm zabbix-3.0.4]# make && make install
SQL文件导入MySQL数据库:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4/database/mysql
[root@apm mysql]# mysql -u zabbix -p zabbix < schema.sql
Enter password: zabbix
[root@apm mysql]# mysql -u zabbix -p zabbix < images.sql
Enter password: zabbix
[root@apm mysql]# mysql -u zabbix -p zabbix < data.sql
Enter password: zabbix
添加系统软连接:
[root@apm install]# ln -s /opt/apm/zabbix/zabbix3/sbin/* /usr/local/sbin/
[root@apm install]# ln -s /opt/apm/zabbix/zabbix3/bin/* /usr/local/bin/
添加MySQL软连接,防止出现server启动失败的情况:
[root@apm lib]# ln -s /usr/local/mysql/lib/* /lib64/
[root@apm lib]# ln -s /usr/local/mysql/lib/* /usr/local/lib64
添加zabbix服务(默认已存在,无需操作):
vi /etc/services #编辑,在最后添加以下代码
# Zabbix
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
:wq! #保存退出
2.1 配置Server:
配置Server启动文件zabbix_server:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4/misc/init.d/fedora/core
[root@apm core]# cp zabbix_server /etc/init.d/
[root@apm core]# cd /etc/init.d/
修改zabbix文件目录,22行:
[root@apm init.d]# vi zabbix_server
21 # Zabbix-Directory
22 BASEDIR=/opt/apm/zabbix/zabbix3
23
修改Server配置文件zabbix_server.conf:
[root@apm init.d]# cd /opt/apm/zabbix/zabbix3/etc/
[root@apm etc]# vi zabbix_server.conf
常用参数列举:
31 ### Option: LogFile
32 # Log file name for LogType 'file' parameter.
33 #
34 # Mandatory: no
35 # Default:
36 # LogFile=
37
38 LogFile=/tmp/zabbix_server.log --日志文件目录
40 ### Option: LogFileSize
41 # Maximum size of log file in MB.
42 # 0 - disable automatic log rotation.
43 #
44 # Mandatory: no
45 # Range: 0-1024
46 # Default:
47 # LogFileSize=1
48 LogFileSize=100 --日志文件大小
70 ### Option: DBHost
71 # Database host name.
72 # If set to localhost, socket is used for MySQL.
73 # If set to empty string, socket is used for PostgreSQL.
74 #
75 # Mandatory: no
76 # Default:
77 # DBHost=localhost
78 DBHost=localhost --数据库地址
63 ### Option: PidFile
64 # Name of PID file.
65 #
66 # Mandatory: no
67 # Default:
68 # PidFile=/tmp/zabbix_server.pid
69 PidFile=/tmp/zabbix_server.pid --pid进程文件目录
79 ### Option: DBName
80 # Database name.
81 # For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored.
82 #
83 # Mandatory: yes
84 # Default:
85 # DBName=
86
87 DBName=zabbix --数据库名称
96 ### Option: DBUser
97 # Database user. Ignored for SQLite.
98 #
99 # Mandatory: no
100 # Default:
101 # DBUser=
102
103 DBUser=zabbix --数据库用户
105 ### Option: DBPassword
106 # Database password. Ignored for SQLite.
107 # Comment this line if no password is used.
108 #
109 # Mandatory: no
110 # Default:
111 # DBPassword=
112 DBPassword=zabbix --数据库密码
113 ### Option: DBSocket
114 # Path to MySQL socket.
115 #
116 # Mandatory: no
117 # Default:
118 # DBSocket=/tmp/mysql.sock
119 DBSocket=/tmp/mysql.sock --数据库socket文件目录
120 ### Option: DBPort
121 # Database port when not using local socket. Ignored for SQLite.
122 #
123 # Mandatory: no
124 # Range: 1024-65535
125 # Default (for MySQL):
126 # DBPort=3306
127 DBPort=3306 --数据库端口号
AlertScriptsPath=/opt/apm/zabbix/zabbix3/alertscripts #可选参数,自定义脚本存放路径
常用的参数配置:
#vi /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log --日志文件目录
LogFileSize=100 --日志文件大小
PidFile=/var/run/zabbix/zabbix_server.pid --pid进程
DBHost=localhost --数据库ip地址
DBName=zabbix --数据库名称
DBUser=zabbix --数据库用户名
DBPassword=zabbix --数据库密码
DBSocket=/tmp/mysql.sock --数据库socket文件目录
DBPort=3306 --数据库端口号
StartTrappers=5
StartPingers=1
StartDiscoverers=1
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
HousekeepingFrequency=1
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
创建zabbix访问站点,并授权:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4
将源码文件中的zabbix-3.0.4/frontends/php目录复制到Apache服务器的站点目录下并修改名称为zabbix:
[root@apm zabbix-3.0.4]# cp -r frontends/php /var/www/html/zabbix
将页面文件属组改为apache.apache
[root@apm zabbix-3.0.4]#chown -R apache.apache /var/www/html/zabbix
设置zabbix_server开机启动:
[root@apm html]# chkconfig zabbix_server on
启动Apache服务器:
[root@apm html]# apachectl start
启动zabbix_server:
[root@apm html]# service zabbix_server start
访问web继续配置:
浏览器访问:http://192.168.120.134/zabbix/setup.php
点击Next step:
显示全部OK即可,点击Next step:
修改数据库端口为3306,密码为zabbix,点击Next step:
设置zabbix Server名称为apm,点击Next step:
信息确认无误,点击Next step:
显示安装成功,点击Finish,跳转到登录界面,默认用户名密码:Admin/zabbix
点击Sign in,登录进入主页面:
2.2 配置Agent:
配置Agent启动文件, zabbix_agentd:
[root@apm ~]# cd /opt/apm/install/zabbix-3.0.4/misc/init.d/fedora/core
[root@apm core]# cp zabbix_agentd /etc/init.d/
[root@apm core]# cd /etc/init.d/
[root@apm init.d]# vi zabbix_agentd
21 # Zabbix-Directory
22 BASEDIR=/opt/apm/zabbix/zabbix3
创建日志文件存放路径:
mkdir -p /opt/APM/zabbix/zabbix3-agent/log
修改目录权限:
useradd zabbix -s /sbin/nologin
chown zabbix:zabbix /opt/APM/zabbix/zabbix3-agent -R
修改zabbix_agent配置文件,cd到安装目录修改配置文件
vi /opt/apm/zabbix/zabbix3/etc/zabbix_agentd.conf
修改下面内容:
LogFile=/opt/apm/zabbix/zabbix3/log/zabbix_agentd.log #日志文件路径,不存在,需要创建
Server=192.168.120.134 #允许那台SERVER来获取数据
ServerActive=192.168.120.134:10051 #主动向那台SERVER传输数据
Hostname=DeliAPM01 #主机名与WEB界面新增主机时的主机名一致
Include= /opt/apm/zabbix/zabbix3/etc /zabbix_agentd.conf.d/ #额外配置文件路径
UnsafeUserParameters=1 #开启自定义KEY
修改host文件,主机名映射真实ip地址,如:192.168.1.81 APM-Master6,(可选操作,若服务器已配置好,则无需操作)
vi /etc/hosts
192.168.1.81 APM-Master6
启动agent
# service zabbix_agentd start
设置开机启动:
# chkconfig --level 345 zabbix_agentd on
--level <等级代号> 指定读系统服务要在哪一个执行等级中开启或关闭。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
第二种启动方式:
/etc/init.d/zabbix_agentd start
验证:
netstat -anp | grep 10050 #agent对server端端口
ps -elf|grep zabbix #查看是否有进程
上一篇: Redis分布式锁加锁案例