All posts by Pham Thai Thinh

Configure Rsyslog with MySQL on centos 6/7

When build application logging is very important to trace and monitor system. One of most common solution for logging is rsyslog. In default Rsyslog will store log to file, log data to file has some disadvantages compare with database especially when amount data is huge.

Rsyslog provide plugin to work with MySQL, or mongo dB for store log. In this post I will guide how to configure Rsyslog with MySQL to make center logging server on centos 6/7.

On this post I assume that your centos box already install rsyslog and mysql.

1. Install rsyslog-mysql plugin

We run below command to install rsyslog mysql plugin.

sudo yum install rsyslog-mysql

2. Create database for rsyslog and user

Rsyslog provide script to create database and tables to store log. Use this script to create database.

mysql –u root –p </usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql

Now we already has a database name Syslog. We need create a user so that rsyslog can connect to mysql and use Syslog database (avoid using root user).

#mysql –u root –p
mysql> create user ‘syslog’@’localhost’ identified by ‘password_syslog’;
mysql> grant all on Syslog.* to ‘syslog’@’localhost’;
mysql> FLUSH PRIVILEGES;

3. Setup Rsyslog with mysql

Now we need edit rsyslog configuration to make it work with mysql.
We need change file rsyslog.conf, to do that run below command.

sudo vi rsyslog.conf

we add below lines

$ModLoad ommysql
*.*       :ommysql:localhost,Syslog,syslog,password_syslog

We restart rsyslog so it can apply new changes

service rsyslog restart

Now we’ve already finished configure rsyslog to work with MySql also

Tomcat – Disable JSESSIONID in URL

When doing Testing to cover PCI Requirement 6, i face with issue exposed session id  in url, so i write this guie to help other one sort down their time to fix this issue. To fix this issue we have some solutions depend on environment.

https://webapp.com/main.do;jsessionid=557206C363324F1267A24AB769CA0DE4529.node01

1.Tomcat 6

In tomcat 6 we can disable by using disableURLRewriting. We create context.xml file and put following lines and make sure cookie is enable

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="PATH_TO_WEBAPP" path="/CONTEXT" disableURLRewriting="true">
</Context>

2 . Tomcat 7 or above

With Tomcat 7 or above we can add follow lines into web.xml

<session-config>
  <tracking-mode>COOKIE</tracking-mode>
</session-config>

Or we can using programatic

servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));

 

java.lang.NoClassDefFoundError maven project

1. Symptom

Maven project build well but get failure when running in eclipse with the issue

java.lang.NoClassDefFoundError

2. Cause
This issue happen cause jars files is missing at run-time. It do not deploy properly in eclipse when running.

3. Fix
You can right click to project and choose Properties->Deployment Assembly and make sure Maven Dependencies in list

eclipse-project-deployment-assembly

some sites provide testcoin

Testnet bitcoin is a alternative bitcoin block chain to provide for test bitcoin, it allow testers have experiment about bitcoin without actual bitcoin.

Following is some site provide testcoin address and testcoin to use

http://www.bitcointestnetfaucet.com/

http://testnet.bitcoin.peercoinfaucet.com/

http://kuttler.eu/bitcoin/btc/faucet/

To have a wallet of testcoin you can create account on site below

https://test.greenaddress.it/

Apache virtual host and mod_proxy configuration quick start

Virtual host in apache is a term to point to server running more than one web sites on it. Apache Virtual host features support both ip-based and name based virtual host.

  • IP-based: is for config multi web sites run on difference interface and port
  • Name-based: is using diffence name to recognize the host. It allow multi virtual host using same ip and port.

In this port i just guide how  to configure name based virtual host and mod_proxy. Below is example of part of httpd.conf config file to use apache as proxy route difference domain to right machine that host application.

NameVirtualHost *:80 
<VirtualHost *:80>
ServerName api.devjav.com
ProxyPass / http://ip_or_hostname/api/
ProxyPassReverse / http://ip_or_hostname/api/
</VirtualHost>

<VirtualHost *:80>
ServerName api2.devjav.com
ProxyPass / http://other_ip_or_hostname:port/api/
ProxyPassReverse / http://other_ip_or_hostname:port/api2/
</VirtualHost>

In this example i want to route to specific server that host application base on the domain that user access. If users access api.devjav.com it will route to one server, if they access using api2.devjav.com it route to other.
We can use this as option to running multi instance of whitelabel application.

apche- cannot start in windows AH00015: Unable to open logs

Symptom

Install apache on windows successful but when start service it show error.
Open Event Viewer in Application view we see below detail error

AH00015: Unable to open logs

Cause

There are application using 80 port so apache cannot listen on that.
You can check by following command:

C:\Users\ThaiThinh>netstat -ao -p tcp

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:25             ThinhPT-PC:0           LISTENING       1960
  TCP    0.0.0.0:80             ThinhPT-PC:0           LISTENING       3228
  TCP    0.0.0.0:110            ThinhPT-PC:0           LISTENING       1960
  TCP    0.0.0.0:135            ThinhPT-PC:0           LISTENING       852
  TCP    0.0.0.0:143            ThinhPT-PC:0           LISTENING       1960
  TCP    0.0.0.0:443            ThinhPT-PC:0           LISTENING       3228
  TCP    0.0.0.0:445            ThinhPT-PC:0           LISTENING       4
  TCP    0.0.0.0:587            ThinhPT-PC:0           LISTENING       1960
  TCP    0.0.0.0:1025           ThinhPT-PC:0           LISTENING       632
  TCP    0.0.0.0:1026           ThinhPT-PC:0           LISTENING       1000
  TCP    0.0.0.0:1027           ThinhPT-PC:0           LISTENING       396
  TCP    0.0.0.0:1028           ThinhPT-PC:0           LISTENING       1404
  TCP    0.0.0.0:1029           ThinhPT-PC:0           LISTENING       744
  TCP    0.0.0.0:1035           ThinhPT-PC:0           LISTENING       728
  TCP    0.0.0.0:1433           ThinhPT-PC:0           LISTENING       1212
  TCP    0.0.0.0:3306           ThinhPT-PC:0           LISTENING       2272
  TCP    0.0.0.0:63933          ThinhPT-PC:0           LISTENING       3228
  TCP    127.0.0.1:1030         lmlicenses:5354        ESTABLISHED     1612
  TCP    127.0.0.1:1031         lmlicenses:5354        ESTABLISHED     1612
  TCP    127.0.0.1:2186         lmlicenses:2187        ESTABLISHED     3888
  TCP    127.0.0.1:2187         lmlicenses:2186        ESTABLISHED     3888
  TCP    127.0.0.1:2947         lmlicenses:2948        ESTABLISHED     4636
  TCP    127.0.0.1:2948         lmlicenses:2947        ESTABLISHED     4636
  TCP    127.0.0.1:5354         ThinhPT-PC:0           LISTENING       1728
  TCP    127.0.0.1:5354         lmlicenses:1030        ESTABLISHED     1728
  TCP    127.0.0.1:5354         lmlicenses:1031        ESTABLISHED     1728
  TCP    127.0.0.1:5939         ThinhPT-PC:0           LISTENING       3180
  TCP    127.0.0.1:6942         ThinhPT-PC:0           LISTENING       3888
  TCP    127.0.0.1:27015        ThinhPT-PC:0           LISTENING       1612
  TCP    127.0.0.1:50911        ThinhPT-PC:0           LISTENING       2412
  TCP    127.0.0.1:63342        ThinhPT-PC:0           LISTENING       3888
  TCP    192.168.0.101:139      ThinhPT-PC:0           LISTENING       4
  TCP    192.168.0.101:1041     sinwns1011312:https    ESTABLISHED     1636
  TCP    192.168.0.101:3117     192.0.78.22:https      TIME_WAIT       0

You can check PID with Taskmanager to find out which process use this port in my case that is Skype.

Solution

Stop application or change port that application use.

apache- Setup http proxy to add header to Http Headers

In this post i will guide how to setup http proxy to add header to http headrs. To do that we need following plugin:

  • mod_headers

Make sure you’d intalled two above plugin. Add follow config to httpd.conf (change value as your expectation)

ProxyPass / http://localhost:8080/myapp
ProxyPassReverse / http://localhost:8080/myapp
Header set sample_header "sample_value"
RequestHeader set sample_header "sample_value"

Header will add header to http response
RequestHeader will add header to http request.

This plugin very useful for you to know where the request come from when you have many proxy route to web application
You can read more on mod_header document here