网络上很多zabbix安装教程都是基于mysql的,基于postgresql的比较少,国外的也不多见,为此将自己参考国外的教程以及自己的亲身安装体验总结一下分享!
环境:ubuntu server 14.04.3
首先主机名称,因为apache服务要求,为了节省麻烦,就按照其要求先修改吧
sudo vim /etc/hostname
本来的主机名为 zabbix,修改为
zabbix.test.me
之后就是修改hosts
sudo vim /etc/hosts
修改为
127.0.0.1 localhost.localdomain localhost 127.0.1.1 zabbix.test.me zabbix
然后保存,如果想hostname即时生效,可以
sudo hostname zabbix.test.me
也可以重启。
sudo aptitude install zabbix-server-pgsql zabbix-frontend-php php5-pgsql libapache2-mod-php5
完成后,首先修改postgresql的配置文件(不然后面使用postgres用户导入数据会因权限不足而出错!)
sudo vim /etc/postgresql/9.3/main/pg_hba.conf
修改以下内容(peer-->trust,md5-->trust)
84 # Database administrative login by Unix domain socket 85 local all postgres peer(修改) 86 87 # TYPE DATABASE USER ADDRESS METHOD 88 89 # "local" is for Unix domain socket connections only 90 local all all peer(修改) 91 # IPv4 local connections: 92 host all all 127.0.0.1/32 md5(修改) 93 # IPv6 local connections: 94 host all all ::1/128 md5 95 # Allow replication connections from localhost, by a user with the
然后重启postgresql server
sudo service postgresql restart
解压原有*.gz包,因为等一下要用sql语句创建数据库
sudo gunzip /usr/share/zabbix-server-pgsql/*.gz
只有登录postgres账号
sudo su - postgres
并且转到postgresql环境中
postgres@ub0-1:~$ psql
postgres=# create user zabbix with password 'zabbix'; postgres=# create database zabbix owner zabbix;
退出psql
\q
在posgres用户操作导入schema、image、data
postgres@ub0-1:~$ psql -U zabbix -d zabbix < /usr/share/zabbix-server-pgsql/schema.sql postgres@ub0-1:~$ psql -U zabbix -d zabbix < /usr/share/zabbix-server-pgsql/images.sql postgres@ub0-1:~$ psql -U zabbix -d zabbix < /usr/share/zabbix-server-pgsql/data.sql
顺序不能错,不然会报错!
退出postgres用户
exit
sudo vim /etc/zabbix/zabbix_server.conf
默认情况下DBName和DBUser已经设置好,当然如果你在psql环境下新建的用户名和数据库名称不一样,就需要修改了,现在只需要添加DBpassword就可以了,最后复制原有的行,然后修改
81 ### Option: DBName 82 # Database name. 83 # For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored. 84 # Sample SQLite3 DBName: 85 # DBName=/var/lib/zabbix/zabbix.sqlite3 86 # 87 # Mandatory: yes 88 # Default: 89 # DBName= 90 91 DBName=zabbix 92 93 ### Option: DBSchema 94 # Schema name. Used for IBM DB2. 95 # 96 # Mandatory: no 97 # Default: 98 # DBSchema= 99 100 ### Option: DBUser 101 # Database user. Ignored for SQLite. 102 # 103 # Mandatory: no 104 # Default: 105 # DBUser= 106 107 DBUser=zabbix 108 109 ### Option: DBPassword 110 # Database password. Ignored for SQLite. 111 # Comment this line if no password is used. 112 # 113 # Mandatory: no 114 # Default: 115 # DBPassword= 116 DBPassword=zabbix
拷贝已有的zabbix配置模板
sudo cp /usr/share/doc/zabbix-frontend-php/examples/zabbix.conf.php.example /etc/zabbix/zabbix.conf.php
拷贝已有的apache配置模板
sudo cp /usr/share/doc/zabbix-frontend-php/examples/apache.conf /etc/apache2/conf-available/zabbix.conf
修改zabbix配置模板
aews@ub0-1:~$ sudo vim /etc/zabbix/zabbix.conf.php
1 <?php 2 // Zabbix GUI configuration file 3 global $DB; 4 5 // Valid types are MYSQL, SQLITE3 or POSTGRESQL 6 $DB["TYPE"] = 'POSTGRESQL'; 7 $DB["SERVER"] = 'localhost'; 8 $DB["PORT"] = '0'; 9 10 // SQLITE3 use full path to file/database: $DB["DATABASE"] = '/var/lib/zabbix/zabbix.sqlite3'; 11 $DB["DATABASE"] = 'zabbix'; 12 $DB["USER"] = 'zabbix'; 13 $DB["PASSWORD"] = 'zabbix'; 14 // SCHEMA is relevant only for IBM_DB2 database 15 $DB["SCHEMA"] = ''; 16 17 $ZBX_SERVER = 'localhost'; 18 $ZBX_SERVER_PORT = '10051'; 19 $ZBX_SERVER_NAME = ''; 20 21 $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG; 22 ?>
按照实际修改,第6行,默认是"MYSQL"的,我改为postgresql,还有第13行,修改实际数据库创建时的密码,其实11-13行都要按实际修改。
aews@ub0-1:~$ sudo a2enconf zabbix.conf aews@ub0-1:~$ sudo a2enmod alias aews@ub0-1:~$ sudo service apache2 restart
aews@ub0-1:~$ sudo vim /etc/php5/apache2/php.ini
post_max_size = 16M max_execution_time = 300 max_input_time = 300 date.timezone = Asia/Chongqing
按照要求修改一下字段部分,就重启zabbix server就可以了
aews@ub0-1:~$ sudo service zabbix-server restart
访问页面
http://x.x.x.x/zabbix
用户名:Admin
密码:zabbix
reference:
https://thedutchlab.com/en/news/installing-zabbix-on-ubuntu-14-04
http://devops-inf.blogspot.com/2013/05/install-script-zabbix-2-ubuntu.html