Deploy openresty + lua + zabbix,openrestyzabbix


OS: CentOS6.5 64Bit
Architecture: openresty + lua + zabbix


Configure mysql

#yum install -y mysql-server mysql-devel
#chkconfig --level 35 mysqld on
#chkconfig --list mysqld
mysqld          0:off   1:off   2:off   3:on    4:off   5:on    6:off

Setup root’s passwd

# mysql -uroot -proot
mysql> use mysql;
mysql> update user set password=password('xxx') where user='root' and host='localhost';
mysql> flush privileges;

Configure php-fpm and depends by zabbix_server

# yum install -y php-fpm php-mysql php-bcmath php-mbstring php-gd php-xml libxml2-devel net-snmp-devel libcurl-devel

# chkconfig --level 35 php-fpm on
# chkconfig --list php-fpm
php-fpm         0:off   1:off   2:off   3:on    4:off   5:on    6:off

Configure zabbix-server

1 Download the source archive zabbix-2.4.6.tar.gz

# tar -zxvf zabbix-2.4.0.tar.gz

2 Create user account for zabbix

# useradd zabbix
# usermod zabbix -s /sbin/nologin

3 Create Zabbix database

shell> mysql -u<username> -p<password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'xxxx';
mysql> quit;
shell> cd zabbix-2.4.6
shell> mysql -uzabbix> -p<password> zabbix < database/mysql/schema.sql
### stop here if you are creating database for Zabbix proxy
shell> mysql -uzabbix -p<password> zabbix < database/mysql/images.sql
shell> mysql -uzabbix -p<password> zabbix < database/mysql/data.sql

4 Configure the sources

At first,install depends:
# yum install -y libxml2-devel net-snmp-devel libcurl-devel

To configure the sources for a Zabbix server and agent, you may run something like:

./configure --prefix=/usr/local/zabbix2.4 --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java
  • --with-libxml2 configuration option is required for virtual machine monitoring, supported since Zabbix 2.2.0.
  • --enable-java Turn on build of Zabbix Java gateway, For monitor tomcat

To configure the sources for a Zabbix agent, you may run:

./configure --enable-agent

5 Install zabbix

make install

6 Review and edit configuration files

edit the Zabbix agent configuration file: /usr/local/etc/zabbix_agentd.conf

  • You need to configure this file for every host with zabbix_agentd installed.
  • You must specify the Zabbix server IP address in the file. Connections from other hosts will be denied.

For example:

# grep -v ^# zabbix_agentd.conf|grep -v '^$'
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.01
Hostname=Zabbix server
UnsafeUserParameters=1

edit the Zabbix server configuration file: /usr/local/etc/zabbix_server.conf

  • You must specify the database name, user and password (if using any).

For example:

LogFile=/var/log/zabbix_server.log
DBHost=localhost
DBName=xxx
DBUser=xxx
DBPassword=xxxx
Timeout=30

7 Start up the daemons

# cp zabbix-2.4.6/misc/init.d/fedora/core/* /etc/init.d/

### Check
# ls /etc/init.d/ |grep zabbix
zabbix_agentd
zabbix_server

### start zabbix-server,zabbix-agent
# service zabbix_server start
# service zabbix_agentd start

2 Installing Zabbix web interface

Copying PHP files

mkdir <htdocs>/zabbix
cd frontends/php
cp -a . <htdocs>/zabbix

Configure openresty

Install depends:

# yum install -y readline-devel pcre-devel openssl-devel gcc

Download ngx_openresty

# useradd nginx
# usermod nginx -s /sbin/nologin

# wget https://openresty.org/download/ngx_openresty-1.9.3.1.tar.gz
# tar -xf ngx_openresty-1.9.3.1.tar.gz
# cd ngx_openresty-1.9.3.1
# ./configure --prefix=/usr/local/openresty --user=nginx --group=nginx
# gmake
# gmake install

Configure vhost for zabbix:

# grep -E -v '(#|^$)' /usr/local/openresty/nginx/conf/nginx.conf

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   /xxx/zabbix/;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           /xxx/zabbix/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

# call lua process
        location /aa {
           default_type 'text/plain';
           content_by_lua 'os.execute("/abs-path/sh-name.sh")';
           rewrite ^/aa /abs-path/aa.html last;
         }
    }
}

Start openresty

# cd /usr/local/openresty/nginx/sbin
# ./nginx

Verify:

# ps aux |grep nginx |grep -v grep
root     14571  0.0  0.0  52480  1316 ?        Ss   Oct27   0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx
nginx    14572  0.0  0.0  52976  2484 ?        S    Oct27   0:08 nginx: worker process

# netstat -anlp |grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      14571/nginx 

......

END.

相关内容

    暂无相关文章