Centos安装Zabbix

来源:互联网 发布:淘宝怎么用版权投诉 编辑:程序博客网 时间:2024/06/05 15:52

from:https://www.zabbix.com/wiki/doku.php?id=howto/install/centos/centosinstall

Installing Zabbix on CentOS/RedHat

This page shows a few methods of installing various versions of Zabbix on various versions of CentOS.

Zabbix on RHEL/CentOS 4, 5 and 6 using packages

Must be in two steps. First you have to configure the EPEL repository fromhttp://fedoraproject.org/wiki/EPEL/FAQ#howtouse.

And then you can install Zabbix as on Fedora with

# yum install zabbix zabbix-agent zabbix-web

where

  • zabbix is Zabbix server
  • zabbix-agent is Zabbix Agent
  • zabbix-web is Zabbix Web interface
  • zabbix-proxy (optional) is Zabbix Proxy

The agent and server config file are then located in /etc/zabbix directory.

Note: it currently installs version 1.8.10 (December 2011) on RHEL/CentOS 6. See here for updates.

For RHEL/CentOS 5 there is only the obsolete Zabbix version 1.4.7 in the EPEL repository.

RHEL/CentOS 4 doesn't support web server monitoring due too old curl library.

Zabbix 1.8.x on CentOS using source (automated)

For Zabbix 1.8.2 see

http://blog.brendon.com/unix/installing-zabbix-18x-on-centos-the-easy-way/

For Zabbix 1.8.3 and 1.8.4 see

https://github.com/manoot/Zabbix-Easy-Install

Zabbix 1.8.x on CentOS using source (manual)

Works also with Zabbix 1.8.1 - 1.8.5 and CentOS 5.4 - 6.0. I have also tested this with Zabbix 1.9.5 on RHEL 5.7

This Guide is for installing Zabbix 1.8.1 on CentOS 5.4 using a MySQL Database, I assume you have installed CentOS with Apache, MySQL, PHP, and a Mail Server during the Setup.

# will indicate that we are using the prompt as the root user

$ will indicate that we are using the prompt as a different user

Setting up the user accounts

The Zabbix server and client both need a user account that they can run on, so may as well set this up first. This also needs to be done on every monitored machine that is running the Zabbix agent:

# groupadd -g 130 zabbix# useradd -u 130 -g zabbix -c 'Zabbix monitoring' zabbix

I have added the ”-u 130” parameter – this ensures that the zabbix user gets created with the same user ID on every server that we created it on, as well as with the zabbix group (which will be group id 130).

Zabbix Installation

We will be installing following components:

  • Zabbix Server (for gathering data)
  • Zabbix Agent (for monitoring)
  • Net-SNMP (for SNMP Support)
  • Jabber (for notifications)
  • OpenIPMI (for monitoring)
  • cURL (for web monitoring)

All these commands are done with the user root, starting of from the root home folder /root

Dependencies

First install all the dependencies with yum using the command

# yum install zlib-devel mysql-devel glibc-devel curl-devel gcc automake mysql libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-devel

CentOS should find all packages in its Repo's and do the rest for you. For Jabber we will need the packages iksemel-devel wich depends on iksemel, however these RPM's aren't in the CentOS Repo's so we will be use them from EPEL instead.

Configure the EPEL repository from http://fedoraproject.org/wiki/EPEL/FAQ#howtouse:

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Than we can install the following packages with yum

# yum --enablerepo=epel install iksemel iksemel-devel

Compile and Install Source

Now that we have our dependencies set up we need to download the actual source, this can also be done with the wget command.

# wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.1/zabbix-1.8.1.tar.gz?use_mirror=freefr

After it has downloaded the file we can unzip and untar with following command.

# gunzip zabbix-1.8.1.tar.gz && tar -xvf zabbix-1.8.1.tar

This should have created a folder called zabbix-1.8.1 in your home directory. Next we need to browse to the directory and configure our setup.

# cd zabbix-1.8.1# ./configure --enable-server --with-mysql --with-net-snmp --with-jabber --with-libcurl --with-openipmi --enable-agent

If you encounter any problems you should read the error messages carefully and check the config.log located in the same directory. If all goes well it will print out your configuration, please make sure following is set:

Enable server:         yesWith database:         MySQLWEB Monitoring via:    cURLNative Jabber:         yesSNMP:                  net-snmpIPMI:                  openipmiEnable agent:          yes

If everything matches the above we can carry on with the command make

# make

After make has compiled all the stuff we can use CHECKINSTALL as described in the next chapter - OR - we could simply proceed as usual with:

# make install

checkinstall

After make has compiled we won't be using make install, but checkinstall which gives us the option to first make a RPM out of the installation and than install it. This gives us the advantage to be able to deinstall Zabbix again with rpm. Because checkinstall also isn't on the CentOS Repo we will download it using wget to our home directory.

# cd ..# wget http://dag.wieers.com/rpm/packages/checkinstall/checkinstall-1.6.0-3.el5.rf.i386.rpm

and than install checkinstall with rpm and rpmbuild with yum

# rpm -ivh checkinstall-1.6.0-3.el5.rf.i386.rpm# yum install rpm-build

Now we can use checkinstall to make a RPM and install it.

# cd zabbix-1.8.1# checkinstall --nodoc --install=yes -y

You Should be able to choose what kind of package that you wish you create, because CentOS is based on RedHat we are going for [R], type R and press Enter.

If you don't encounter any errors you should get following output:

**********************************************************************Done. The new package has been installed and saved to/usr/src/redhat/RPMS/i386/zabbix-1.8.1-1.i386.rpmYou can remove it from your system anytime using:     rpm -e zabbix-1.8.1-1**********************************************************************

Now Zabbix is installed.

A 64 bit version of checkinstall RPM can be downloaded fromhttp://code.google.com/p/atyu30/downloads/detail?name=checkinstall-1.6.2-3.1.x86_64.rpm&can=2&q=

Creating the MySQL DB

We will have to create a database for Zabbix and than import scripts which will do the rest for us.

First of make sure the MySQL daemon is running using

# service mysqld status

If not you can start it with

# service mysqld start

If this is the first time MySQL is started, you will probably get a message telling you that root has no password. Change the root password to something safe which you won't forget with

# mysqladmin -u root password 'new-password-here'

After the password has been set, its recommended to run the following script in your console to secure your MySQL installation

# mysql_secure_installation

Now that we have set a root pw and secured our db we can connect to it, to create a new db for Zabbix.

# mysql -u root -p

and enter the password you set before. Then let us create the db with

mysql> create database zabbix character set utf8;

Next we want to tell MySQL that our zabbix user hast he rights to mess with the db so lets give him all rights

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'set-password-here';mysql> quit;

It's important to remember this password as we a going to need it for the Zabbix config files. Now we are going to import the sql scripts into the db so we have tables, and data

# cd create/schema# cat mysql.sql | mysql -u zabbix -p zabbix# cd ../data# cat data.sql | mysql -u zabbix -p zabbix# cat images_mysql.sql | mysql -u zabbix -p zabbix

To make sure the script worked we can list the tables of the Zabbix database to see if any where created.

mysql> use zabbix;mysql> show tables;mysql> quit;

If any problems occur the easiest way is to delete the db with

mysql> drop database zabbix; 

and start from the beginning again.

Configuring Zabbix

Now lets create a folder for Zabbix where the config files are stored and then copy the appropriate files.

# mkdir /etc/zabbix# cd ../..# cp misc/conf/{zabbix_server.conf,zabbix_agentd.conf} /etc/zabbix/

For the beginning the Zabbix agent config file can be left as how it is, but we do need to tell Zabbix where our database is to be found, for that open /etc/zabbix/zabbix_server.conf with your favourite editor

# nano /etc/zabbix/zabbix_server.conf

Look for DBName, with Nano you can do this with Ctrl+W, than type in DBName and press enter. The default value it is set to zabbix, so we can leave that as how it is, but we do need to change the user and password set DBUser to zabbix and DBPassword to the one you set during the MySQL configuration above.

DBName=zabbixDBUser=zabbixDBPassword=your-zabbix-mysql-password

Now Zabbix knows where to connect to and with which login information

Permissions and Running Zabbix Server

It is recommended to change the file permissions for the Zabbix config so not every user can just read the password out of our file

# chmod 400 /etc/zabbix/zabbix_server.conf# chown zabbix /etc/zabbix/zabbix_server.conf

Now we can execute the script zabbix_agentd and zabbix_server which are found in /usr/local/sbin/

# /usr/local/sbin/zabbix_agentd# /usr/local/sbin/zabbix_server

if all went well you shouldn't get any error messages.

It's not actually necessary to su to the zabbix user before running these processes. The zabbix agent and server processes will actually change user IDs themselves provided that the user accounts exist.

To check if Zabbix is running we can grep the output of all running processes

$ ps -e | grep zabbix

You should see several processes running as zabbix_server and zabbix_agentd, and hopefully they will be running as the zabbix user.

Its all nice that the server is up and running, but latest until the next reboot of the server, Zabbix wont be running anymore. To make the this process run automatically we will have to add the server and the agent to the system startup sequence.

Creating startup scripts

Zabbix comes with startup scripts but it should be mentioned that these scripts are old. Never the less they will still work. All that is needed to be done are minor changes in the scripts.

Login in back to root

$ su -

After a successful login let us copy the scripts from our Zabbix source into our /etc/init.d/ folder. this can be done with the following command:

# cd zabbix-1.8.1# cp misc/init.d/redhat/8.0/zabbix_* /etc/init.d/

this will copy zabbix_server and zabbix_agentd startup scripts.

Open zabbix_server with your favourite editor.

# nano /etc/init.d/zabbix_server

and than change the progdir to progdir=”/usr/local/sbin/” . Do the exactly the same with zabbix_agentd.

Now let us add it to the services with

# chkconfig --add zabbix_server# chkconfig --add zabbix_agentd

all that is left, it to tell the system on which runlevels it should start them, we are going to use runlevel 3 and 5.

# chkconfig --level 35 zabbix_server on# chkconfig --level 35 zabbix_agentd on

to verify that the changes have been made, we can use chkconfig to list all configurations with

# chkconfig --list

or to just show the zabbix services we can customize our output with grep

# chkconfig --list | grep zabbix

All that is left to be done, is to make these scripts executable, this is done with the following command

# chmod 755 /etc/init.d/zabbix_server# chmod 755 /etc/init.d/zabbix_agentd

Now we can control our scripts with

# service zabbix_server {start|stop|restart|condrestart}

Installing the Web frontend

We have Zabbix Server and Agent installed and running on our server, we can control the them with services and they startup each time the machine boots into runlevel 3 or 5 but we still don't have our Web frontend.

This is where Apache and PHP come into play. We will need to install some extra php packages for full functionality

# yum install php-mysql php-gd php-bcmath php-mbstring php-xml

Once installed its time to copy the web files to the correct folder, with CentOS and Apache this would be /var/www/html/.

# cp -r frontends/php/ /var/www/html/

To make the page accessable through http://localhost/zabbix we will have to to rename the folder to zabbix.

# mv /var/www/html/php/ /var/www/html/zabbix

Now you should now be able to access the Web frontend trough http://localhost/zabbix

If you encounter problems try checking if the httpd service is running. If it worked you should see the Welcome screen from Zabbix

Don't worry if you get a timezone warning in the upper lines - we'll fix it later. Read the Text and continue with the Next » button.

Agree to the GNU v2 Licence and carry on.

Most Likely Zabbix won't agree with all of your settings and will tell you to change them to the requiered settings. In my case these are all php related problems. Open php.ini with your favourite editor

# nano /etc/php.ini

and change following:

max_execution_time = 600memory_limit = 256Mpost_max_size = 32Mdate.timezone = Europe/Zurichmbstring.func_overload = 2

To make the changes noticable you will have to restart the httpd service

PHP provides a table of all supported timezones underhttp://www.php.net/manual/en/timezones.php

If you hover with your mouse over the FAIL sign it should describe the problem. If you encounter any extra problems you should be able to find thse problems out with the web. Than after a restart of httpd it should all be OK

# service httpd restart

Fill in the Information as above and use the password you gave zabbix when you configured your DB. You can test the connection with the button Test connection.

Leave the Information as it is and continue the Setup

It will summarise your Installation, continue the setup.

Most likely saving your config file won't work, instead of changing the permissions we will download the file localy to the specified path. If your not on the server you can either copy the file through ssh if your using Linux or through winscp if your using Windows.

That's it, we're finished :-)

Zabbix 1.6.x on CentOS using source (automated)

http://blog.brendon.com/unix/installing-zabbix-the-easy-way/

Zabbix 1.4 on Cent OS using source

Use the following steps to install Zabbix 1.4 on CentOS

These steps assume that you have a dedicated server/ virtual server that you can format the harddrive and delete any data already on the server.

It also assumes that you will run the Zabbix server process, web frontend and database on the same server. This is fine for most small to medium installations and if you run into issues with performance you can always split it up later.

Also note that the installation below has virtually no security on it - you should setup passwords for the mysql root account and create a dbuser with password for zabbix but that is outside the scope of this article.

Preliminary Steps:

Install CentOS (you can use the ServerCD as I like to start with the minimal install and add packages as necessary).

There are many How To's for installing CentOS so I am not going to go step by step. For a newbie the only steps you should be aware of are:

A) Firewall Configuration Step you should select “No Firewall” and set SELinux to Disabled. You can always change them later as your skills increase but for now (assuming the server is already behind a firewall) you should be okay.

B) On the Package Installation Defaults step Choose “Customize Software Packages To Install”

C) On the Package Group Selection step Choose “Minimal Install” (near the bottom).

D) After Installation is complete and server has rebooted you should use yum to update the installation as soon as possible to get all the latest fixes and security patches. Log into server as root (using password supplied during setup).

[root@zabbix ~]# yum -y update

You should then reboot (especially if there was a new kernel installed).

[root@zabbix ~]# reboot

Installing Prerequisites:

[root@zabbix ~]# yum install httpd php mysql mysql-server mysql-devel php-gd php-mysql gcc net-snmp net-snmp-libs net-snmp-utils net-snmp-devel curl-devel

If you are running CentOS 4.x then you need to get a newer version of curl and curl-devel

[root@zabbix ~]# cd /usr/src

Note: broken URLs

[root@zabbix src]# wget http://curl.mirrors.cyberservers.net/download/libcurl4-devel-7.16.2-1.i386.rpm

[root@zabbix src]# wget http://curl.mirrors.cyberservers.net/download/libcurl4-7.16.2-1.i386.rpm

[root@zabbix src]# yum install openssl096b

[root@zabbix src]# yum remove curl-devel

[root@zabbix src]# rpm -i libcurl4*

Obtaining Zabbix and Installing Server:

[root@zabbix ~]# cd /usr/src

In the commands below be sure to change the filename to the latest version (i.e zabbix-1.4.6.tar.gz or zabbix-1.4.6)

[root@zabbix src]# wget http://internap.dl.sourceforge.net/sourceforge/zabbix/zabbix-1.4.5.tar.gz

[root@zabbix src]# tar zxf zabbix-1.4.5.tar.gz

[root@zabbix src]# cd zabbix-1.4.5

Start up/initialize and create mysql database (Section 3.4.5 Step 3 in Manual)

[root@zabbix zabbix-1.4]# service mysqld start

[root@zabbix zabbix-1.4]# mysql -u root

mysql> create database zabbix;

mysql> quit

[root@zabbix zabbix-1.4]# cat create/schema/mysql.sql | mysql -u root zabbix

[root@zabbix zabbix-1.4]# cat create/data/data.sql | mysql -u root zabbix

[root@zabbix zabbix-1.4]# cat create/data/images_mysql.sql | mysql -u root zabbix

Compile and Install Server/Agent (Section 3.4.5 Steps 4-10 in Manual)

[root@zabbix zabbix-1.4]# ./configure –enable-server –enable-agent –with-mysql –with-net-snmp –with-libcurl

[root@zabbix zabbix-1.4]# make install

[root@zabbix zabbix-1.4]# mkdir /etc/zabbix

[root@zabbix zabbix-1.4]# cp misc/conf/zabbix_agentd.conf /etc/zabbix

[root@zabbix zabbix-1.4]# cp misc/conf/zabbix_server.conf /etc/zabbix

Zabbix will not run as root so we need to setup a user for zabbix to run under (Section 3.4.5 Step 1 in Manual)

[root@zabbix zabbix-1.4]# groupadd zabbix

[root@zabbix zabbix-1.4]# useradd -g zabbix zabbix

[root@zabbix zabbix-1.4]# chown zabbix:zabbix /usr/local/sbin/zabbix*

Install Zabbix as a service

[root@zabbix zabbix-1.4]# cp misc/init.d/fedora/core/zabbix* /etc/init.d

we need to modify these scripts for the paths we are using (there are some vi instructions available on the web but see below for some common functions)

[root@zabbix zabbix-1.4]# vi /etc/init.d/zabbix_agentd

change BASEDIR=/opt/zabbix to BASEDIR=/usr/local/sbin

change FULLPATH=$BASEDIR/bin/$BINARY_NAME to FULLPATH=$BASEDIR/$BINARY_NAME

[root@zabbix zabbix-1.4]# vi /etc/init.d/zabbix_server

make the same changes as above

[root@zabbix zabbix-1.4]# chkconfig –add zabbix_agentd

[root@zabbix zabbix-1.4]# chkconfig –add zabbix_server

Set services to auto start when server boots

[root@zabbix zabbix-1.4]# chkconfig –level 3 httpd on

[root@zabbix zabbix-1.4]# chkconfig –level 3 mysqld on

[root@zabbix zabbix-1.4]# chkconfig –level 3 zabbix_server on

[root@zabbix zabbix-1.4]# chkconfig –level 3 zabbix_agentd on

Install frontend

[root@zabbix zabbix-1.4]# mkdir /var/www/html/zabbix

[root@zabbix zabbix-1.4]# cp -R frontends/php/* /var/www/html/zabbix

[root@zabbix zabbix-1.4]# chown apache:apache /var/www/html/zabbix/conf

[root@zabbix zabbix-1.4]# vi /etc/php.ini

find resource limits section and change max_execution_time to 300

;;;;;;;;;;;;;;;;;;; ; Resource Limits ; ;;;;;;;;;;;;;;;;;;;

max_execution_time = 300 ; Maximum execution time of each script, in seconds

Start services

[root@zabbix zabbix-1.4]# service httpd start

[root@zabbix zabbix-1.4]# service zabbix_server start

[root@zabbix zabbix-1.4]# service zabbix_agentd start

now follow Manual from Section 3.4.5 Step 1 on

Zabbix should now be installed and working on local server. You should use the manual for the rest of the setup/configuration process

0 0
原创粉丝点击