Zabbix3的离线安装
背景与环境
由于实际情况需求,zabbix在局域网中进行部署,遇到许多问题,在此记录。
- 操作系统:CentOS 6.9(使用的最小安装)
- zabbix版本:zabbix-3.0.13(LTS)
- php版本:php-5.6.32(必须要使用5.4及以上的版本)
- 关闭iptables和selinux
- 需要本地的yum源
- 调整本机的硬件和系统时钟,与现实情况一致
- 还有一些需要下载的,后面再说明
一、Mysql安装与配置
// (1)安装
# yum install -y mysql-server mysql-devel
// (2)开启
# service mysqld start
// (3)修改密码为root
# /usr/bin/mysqladmin -u root password 'root'
// (4)设置root用户的远程登录
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; mysql> flush privileges;
设置UTF8
(1)修改/etc/my.cnf
# 在[mysqld]下添加utf8
[mysqld]
...
default-character-set=utf8
(2)重启mysql服务
# service mysqld restart
(3)修改其他字符集
# mysql -uroot -p // 查看字符集,除了database其余都是 latin1 mysql> show variables like "% character %"; | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary| | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | latin1 | | character_sets_dir | /usr/share/mysql/charsets/ | // 修改这些字符集。 //注:filesystem不用修改 mysql> set character_set_client=utf8; mysql> set character_set_connection=utf8; ... // 修改完查看一下,即可 mysql> show variables like "% character %"; | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary| | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ |
二、基础软件的安装
基于搭建好本地yum源后方可使用,不然是需要连接互联网。
# yum install gcc gcc-c++ libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel bzip2 bzip2-devel readline readline-devel httpd httpd-devel -y
这些软件中,大部分是用于php的编译的,特别是最后一个,用于apache能够识别*.php文件,不然显示的就是代码
三、PHP编译与安装
3.1 libmcrypt安装
(1)下载地址:http://mcrypt.hellug.gr/lib/
(2)编译安装
# tar -zxvf libmcrypt-2.5.7.tar.gz # cd libmcrypt-2.5.7 # ./configure --prefix=/usr/local/ # make # make install
3.2 --enble-opchahe启用
(1)如果不开启这个功能,编译时会遇到错误
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
(2)在/etc/ld.so.conf的配置文件中添加下面这句
/usr/local/lib
效果如下所示
# cat /etc/ld.so.conf include ld.so.conf.d/*.conf /usr/local/lib
(3)执行命令,即可
# ldconfig
3.3 PHP的编译安装
# tar zxvf php-5.6.32.tar.gz # cd php-5.6.32 # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --with-apxs2=/usr/sbin/apxs **(注:apxs2是需要安装httpd-devel才能使用的)** # make -j8 # make install
3.4 php-fpm服务配置
(接着上面的目录)
# cp php.ini-development /usr/local/php/etc/php.ini # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod +x /etc/init.d/php-fpm // 添加用户 # groupadd www # useradd -g www -s /sbin/nologin -M www // 开启php-fpm服务 # service php-fpm start
3.5 添加php命令
编辑 ~/.bash_profile
PATH=$PATH:$HOME/bin
改为
PATH=$PATH:$HOME/bin:/usr/local/php/bin
执行命令,使其生效
# . ~/.bash_profile # php -v PHP 5.6.32 (cli) (built: Jan 11 2018 14:53:21) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
3.6 添加php-gd
(1)安装jpegsrc(下载地址:http://www.ijg.org/)
# tar -zxvf jpegsrc.v9b.tar.gz # cd jpeg-9b/ # ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static # make && make install
(2)编译安装php-gd
# cd /opt/php-5.6.32/ext/gd/ # /usr/local/php/bin/phpize # ./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir --with-freetype-dir # make && make install
(3)编辑/usr/local/php/etc/php.ini
添加如下内容
extension=gd.so
(4)重启php-fpm
# service php-fpm restart
3.7 修改httpd
vi /etc/httpd/conf/httpd.conf # 添加如下内容 AddType application/x-httpd-php-source .phps AddType application/x-httpd-php .php # 查看一下内容是否存在 LoadModule php5_module modules/libphp5.so
3.8 验证
(1)创建php页面
# vi /var/www/html/test.php <?php phpinfo(); ?>
(2)运行httpd
# service httpd start
(3)访问页面:localhost/test.php
四、Zabbix编译与安装
(1)编译与安装
# tar -zxvf zabbix-3.0.13.tar.gz # cd zabbix-3.0.13 # ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql --enable-net-snmp --with-libcurl # make # make install
(2)修改server配置
# vi /usr/local/zabbix/etc/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=root DBPassword=root DBSocket=/var/lib/mysql/mysql.sock // 查看本地mysql.sock的位置
(3)添加zabbix用户
# useradd zabbix
(4)添加开机脚本
cd /opt/zabbix-3.0.13 cp misc/init.d/fedora/core5/zabbix_server /etc/rc.d/init.d/zabbix_server cp misc/init.d/fedora/core5/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd chmod u+x /etc/rc.d/init.d/zabbix_server chmod u+x /etc/rc.d/init.d/zabbix_agentd chkconfig zabbix_server on chkconfig zabbix_agentd on
(5)更改脚本路径
-----更改zabbix_server路径 vim /etc/init.d/zabbix_server ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server" -----更改zabbix_agentd路径 vim /etc/init.d/zabbix_agentd ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
(6)启动
service zabbix_server start
service zabbix_agented start
(7)验证端口
# netstat -nltp |grep 10050 tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1193/zabbix_agentd # netstat -nltp |grep 10051 tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 1175/zabbix_server
五、Zabbix-web安装
(1)拷贝zabbix-web工程到apache目录
# cp -r /opt/zabbix-3.0.13/frontends/php/* /var/www/html/
(2)添加配置文件
# vi /etc/httpd/conf.d/zabbix.conf php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value always_populate_raw_post_data -1 php_value date.timezone Asia/Shanghai
(3)导入数据库
先创建一个数据库,名称为zabbix # mysql -uroot -proot zabbix </opt/zabbix-3.0.13/database/mysql/schema.sql # mysql -uroot -proot zabbix </opt/zabbix-3.0.13/database/mysql/images.sql # mysql -uroot -proot zabbix </opt/zabbix-3.0.13/database/mysql/data.sql
六、Zabbix-web向导
向导配置很简单,填入数据库信息即可(与zabbix_server.conf一样),最后一步略有不同。
会显示一个报错提示,如图所示
此时,只要按照英文提示,下载文件再重命名放到/var/www/html/conf/zabbix.conf.php即可。下载的这个文件zabbix.conf.php.example,一定不要从工程目录中删除,否则工程会跑不起来。
本文转载自:https://segmentfault.com/a/1190000012818998