วันอังคารที่ 22 พฤศจิกายน พ.ศ. 2554

การส่ง Apache Syslog-ng สำหรับ Web Server

#yum remove rsyslog ==> [Y]

#wget http://www.silfreed.net/download/repo/packages/syslog-ng/syslog-ng-2.1.1-4.el5.x86_64.rpm

** สำหรับ Centos 6.0 ต้อมเพิ่มคำสั่ง นี้ **
#yum install eventlog*

#rpm -Uvh syslog-ng-2.1.1-4.el5.x86_64.rpm

#chkconfig syslog-ng on

#vim /etc/httpd/conf/httpd.conf
Line - 486 ErrorLog syslog-ng
Line - 493 LogLevel notice
Line - 529 CustomLog "|/root/script/apache_syslog" combined

#mkdir /root/script
#vim /root/script/apache_syslog
#!/usr/bin/perl
use Sys::Syslog qw(:DEFAULT setlogsock);
setlogsock('unix');
openlog('apache','cons,pid','local3');
while($log = < STDIN > ) #เขียนให้ติดกัน
{
syslog('notice',$log);
}
Closelog
#vim /etc/syslog-ng/syslog-ng.conf
destination d_mysql {
program("/usr/bin/mysql -usyslogadmin -psyslogadmin -h172.17.3.32 syslog"
template("CREATE TABLE IF NOT EXISTS log$YEAR$MONTH$DAY (server varchar(15) NOT NULL,host varchar(128) DEFAULT NULL,facility varchar(10) DEFAULT NULL,priority varchar(10) DEFAULT NULL,level varchar(10) DEFAULT NULL,tag varchar(10) DEFAULT NULL,logtime datetime DEFAULT NULL,program varchar(15) DEFAULT NULL,msg text,seq bigint(20) unsigned NOT NULL AUTO_INCREMENT,counter int(11) NOT NULL DEFAULT '1',fo datetime DEFAULT NULL,lo datetime DEFAULT NULL,PRIMARY KEY (seq)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n INSERT INTO log$YEAR$MONTH$DAY (server,host, facility, priority, level, tag, logtime, program, msg)
VALUES ( '172.17.3.15','$HOST', '$FACILITY', '$PRIORITY', '$LEVEL', '$TAG',
'$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC', '$PROGRAM', '$MSG' );\n")
template-escape(yes));};

filter f_weblog { facility(local3); };

log { source(s_sys); filter(f_weblog); destination(d_mysql); };
#/etc/init.d/httpd restart
#/etc/init.d/syslog-ng restart

การปรับปรุง EPEL

หลายท่านอาจใช้คำสั่ง yum แล้วพอว่า no such packageซึ่งจริง ๆ แล้วนอกจากการใช้
rpmforg แล้วอีกหนึ่งคำสั่งที่ควรใช้คือการ ปรับปรุง EPEL

#wget ftp://rpmfind.net/linux/epel/6/x86_64/epel-release-6-5.noarch.rpm

#rpm -Uhv epel-release-6-5.noarch.rpm

เท่านี้ก็จะสามารถใช้งาน yum ได้มากขึ้น

ปล. ควรเข้าไปตรวจดูในเว็บว่า CentOS ที่ติดตั้งตรงกับรุ่งใหน เช่น 32 bits และ 64 bits

อ้างอิงจาก http://fedoraproject.org/wiki/EPEL

วันพฤหัสบดีที่ 1 กันยายน พ.ศ. 2554

การ Clone VM CentOS 6.0 ใน VirtualBox

หากท่านเคยทำการ Clone VM ในโปรแกรม Virtual Box คงพบกับปัญหาเรื่องการตั้งค่าการ์ดเครือข่าย ใน CentOS 6.0 วิธีการแก้ไข ทำได้ 2 วิธี คือ
ขั้นที่ 1
#vim /etc/udev/rules.d/70-persistent-net.rules

จากนั้นเข้าสู่หน้าแสดง ให้ทำการตรวจสอบ Mac Address ของการ์ดที่มีปัจจุบัน
แล้วให้ลบการ์ดที่ีไม่มี และทำการเปลี่ยน eth1 กลับไปสู่ eth0 แล้วทำการแก้ไขไฟล์ในขั้นที่ 2

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

***ที่สำคัญ ให้ตรวจสอบ Mac Address ให้ถูกต้องและปรับ IP Address ตามต้องการ ***

เมื่อทำตามขั้นตอนครบถ้วนให้ทำการ Restart โดย
#init 6

วันศุกร์ที่ 1 กรกฎาคม พ.ศ. 2554

ยามดึก กับ snmp บน CentOS5

วันนี้ดึกแล้วนะครับ ขอเขียนอะไรไว้เตือนความจำสักเรื่อง สำหรับเรื่องของการ Monitor Server โดยติดต่อผ่าน SNMP Protocol คงขาดไม่ได้สำหรับโปรแกรมที่มีชื่อว่า Net-SNMP โดยขอสรุปขั้นตอนการติดตั้งไว้ดังนี้นะครับ ส่วนภาคขยายสำหรับงานเฉพาะคงตอนต่อไป
Install
การติดตั้งโดยการใช้คำสั่ง yum
#yum install net-snmp net-snmp-utils

ติดตั้งแล้วคงต้อง Download นะครับ อย่าลืมกด Y
Configure
เริ่มต้นสำรองไฟล์กันก่อนครับ เผื่อเกิดความผิดพลาดจะได้ กลับมาถูกทาง
#cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.old
แก้ไข snmpd.conf เพื่อเพิ่มความสามารถในการตรวจสอบค่าและ การเชื่อมต่อจากภายนอก
#vim /etc/snmp/snmpd.conf
แทรกบรรทัดที่ 39 rocommunity public
แก้ไขบรรทัดที่ 162 Chang to ==> syslocation "LMS Server"
สำหรับ protocol นี้ ต้อง start service หลายตัวนิดนึงนะครับ มีดังนี้ ครับ
# /etc/init.d/snmpd start
#/etc/init.d/snmptrapd start
เมื่อเปิดครบ 2 บริการนี้ เราจะดูการทำงานได้แล้วครับ อย่าลืม ตั้งให้มันทำการ start เองนะครับ
# chkconfig snmpd on
#chkconfig snmptrapd on

Test
สำหรับคำสั่งพื้นฐานเพื่อให้รู้ว่าสามารถคุยกับเครื่อง server ผ่าน SNMP ได้คือ
# snmpwalk -v 1 -c public -O e localhost

เท่านี้ เราสามรถใช้งาน SNMP Protocol ได้แล้วครับ สำหรับการอ่านค่าที่มีความซับซ้อนคงต้องไปตั้งค่า Configure กับแล้วครับ ติดตามตอนต่อไปนะครับ

ทำการทดสอบเรียกอ่านค่าจากเครื่องลูกข่ายหรือ เครื่องที่ต้องการ ด้วยโปรแกรม MIB Browser
Download from http://ireasoning.com/mibbrowser.shtml

หมายเหตุ หากต้องการอ่านค่าการทำงานของ CPU RAM และ Disk สามารถศึกษาเพิ่มเติมได้ที่
http://www.debianadmin.com/linux-snmp-oids-for-cpumemory-and-disk-statistics.html



ที่สำคัญครับ เปิด firewall ด้วยนะครับ
  • 161/udp SNMP
  • 162/udp SNMPTRAP

อ้างอิงจาก
http://www.it-slav.net/blogs/2008/11/11/install-and-configure-snmp-on-rhel-or-centos/
http://forums.solidhost.com/showthread.php?t=470

วันอังคารที่ 11 มกราคม พ.ศ. 2554

Nocat Gateway Authen with CentOs 5.5


วันนี้หลายคนคงรู้จักระบบ Authentication server หลายตัว แต่ตัวนี้อาจยุ่งอยากในการติดตั้งสักนิดแต่ใช้ร่วมกับระบบอื่นได้มากกว่า

ขั้นตอนที่ 1 เตรียมติดตั้ง DHCP ให้ระบบ

#yum install dhcp

1. ทำการสร้าง dhcpd.conf

#cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

* ทำการแก้ไขตามกลุ่มเครือข่ายที่กำหนดไว้

#vim /etc/dhcpd.conf

หมายเหตุ ขั้นตอนการใช้ vi และ vim ขอข้ามในช่วงหลัง กด I เพื่อทำการ Insert

ddns-update-style interim;

ignore client-updates;

DHCPARGS=eth1;

subnet 200.0.0.0 netmask 255.255.255.0 {

# --- default gateway

option routers 200.0.0.1;

option subnet-mask 255.255.255.0;

option domain-name "coe.psu.ac.th"; # name server isp

option domain-name-servers 172.30.0.5;

option domain-name-servers 172.30.0.9;

option time-offset -18000; # Eastern Standard Time

# option ntp-servers 192.168.1.1;

# option netbios-name-servers 192.168.1.1;

# --- Selects point-to-point node (default is hybrid). Don't change this unless

# -- you understand Netbios very well

# option netbios-node-type 2;

range dynamic-bootp 200.0.0.100 200.0.0.200;

default-lease-time 21600;

max-lease-time 43200;

# we want the nameserver to appear at a fixed address

host ns {

next-server marvin.redhat.com;

hardware ethernet 12:34:56:78:AB:CD;

fixed-address 207.175.42.254;

}

หมายเหตุ ขั้นตอนการใช้ vi และ vim ขอข้ามในช่วงหลัง เมื่อกำหนดค่าเสร็จเรียบร้อย Esc+ “:wq” เพื่อทำการบันทึก

#chkconfig dhcpd on

#/etc/init.d/dhcpd start

#chkconfig httpd on

#/etc/init.d/httpd start

ข้อตอนที่ 2. การเตรียม SSL สำหรับ Apache

#yum install mod_ssl openssl

บรรทัดนี้ Generate private key ทำการสร้าง Generate CSR
#openssl genrsa -out ca.key 1024

#openssl req -new -key ca.key -out ca.csr

ขอขยายความนะ ครับ

Country Name (2 letter code) [XX]: TH >Enter

State or Province Name (full name) []:SK >Enter

Locality Name (eg, city) [Default City]: >Enter

Organization Name (eg, company) [Default Company Ltd]: >Enter

Organizational Unit Name (eg, section) []: test >Enter

Common Name (eg, your name or your server's hostname) []: test.com >Enter

Email Address []:admin@test.com >Enter

A challenge password []: >Enter

An optional company name []: >Enter

ทำการสร้าง Generate Self Signed Key

#openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

ทำการย้าย files ไปยังที่สำหรับกำหนด

#mv ca.crt /etc/pki/tls/certs

#mv ca.key /etc/pki/tls/private/

#mv ca.csr /etc/pki/tls/private/

ทำการแก้ไขไฟล์

#vim +/SSLCertificateFile /etc/httpd/conf.d/ssl.conf

ทำการแก้ไข บรรทัดต่อไปนี้ให้เป็นตามที่กำหนด
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key

เสร็จกระบวนการแล้วให้ทำการ restart service ใหม่
#/etc/init.d/httpd restart

หากต้องตรวจสอบให้ทำการเรียกผ่านเว็บที่เครื่องลูกข่าย https://IP Server/ ถ้าเรียกขึ้นแสดงว่า Web server รองรับ ssl แต่หากเรียกไม่ผ่าน หรือ ฟ้อง Error ให้ทดลองอ่านเพิ่มเติมดู ที่

http://wiki.centos.org/HowTos/Https

ขั้นตอนที่ 3 ติดตั้ง NoCat Authen

เตรียมความพร้อมโดยติดตั้ง โปรแกรมสนับสนุนเพิ่มก่อน

#yum install perl*

#yum install gnupg

เข้าสู่กระบวนการติดตั้ง

Download with command

#wget http://nocat.net/download/NoCatAuth/NoCatAuth-nightly.tgz

#cp NoCatAuth-nightly.tgz /root

#cd /root

#tar zxvf NoCatAuth-nightly.tgz

#cd NoCatAuth-nightly

ทำการปรับค่า Linux จาก 2.4 เป้น 2.6

#vim bin/detect-fw.sh

ทำการแก้ไข เลข 2.4 เป็น 2.6

ขั้นตอนสำหรับการติดตั้ง gateway และ Authen แบบ Same Machine

#make PREFIX=/usr/local/nocat/gw gateway
#make PREFIX=/usr/local/nocat/authserv authserv
#make PREFIX=/usr/local/nocat/authserv pgpkey

------------------------------------------------------------------------------------

Looking for gpg...

[ -d /usr/local/nocat/authserv/pgp ] || mkdir /usr/local/nocat/authserv/pgp

chmod 700 /usr/local/nocat/authserv/pgp

gpg --homedir=/usr/local/nocat/authserv/pgp --gen-key

gpg (GnuPG) 1.4.7; Copyright (C) 2006 Free Software Foundation, Inc.

This program comes with ABSOLUTELY NO WARRANTY.

This is free software, and you are welcome to redistribute it

under certain conditions. See the file COPYING for details.

gpg: keyring /usr/local/nocat/authserv/pgp/secring.gpg' created

gpg: keyring /usr/local/nocat/authserv/pgp/pubring.gpg' created

Please select what kind of key you want:

(1) DSA and Elgamal (default)

(2) DSA (sign only)

(5) RSA (sign only)

Your selection?

DSA keypair will have 1024 bits.

ELG-E keys may be between 1024 and 4096 bits long.

What keysize do you want? (2048)

Requested keysize is 2048 bits

Please specify how long the key should be valid.

0 = key does not expire

= key expires in n days

w = key expires in n weeks

m = key expires in n months

y = key expires in n years

Key is valid for? (0)

Key does not expire at all

Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID

from the Real Name, Comment and Email Address in this form:

"Heinrich Heine (Der Dichter) "

Real name: Authenication server

Name must be at least 5 characters long
Email address: admin@yourdomain.com

Comment: WIFI Authen

You selected this USER-ID:

"Authenication server (WIFI Authen) "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o

You need a Passphrase to protect your secret key.

You don't want a passphrase - this is probably a *bad* idea!

I will do it anyway. You can change your passphrase at any time,

using this program with the option "--edit-key".

--------------------------------------------------------------------------------------------------

ระหว่างนี้ระบบจะแนะนำให้กด แป้น Keyboard ไปเรื่อย ๆ เพื่อไม่ให้ระบบเข้าสู่ sleep mode ไม่นานครับไม่เกิน 1 นาที อดทนนิดนึง

gpg: /usr/local/nocat/authserv/pgp/trustdb.gpg: trustdb created

gpg: key ACF06752 marked as ultimately trusted

public and secret key created and signed.

gpg: checking the trustdb

gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model

gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u

pub 1024D/ACF06752 2007-10-20

Key fingerprint = 7A1A BC17 C129 8894 AEFD BAA4 4F31 0B7A ACF0 6752

uid Authenication server (WIFI Authen)

sub 2048g/ABD7FC22 2007-10-20
cp -R /usr/local/nocat/authserv/pgp/pubring.gpg /usr/local/nocat/authserv/trustedkeys.gpg

cp -R /usr/local/nocat/gw/pgp/pubring.gpg /usr/local/nocat/authserv/trustedkeys.gpg
The public key ring you'll need to distribute can be found in

/usr/local/nocat/authserv/trustedkeys.gpg.

เมื่อเสร็จกระบวนการมีบรรทัดด้านบนปรากฏ

*** ควรตรวจสอบว่า Directory /usr/local/nocat/authserv/pgp สามารถเขียนอ่านได้นะครับ

ทำการย้ายไฟล์ key ไป พร้อมเปลี่ยนสิทธิการใช้งานให้กับ web service (Apache)

#cp /usr/local/nocat/authserv/trustedkeys.gpg /usr/local/nocat/authserv/pgp/
#cp /usr/local/nocat/authserv/trustedkeys.gpg /usr/local/nocat/gw/pgp/
#chown -R apache.apache /usr/local/nocat/authserv
#chown -R apache.apache /usr/local/nocat/gw

ขั้นที่ 4 ทำการเตรียม Mysql สำหรับบริหารจัดการผู้ใช้ระบบ

#chkconfig mysqld on

#/etc/init.d/mysqld start

#mysqladmin –u root password 123456

การเตรียมฐานข้อมูลสำหรับระบบ Nocat

#mysqladmin create nocat -p (and hit the password you set on Mysql admin)

#cd /root/NoCat..../etc

#mysql -u root -p nocat < nocat.schema

Install phpMyAdmin for management your mysql via web page

# wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/2.11.10.1/phpMyAdmin-2.11.10.1-all-languages.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fphpmyadmin%2Ffiles%2FphpMyAdmin%2F2.11.10.1%2F&ts=1312044975&use_mirror=cdnetworks-kr-2

# tar -zxvf phpMyAdmin-2.11.10.1-all-languages.tar.gz

# mv phpMyAdmin-2.11.10.1 phpmyadmin

#cp -R phpmyadmin /var/www/html/

#mv /var/www/html/phpmyadmin/config.sample.inc.php /var/www/html/phpmyadmin/config.inc.php

#vim /var/www/html/phpmyadmin/config.inc.php

Fix for secret passwordthis line

$cfg['blowfish_secret'] = 'testpassword';

Now you can use phpMyAdmin via web browser

ขั้นตอนที่ 5 การตั้งค่าให้กับ nocat

#vim /usr/local/nocat/authserv/nocat.conf

แก้ไขบรรทัดด้านล่างนี้

• HomePage http://www.yoursite.com

• DataSource DBI

• Database dbi:mysql:database=nocat

• DB_User nocat

• DB_Passwd 123456

#vim /usr/local/nocat/gw/nocat.conf

แก้ไขบรรทัดด้านล่างนี้

• GatewayName yourcompanyname

• GatewayMode Passive

• #GatewayLog /usr/local/nocat/gw/nocat.log (เพื่อระบุว่า ให้เก็บ log การใช้งานไว้ที่ใหน)

• LoginTimeout 86400 (ตัวอย่างกำหนดให้หมดเวลาใน 1 วัน)

• IdleTimeout 86400

• HomePage http://www.yoursite.com

• TrustedGroups Any

• Owners admin@yoursite.com

• AuthServiceAddr serveraddress (200.0.0.1)

• AuthServiceURL https://$AuthServiceAddr/cgi-bin/login

• LogoutURL https://$AuthServiceAddr/logout.html

• ExternalDevice eth0 (or the one you set)

• InternalDevice eth1 (or the one you set)

• LocalNetwork yourlannetwork (example 200.0.0.0/24)

• DNSAddr clarkconnectserveraddress(200.0.0.1 maybe)

• AllowedWebHosts somewebsiteaddress (google.com สามารถระบุเวบที่ต้องการให้เข้าโดยไม่ต้องผ่านการ authentication)
ทำหารตั้งค่าสำหรับระบบ Web service(Apache)

#cp /usr/local/nocat/authserv/httpd.conf /etc/httpd/conf.d/nocat.conf

#vim /etc/httpd/conf/httpd.conf

DocumentRoot "/usr/local/nocat/authserv/htdocs"

เปลี่ยน Directory "/var/www/html" - "/usr/local/nocat/authserv/htdocs"

(comment this line) #ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

A few lines under #ScriptAlias Change to

#vim /etc/httpd/conf.d/ssl.conf

แก้ไขบรรทัดด้านล่างนี้

"/var/www/cgi-bin/" == "/usr/local/nocat/authserv/cgi-bin"

ทำการกำหนดให้เครื่องเป็น foreward ออกภายนอก โดย

#vim /etc/sysctl.conf แก้ net.ipv4.ip_forward = 1

สำหรับการสร้างให้ Nocat เป็นเหมือน Service ทั่วไป

#cd /root

#wget http://trip.ge.infn.it/software/config_file/nocat/nocatgw
#cp /root/nocatgw /etc/init.d/

#chkconfig --add nocatgw;

#/etc/init.d/nocatgw start

*** หากต้องการให้ใช้ กับการเปิดอัตโนมัติให้ใช้ ตัวอย่างไฟล์ Script จากที่นี่ http://trip.ge.infn.it/software/config_file/nocat/nocatgw

ขั้นตอนที่ 6 การเพิ่มผู้ใช้ระบบ

/usr/local/nocat/authserv/bin/admintool -c user01 123456

/usr/local/nocat/authserv/bin/admintool -a user01 member

Link อ้างอิง(ที่ทำให้เกิดเอกสารฉบับนี้)

http://shapeshed.com/journal/setting_up_mod_ssl_on_apache_centos_52/

http://kom.homelinux.org/node/295

http://trip.ge.infn.it/software/config_file/nocat/