Showing posts with label CentOS. Show all posts
Showing posts with label CentOS. Show all posts

Jan 24, 2014

Enable HAProxy logging on CentOS

By default, HAProxy will not log to files unless we make some modifications
1. Create rsyslog configuration file
nano /etc/rsyslog/haproxy.conf
Add these lines to the file
# Enable UDP port 514 to listen to incoming log messages from haproxy
$ModLoad imudp
$UDPServerRun 514
$template Haproxy,"%msg%\n"
local0.=info -/var/log/haproxy/haproxy.log;Haproxy
local0.notice -/var/log/haproxy/admin.log;Haproxy
# don't log anywhere else
local0.* ~
Restart rsyslog service
/etc/init.d/rsyslog restart
Ref: http://blog.hintcafe.com/post/33689067443/haproxy-logging-with-rsyslog-on-linux
2. Modify the log rotate config to match the new folder:
nano /etc/logrotate.d/haproxy
Change
/var/log/haproxy.log {
    daily
    rotate 10
    missingok
[...]
to
/var/log/haproxy/*.log {
    daily
    rotate 10
    missingok
[...]
Now we can check if HAProxy logging is working.
tail -f /var/log/haproxy/haproxy.log

Jan 16, 2014

Synchronize time using NTP on CentOS

If we run CentOS on a virtual machine, there will be time that the server time is off a few seconds or even minutes. We can install and use ntp to update server time:

yum -y install ntp
chkconfig --level 235 ntpd
service ntpd start
date

If we want to manually sync server time with a time server, then we need to stop ntpd service first, then use ntpdate to sync time:

service ntpd stop
ntpdate 0.centos.pool.ntp.org
ntpdate 0.pool.ntp.org
date

Log client's IP address in apache log when using HAProxy and ISPConfig

If we use HAProxy and ISPConfig to publish websites, by default, Apache log will log only the IP of the HAproxy server. To log client's IP in Apache log, we have to:

1. Config HAProxy
Add
option forwardfor to backend option in HAProxy config file, then reload haproxy
service haproxy reload
2. Change the LogFormat for ISPConfig site
Edit ispconfig config file nano /etc/httpd/conf/sites-available/ispconfig.conf Replace LogFormat "%v %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig with LogFormat "%v %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
3. Change the LogFormat for httpd
Edit httpd.conf file nano /etc/httpd/conf/httpd.conf Replace LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined with LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined Save the file and restart apache server service httpd restart
Check the log again. Not as other guides, I still keep the %h because we sometimes need to test the webserver directly. Also, we want to log if there is any other IP accessing our webserver besides the HAProxy.

Jan 3, 2014

VMware Tools are not running after cloning a CentOS VM

After cloning a CentOS virtual machine, the VM status may say that the VMware Tools are not installed and running. If we have installed the VMware Tools in the source VM, then the VMware Tools are still there, we just need to rerun the VMware Tools configuration script
/usr/bin/vmware-config-tools.pl

How to install GlusterFS on CentOS 6.5

1. Install from gluster repo
Install gluster repo cd /etc/yum.repos.d/
wget http://download.gluster.org/pub/gluster/glusterfs/3.4/3.4.0/EPEL.repo/glusterfs-epel.repo
Install gluster server and client yum install glusterfs-server If we want to install only glusterfs client, then run yum install glusterfs-client Start GlusterFS chkconfig --level 235 glusterd on
service glusterd start

2. Install from rpm packages
Download the packages for CentOS mkdir /tmp/glusterfs
cd /tmp/glusterfs
wget -l 1 -nd -nc -r -A.rpm http://download.gluster.org/pub/gluster/glusterfs/LATEST/RHEL/epel-6.5/x86_64/
Install the GlusterFS packages yum install glusterfs-3.4.2-1.el6.x86_64.rpm glusterfs-fuse-3.4.2-1.el6.x86_64.rpm glusterfs-geo-replication-3.4.2-1.el6.x86_64.rpm glusterfs-server-3.4.2-1.el6.x86_64.rpm glusterfs-cli-3.4.2-1.el6.x86_64.rpm glusterfs-libs-3.4.2-1.el6.x86_64.rpm Start GlusterFS chkconfig --level 235 glusterd on
service glusterd start
You may need to change the package names if versions are different. Ref: http://www.howtoforge.com/high-availability-storage-with-glusterfs-3.2.x-on-centos-6.3-automatic-file-replication-mirror-across-two-storage-servers

Jan 18, 2013

Device eth0 does not seem to be present, delaying initialization after you clone CentOS 6 in VMWare

If you get the error "device eth0 does not seem to be present, delaying initialization" after you clone a CentOS 6 VMWare machine, there's a simple solution

1. In /etc/udev/rules.d/70-persistent-net.rules, disable the old eth0 NIC
nano /etc/udev/rules.d/70-persistent-net.rules

1.1 Comment out line
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:9b:62:83", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

1.2 Change "eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:9e:42:91", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

to "eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:9e:42:91", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"