แสดงกระทู้

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - golfreeze

Pages: 1 ... 144 145 [146]
2176
#พอดี เครื่องที่ได้ดูแล มีปัญหาเรื่อง perl script น่ะครับ ลักษณะคือมีการรัน perl5.7 อยู่ซึ่งเป็น
user apache สำหรับวิธีการ tracking หาต้นตอ นั้น ขอให้มีสติ ให้นิ่งก่อน แล้วเริ่มใช้วิธีง่ายๆ ดังนี้
ครับ
1.find command

#find / -user apache -name "*.pl"
#find / -user apache -name "*.txt"

ดูเจอไฟล์ไหนแปลกๆ ก็เข้าไปดูครับ

2.จะเข้าไปดูตาม log ของ access กับ error_log ใน apache ครับ
#less /var/log/httpd/access_log
#less /var/log/httpd/error_log

3.เข้าไปใน ไฟล์พวก log ของ ไฟล์ ftp log
#less /var/log/xferlog

4.อีกวิธีที่ผมชอบใช้ คือ ใช้ตัว application มาช่วย คือตัว lsof

ตัวนี้ เก๋าพอสมควร ซึ่งมันจะ หา ip ที่ connection "ESTABLISH" อยู่

และบางทีอาจปรากฏเป็น path ที่รันไฟล์อยู่ด้วย เราก็เข้าไปจัดการได้เลย

#lsof -i -n -P | more
ถ้าเจอ ip ที่เชื่อมต่อก็ block เพื่อตัดปัญหาที่ปลายทางไปก่อนก็ได้ครับ

5.ลองดู crontab ของ user นั้นๆเช่น
#crontab -u apache -l
ถ้าเจอ ก็ตามไปดู ไฟล์นั้น

6.ทำการ ตรวจไวรัสโดยใช้ tools clamscan ช่วย
#clamscan /

ึ7.ถ้าไม่เจอ จริงๆ แล้วล่ะก็ทำการ Killall process นั้นทิ้งซะ เช่น
#killall -9 perl5.7.8


ซึ่งปัญหาที่เกิดขึ้น แอดมินแต่ล่ะคนก็ แก้ปัญหาตามสไตส์ที่ตนเองถนัด สำหรับผมก็จะใช้ประมาณนี้
เลยอยากมาแชร์ให้เพื่อนๆ ได้ทราบ เผื่ออาจจะช่วยท่านได้บ้าง

แต่สุดท้าย ทุกอย่างก็ล้วนไม่มีอะไรสมบูรณ์ มันเป็น อนิจจัง ครับ

golfreeze[at]packetlove.com

2177
#คำศัพท์ เกี่ยวกับ DNS

ความหมาย/หน้าที่
Forward Master Zone
แปลงชื่อ Domain เป็น IP Adress

Reverse Master Zone
แปลง IP Adress เป็นชื่อ Domain

BIND(Berkeley Internet Name Domain)
โปรแกรมให้บริการดีเอ็นเอส

Quote
bind-utils-9.2.4-2
bind-9.2.4-2
bind-libs-9.2.4-2
ypbind-1.17.2-3
bind-chroot-9.2.4-2

Master Name Sever

Slave Name Server Name Server มีสองแบบคือ Master Name Sever และ
Slave Name Server ซึ่งจะต้องอยู่ต่างเครื่องกัน

Master Name Server จะอ่านข้อมูลประจำโซนจากแฟ้มใน Disk และมีสิทธิหน้าที่ในโซนนั้นๆ
Slave Name Server สำเนาข้อมูลจาก Master Name Server

named โปรแกรมบริการชื่อ Domain บน Linux

/usr/sbin/named -u named -t /var/named/chroot
Host
เครื่องคอมพิวเตอร์ศูนย์กลางที่ต่อเข้ากับ Network,Internet เพื่อบริการใดๆ

Domain
ชื่อ web address/computer
ทำให้เข้าใจ/จำง่าย/มีความหมาย กว่า IP Address

ถ้าเรียก โดเมน เหมือนเรียก IP Address

http://www.icann.org/

Sub Domain
ส่วนย่อยของ Domain เช่น mail.dns.linuxstep.com
mail คือ Sub Domain
Localhost = เครื่องเราเอง จะตั้งค่า ip address อะไร แต่เมื่อเรียก
Localhost ก็จะเรียกเครื่องเราเอง

IP Address 127.0.0.1 = Localhost
IP(Internet Protocal)
IP หรือ Internet Protocal
IP Address คือรหัสตัวเลขที่กำหนดขึ้น เพื่อใช้อ้างถึงที่อยู่ของ Host และ Network
ตัวเลขเหล่านี้จะไม่ซ้ำกัน (unique numeric) ซึ่งมีมาตรฐานในการกำหนด และเป็นที่รู้จักทั่วโลก IPV4,IPV6
Port ช่องทาง ที่ใช้ติดต่อกับ computer/อุปกรณ์ ใน network

(Address Localhost)
สำหรับ window กำหนด loopback IP=127.0.0.1 เมื่อส่งสัญญาณออกจะไม่ส่งออกนอกเครือข่าย แต่จะกลับมา
ที่ต้นทาง ด้วย loop back driver

http://www.certiguide.com/netplus/
cg_np_IVLoopbackAddressingandConnections.htm

Root Domain ตอนนี้มีอยู่ 13 ตัวทั่วโลก
ลำดับบนสุดของระบบ DNS โดยมีการกำหนดดังนี้
ลำดับที่ 1 root
ลำดับที่ 2 .com, .net, .edu, .gov, .org, .th, ...
ลำดับที่ 3 subdomain ตัวอย่าง mail3.linuxstep.com
mail3 =subdomain

ตัวอย่างลำดับ DNS
www2.dns.linuxstep.com

Name Resolution

การที่ DNS Server เก็บหมายเลข IP Address คู่กับชื่อเครื่องแบบ Domain Name
เพื่อทำการค้นหาชื่อตามการร้องขอของเครื่อง DNS client
DNS Server
เครื่องที่คอยจัดการ/ดูแล/แก้ไข domain subdomain
Client
เครื่องลูกข่าย
Resolver
กลไกการแปลง domain เป็น ip address
Reverse File
/etc/resolve.conf

การ resolve หมายถึง
DNS Zone
การจัด domain เป็นพื้นที่ย่อย
TCP,UDP,ARP

เป็น protocol ที่ DNS ใช้ในการติดต่อผ่าน port 53

TCP - ปรับปรุงข้อมูล
UDP - ส่งคำขอข้อมูล
ARP - แปลงค่า IP address เป็น Hardware

#Files ที่ใช้ในการ Config
Files Config

ความหมาย / หน้าที่
/etc/named.conf
กำหนดการทำงานของ Name Server สำคัญมาก
/var/named/named.ca เก็บข้อมูลชื่อ Server ซื่งเป็น Root Name Server
ไม่ควรแก้ไขข้อมูลใน file นี้เป็นอันขาด
/var/named/named.local เก็บข้อมูลการ map ชื่อ กับ IP Address แบบ Reverse Lookup
/var/named/dm.com.zone ระบุชื่อ Server,Zone, ทำ Forward Lookup
/var/named/ 203.203.203.203.zone

Reward Lookup
/etc/hosts
เก็บชื่อ host
/etc/resolve.conf
เก็บชื่อ domain และ ip ที่ทำงานแบบ Forward Lookup
/etc/sysconfig/network เก็บชื่อ host ของเครื่อง
/etc/sysconfig/named กำหนดตำแหน่งของ named ที่เป็น file config

#ความหมายของ SOA Resource Record
SOA (Start to authority)
เริ่มให้สิทธิ/อำนาจ

ความหมาย / หน้าที่

Domain Name ที่ได้จาก /etc/named.comf
IN Internet
serial = เป็นหมายเลขที่ใช้แสดงการอัพเดทข้อมูลระหว่าง Primary master และ Secondary master
refresh = ระยะเวลา refresh ข้อมูล
retry = ระยะเวลา ตรวจสอบข้อมูลกับ Primary DNS Server
expire = ระยะเวลา หมดอายุ กรณีติดต่อกับ Primary DNS Server ไม่ได้

#ความหมายข้อมูลใน Fields Type DNS Record
Type

ความหมาย / หน้าที่
A = แปลงชื่อ Domain เป็น IP Address แบบ ipv4
NS = Name Server record กำหนดว่า server ใดรับผิดชอบ domain
PTR = Pointer record ใช้ Map IP Address เป็น Host

MX = Mail Exchanger
ใช้ระบุชื่อเครื่อง Mail Server ของ Domain
เมื่อเราต้องกำหนด MX เราจะพบว่าต้องกำหนด
MX 10 mail1.example.com
MX 20 mail2.newdomain.com

ค่าเลข 10 และ20 นั้นหมายถึง Priority ของ Mail โดยค่าน้อยสุดจะสำคัญสุด

ชื่อหลัง MX ต้องเป็น Domain เท่านั้นและไม่ใช่ CName
CNAME = Cononical name ใช้เป็น Alias name ให้เป็น host จริง
เช่น ns,mail,www,www2
;
Remark


2178
ลง mailgraph + syslog-ng ใน freebsd

#cd /usr/ports/mail/mailgraph
#make install clean

เพิ่มใน /etc/rc.conf ตามนี้
mailgraph_enable="YES"
mailgraph_pidfile="/var/db/mailgraph/mailgraph.pid"
mailgraph_flags=""
logfile /var/log/maillog
"daemon-rrd=/var/db/mailgraph "ignore-localhost "daemon
"daemon-pid=${mailgraph_pidfile}"
mailgraph_user="root"
mailgraph_group="wheel"
สั่งให้ service ทำงาน
/usr/local/etc/rc.d/mailgraph start
ถ้าทำงานแล้วสั่ง
#/usr/local/etc/rc.d/mailgraph status
จะเป็น
mailgraph is running as pid 4406.

SYSLOG ธรรมดา
กรณีให้ส่ง log maillog มาจาก เครื่อง client (smtp0 , smtp1)
ฝั่ง client ที่ต้องการให้ ส่ง log มายังเครื่อง server ก็
ให้เข้าไปแก้ไข ใน
#vi /etc/syslog.conf

ยกตัวอย่างเช่น
ให้ maillog ส่ง log มาที่เครื่อง log server(xxx.yyy.zzz.100) ก็เพียงแค่

# ให้เก็บที่เครื่องตัวเอง กับส่งมาที่ ip xxx.yyy.zzz.100
mail.* -/var/log/maillog
mail.* @xxx.yyy.zzz.100

แล้วจัดการ save
แล้วสั่งให้ syslog ที่เครื่อง client restart 1 ครั้ง

#ตระกูล RH
/etc/init.d/syslog restart

แค่นั้นแล้วไปรอดูที่ cacti_syslog ครับ


แล้วไป config ให้ mailgraph.cgi ให้แสดงรูปให้ถูกที่

แล้วทำการสั่งให้ mailgraph ทำงานโดยเข้าไปเรียก

#/usr/local/sbin/mailgraph.pl --logfile /var/log/customer-maillog/maillog-total
--daemon-pid=/var/db/mailgraph/mailgraph.pid --daemon

ดูว่า service ทำงาน
#/usr/local/etc/rc.d/mailgraph status
จะเป็น
mailgraph is running as pid 4406.
ประมาณนั้น


ส่วนของ syslog-ng ( ฝั่ง server จะเป็น ) นั้น จะอยู่ที่

/usr/local/syslog-ng/syslog-ng.conf

สำหรับ config หลักๆ เป็น

source s_maillog_smtp0 { tcp(ip(116.68.146.13) port(21245)); }; #ควรตรงกับฝั่ง client
destination d_maillog_smtp0 { file("/var/log/customer-maillog/maillog-smtp0"); };
log { source(s_maillog_smtp0); destination(d_maillog_smtp0); }; #สามารถใส่ค่า filter ต่างได้ที่
ในส่วนของ "log" น่ะครับ
ข้อแนะนำ ส่วนของ filter สามารถใช้งานได้ดี เมื่อ log ที่ถูกส่งเข้ามาที่ server มีปริมาณไม่มากเกินไป
จะทำงานได้ ดี
แต่ ถ้ามีปริมาณเข้ามาเร็ว แนะนำ ให้ ส่วนของ client ทำการ ส่งเข้ามาเป็น socket แยก เลย ลองมาดูฝั่ง
client บ้างน่ะครั บ

options {
use_fqdn(no);
sync(0);
};

source s_maillog { unix-stream("/dev/log" max_connections(1000));
pipe("/proc/km
sg"); internal(); };
source s_file { unix-stream("/dev/log"); pipe("/proc/kmsg"); internal();
};

destination d_maillog { file("/var/log/maillog"); };
destination d_backup { tcp("10.20.0.252" port(20245)); }; # socket ควรส่งไปให้ ตรงกับ
ฝั่ง server น่ะครับ
destination d_tools { tcp("116.68.146.13" port(20245)); };# socket ควรส่งไปให้ ตรงกับ
ฝั่ง server น่ะครับ

destination d_tools_1 { tcp("116.68.146.13" port(21245)); };


log { source(s_maillog); destination(d_backup); };
log { source(s_maillog); destination(d_tools); };
log { source(s_maillog); destination(d_tools_1); };
log { source(s_maillog); destination(d_maillog); };

เมื่อ config เสร็จทั้งสองฝั่ง สั่งให้ restart service syslog-ng โดย

#killall syslog-ng
#/usr/local/sbin/syslog-ng

ครับ

ทำการปรับ permission maillog เป็น 644
#chmod 644 /var/log/customer_log/maillog*
แล้วสั่ง รันคำสั่ง ดังนี้
/usr/bin/perl /usr/local/sbin/mailgraph.pl --logfile /var/log/customer-maillog/maillog-smtp0
--daemon-rrd=/var/db/mailgraph/ --ignore-localhost --daemon
--daemon-pid=/var/db/mailgraph/mailgraph2.pid

2179
ต้องการจำกัด user ที่จะเข้าถึงไดเรกทอรี conf



สำหรับ apache ที่ใช้ทดสอบนั้น สามารถสร้างแฟ้มคอนฟิกแยกจาก httpd.conf ได้โดยใส่ในไดเรกทอรี conf.d

ให้สร้างแฟ้ม /etc/httpd/conf.d/my.conf โดยเพิ่มบรรทัดเหล่านี้

<Directory "/var/www/cgi-bin/conf">
Options ExecCGI FollowSymLinks
AllowOverride None
Options None
AuthType Basic
AuthName "Please enter our server's User Account"
AuthUserFile /var/www/users/local_users
Require user user1 user2
Order Allow,Deny
Allow from all
Satisfy all
</Directory>



สร้าง user ดังนี้

ครั้งแรก ใส่ -c เพื่อสร้างไฟล์ ด้วย

htpasswd -c /var/www/users/local_users user1
รอให้ใส่ password ของ user1 ดังนี้

New password:
Re-type new password:
Adding password for user user1
ครั้งต่อไปไม่ต้องใส่ -c

htpasswd /var/www/users/local_users user2



เสร็จแล้วให้ restart httpd ดังนี้

service httpd restart

2180
all application on unix knowledges by golfreeze / set mod rewrite ใน file .htaccess
« on: มกราคม 23, 2011, 12:17:25 AM »
ก่อนอื่น ต้องทำความเข้าใจเกี่ยวกับ mod rewrite ก่อน

แต่เด๋วผมมาอัฟเดท อีกที วันนี้ ง่วงๆ เพลียๆ เขียนตัวแปรผิด ตลอด

เอาเป้นว่า config ดังนี้

เปิดไฟล์ httpd.conf ของ apache มาครับ
ถ้าจะใช้ .htaccess ใน dir ก็ config ใน dir นั้นอย่างเดียวน่ะครับ
เช่นจะใช้ ใน document root ที่เป็น /usr/local/www/apache22/data/xxx

ก็ set แบบนี้
<Directory \"/usr/local/www/apache22/data/xxx\">
Options FollowSymLinks
#AllowOverride None จะเลี้ยงใช้ htaccess ไม่ได้ เปลี่ยนเป็น All ครับ
#AllowOveride None
AllowOverride All
Order allow,deny
Allow from all
</Directory>

แล้วไปเขียนไฟล์ test ดังนี้
#vi /usr/local/www/apache22/data/xxx/.htaccess

RewriteEngine on
RewriteBase /
RewriteRules ^(.*)$ index.php?id=$1

-----------------------------------------------------------
#vi index.php
<?php
session_start();
$id = $_GET=[\"id\"];

echo \"$id\";

if (empty($id)) {
echo \"can not use\"; }
else {
echo \"can use\";
}
echo php_uname(\"n\");

?>

แล้วลองเรียกไฟล์ index.php ดูน่ะครับ ถ้าใช้ได้ จะขึ้นเป็น ชื่อ node + can use


golfreeze[at]packetlove.com

Pages: 1 ... 144 145 [146]