Proxylizer/Getting Started: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
(5 intermediate revisions by the same user not shown)
Line 5: Line 5:
== Install ==
== Install ==


All the examples assume that Proxylizer server IP address is 10.1.1.2;
All the examples assume that Proxylizer server IP address is 10.1.1.2.


The installation includes steps for setting up the following:
The installation includes steps for setting up the following:
* [[Proxylizer/Getting Started#Mikrotik router | Mikrotik router:]]
* [[Proxylizer/Getting Started#Mikrotik router | Mikrotik router:]]
# [[Proxylizer/Getting Started#Web-proxy log export to remote host (Proxylizer server) | Web-proxy log export to remote host]]
** [[Proxylizer/Getting Started#Web-proxy log export to remote host (Proxylizer server) | Web-proxy log export to remote host]]
* [[Proxylizer/Getting Started#Proxylizer server | Proxylizer server:]]
* [[Proxylizer/Getting Started#Proxylizer server | Proxylizer server:]]
# [[Proxylizer/Getting Started#Web page scripts | Web page scripts]]
** [[Proxylizer/Getting Started#Web page scripts | Web page scripts]]
# [[Proxylizer/Getting Started#Permissions for directories | Permissions for directories]]
** [[Proxylizer/Getting Started#Permissions for directories | Permissions for directories]]
# [[Proxylizer/Getting Started#Syslog deamon | Syslog deamon]]
** [[Proxylizer/Getting Started#Syslog deamon | Syslog deamon]]
# [[Proxylizer/Getting Started#Web server with PHP and PHP-Pear | Web server with PHP and PHP-Pear]]
** [[Proxylizer/Getting Started#Web server with PHP and PHP-Pear | Web server with PHP and PHP-Pear]]
# [[Proxylizer/Getting Started#MySQL database server | MySQL database server]]
** [[Proxylizer/Getting Started#MySQL database server | MySQL database server]]
# [[Proxylizer/Getting Started#MySQL user for proxylizer database | MySQL user for proxylizer database]]
** [[Proxylizer/Getting Started#MySQL user for proxylizer database | MySQL user for proxylizer database]]
# [[Proxylizer/Getting Started#Scheduled scripts for forwarding records from syslog to MySQL and report generation | Scheduled scripts for forwarding records and report generation]]
** [[Proxylizer/Getting Started#Scheduled scripts for forwarding records from syslog to MySQL and report generation | Scheduled scripts for forwarding records and report generation]]


===Mikrotik router===
===Mikrotik router===
Line 32: Line 32:
==== Web page scripts ====
==== Web page scripts ====


[[Proxylizer/Getting Started#Download | Download]] proxylizer archive. Create directory and extract it in web page root directory.
[[Proxylizer/Getting Started#Download | Download]] proxylizer archive. Create directory and extract it in web page root directory:
<pre>sudo mkdir /var/www/proxylizer/
<pre>sudo mkdir /var/www/proxylizer/
sudo tar -xvzf /var/www/proxylizer/</pre>
sudo tar -xvzf /var/www/proxylizer/</pre>


==== Permissions for directories ====
==== Permissions for directories ====
Open console. Change ownership of web page root directory for web server user
Change ownership of web page root directory for web server user:


<pre> chown proxylizer:www-data /var/www/proxylizer -R </pre>
<pre> chown proxylizer:www-data /var/www/proxylizer -R </pre>


Set write permissions to web page root directory for web server user
Set write permissions to web page root directory for web server user:


<pre> chmod g+w /var/www/proxylizer </pre>
<pre> chmod g+w /var/www/proxylizer </pre>


Set permissions to execute 3 shell script files for web server user group.
Set permissions to execute 3 shell script files for web server user group:
<pre>
<pre>
cd /var/www/proxylizer
cd /var/www/proxylizer
Line 53: Line 53:
==== Syslog daemon ====
==== Syslog daemon ====


Install syslog-ng daemon.
Install syslog-ng daemon:
<pre>apt-get install syslog-ng</pre>
<pre>apt-get install syslog-ng</pre>
WARNING : If you have Ubuntu OS syslog-ng can conflict with ubuntu-minimal package! You can remove this package.  
WARNING : If you have Ubuntu OS syslog-ng can conflict with ubuntu-minimal package! You can remove this package.  


Change syslog-ng config to receive logs from Mikrotik router and put them into mysql.pipe file. Open /etc/syslog-ng/syslog-ng.conf and add these lines next to "#destinations"  
Change syslog-ng config to receive logs from Mikrotik router and put them into mysql.pipe file. Open /etc/syslog-ng/syslog-ng.conf and add these lines next to "#destinations" :
<pre>
<pre>
destination d_mysql {
destination d_mysql {
Line 65: Line 65:
log { source(net); destination(d_mysql); };
log { source(net); destination(d_mysql); };
</pre>
</pre>
And this line next to "#sources"
And this line next to "#sources":
<pre>source net { udp(); }</pre>
<pre>source net { udp(); }</pre>


Create pipe file.
Create pipe file:


<pre>mkfifo /home/proxylizer/mysql.pipe</pre>
<pre>mkfifo /home/proxylizer/mysql.pipe</pre>
Set destination of .pipe file in /var/www/proxylizer/webproxylogtomysql.php. At the beginning of the file you must change variable value in the line <pre>$MYSQL_PIPE = "/home/proxylizer/mysql.pipe";</pre>
Set destination of .pipe file in /var/www/proxylizer/webproxylogtomysql.php. At the beginning of the file you must change variable value in the line:
<pre>$MYSQL_PIPE = "/home/proxylizer/mysql.pipe";</pre>


restart syslog
restart syslog:


<pre>/etc/init.d/syslog-ng restart</pre>
<pre>/etc/init.d/syslog-ng restart</pre>
Line 79: Line 80:
==== Web server with PHP and PHP-Pear ====
==== Web server with PHP and PHP-Pear ====


Install web server (we recommend Apache2), PHP5, PHP5-cli and PHP-Pear : DB, Mail, Mail_Mime and Net_SMTP packages.
Install web server (we recommend Apache2), PHP5, PHP5-cli and PHP-Pear : DB, Mail, Mail_Mime and Net_SMTP packages:
<pre>apt-get install libapache2-mod-php5 php5-cli php-pear php-db php-mail php-mail-mime php-net-smtp</pre>
<pre>apt-get install libapache2-mod-php5 php5-cli php-pear php-db php-mail php-mail-mime php-net-smtp</pre>


==== MySQL database server ====
==== MySQL database server ====


Install MySQL database server.
Install MySQL database server:
<pre> apt-get install mysql-server mysql-client </pre>
<pre> apt-get install mysql-server mysql-client </pre>


==== MySQL user for proxylizer database ====
==== MySQL user for proxylizer database ====


Default user name for mysql database is root with no password. But we recomend to change it for security reasons.<br> Connect to mysql server and create new database and user.
Default user name for mysql database is root with no password. But we recomend to change it for security reasons.<br> Connect to mysql server and create new database and user:
<pre>
<pre>
mysql -u root
mysql -u root
create database proxylizerdb;
CREATE DATABASE proxylizerdb;
grant all privileges on proxylizerdb.* to proxylizer@localhost identified by "password" with grant option;
GRANT ALL PRIVILEGES ON proxylizerdb.* TO proxylizer@localhost IDENTIFIED BY "password" WITH GRANT OPTION;
flush privileges;Scheduled scripts for forwarding records from syslog to MySQL and report generation
FLUSH PRIVILEGES;
</pre>
</pre>


==== Scheduled scripts for forwarding records from syslog to MySQL and report generation ====
==== Scheduled scripts for forwarding records from syslog to MySQL and report generation ====


Create directory for script logs and set permesions.
Create directory for script logs and set permesions:
<pre>
<pre>
mkdir /var/log/proxylizer
mkdir /var/log/proxylizer
Line 106: Line 107:
</pre>
</pre>


Put two scripts in cron sheduler. First create crontab file for web server system user
Put two scripts in cron sheduler. First create crontab file for web server system user:
<pre>
<pre>
nano /home/proxylizer/proxylizercrontab
nano /home/proxylizer/proxylizercrontab
</pre>
</pre>
and copy these lines.
and copy these lines:
<pre>
<pre>
SHELL=/bin/sh
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* *    * * *          /var/www/proxylizer/mail_send.php >> /var/log/mail_send_log.log
* *    * * *          /var/www/proxylizer/mail_send.php >> /var/log/proxylizer/mail_send_log.log
* *    * * *          /var/www/proxylizer/checkwebproxy.sh >> /var/log/checkwebproxy.log &
* *    * * *          /var/www/proxylizer/checkwebproxy.sh >> /var/log/proxylizer/checkwebproxy.log &
</pre>
</pre>
Set scheduler tasks from this file
Set scheduler tasks from this file:
<pre>crontab proxylizercrontab</pre>
<pre>crontab /home/proxylizer/proxylizercrontab</pre>

Revision as of 13:49, 8 January 2009

Download

You can download proxylizer archive here.

Install

All the examples assume that Proxylizer server IP address is 10.1.1.2.

The installation includes steps for setting up the following:

Mikrotik router

Web-proxy log export to remote host (Proxylizer server)

To forward logs from Mikrotik Router to Proxylizer server, open RouterOS console and type in the following commands:

/system logging action add name=sendToProxylizer target=remote remote=10.1.1.2:514
/system logging add topics=web-proxy action=sendToProxylizer

Note that logs are sent to port number 514, it must be equal with the port on which Syslog daemon on Proxylizer server is listening.

Proxylizer server

All the examples assume that web page root directory is "/var/www/proxylizer", web server user is "www-data", Proxylizer server system user is "proxylizer" and .pipe file destination/name is "/home/proxylizer/mysql.pipe".

Web page scripts

Download proxylizer archive. Create directory and extract it in web page root directory:

sudo mkdir /var/www/proxylizer/
sudo tar -xvzf /var/www/proxylizer/

Permissions for directories

Change ownership of web page root directory for web server user:

 chown proxylizer:www-data /var/www/proxylizer -R 

Set write permissions to web page root directory for web server user:

 chmod g+w /var/www/proxylizer 

Set permissions to execute 3 shell script files for web server user group:

cd /var/www/proxylizer
chmod g+x checkwebproxy.sh mail_send.php webproxylogtomysql.php

Syslog daemon

Install syslog-ng daemon:

apt-get install syslog-ng

WARNING : If you have Ubuntu OS syslog-ng can conflict with ubuntu-minimal package! You can remove this package.

Change syslog-ng config to receive logs from Mikrotik router and put them into mysql.pipe file. Open /etc/syslog-ng/syslog-ng.conf and add these lines next to "#destinations" :

destination d_mysql {
pipe("/home/proxylizer/mysql.pipe"
template("$HOST $YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC $MSG\n") template-escape(yes));
};
log { source(net); destination(d_mysql); };

And this line next to "#sources":

source net { udp(); }

Create pipe file:

mkfifo /home/proxylizer/mysql.pipe

Set destination of .pipe file in /var/www/proxylizer/webproxylogtomysql.php. At the beginning of the file you must change variable value in the line:

$MYSQL_PIPE = "/home/proxylizer/mysql.pipe";

restart syslog:

/etc/init.d/syslog-ng restart

Web server with PHP and PHP-Pear

Install web server (we recommend Apache2), PHP5, PHP5-cli and PHP-Pear : DB, Mail, Mail_Mime and Net_SMTP packages:

apt-get install libapache2-mod-php5 php5-cli php-pear php-db php-mail php-mail-mime php-net-smtp

MySQL database server

Install MySQL database server:

 apt-get install mysql-server mysql-client 

MySQL user for proxylizer database

Default user name for mysql database is root with no password. But we recomend to change it for security reasons.
Connect to mysql server and create new database and user:

mysql -u root
CREATE DATABASE proxylizerdb;
GRANT ALL PRIVILEGES ON proxylizerdb.* TO proxylizer@localhost IDENTIFIED BY "password" WITH GRANT OPTION;
FLUSH PRIVILEGES;

Scheduled scripts for forwarding records from syslog to MySQL and report generation

Create directory for script logs and set permesions:

mkdir /var/log/proxylizer
chown proxylizer:proxylizer /var/log/proxylizer
chmod u+w /var/log/proxylizer

Put two scripts in cron sheduler. First create crontab file for web server system user:

nano /home/proxylizer/proxylizercrontab

and copy these lines:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* *     * * *           /var/www/proxylizer/mail_send.php >> /var/log/proxylizer/mail_send_log.log
* *     * * *           /var/www/proxylizer/checkwebproxy.sh >> /var/log/proxylizer/checkwebproxy.log &

Set scheduler tasks from this file:

crontab /home/proxylizer/proxylizercrontab