ads

วันอังคารที่ 3 กันยายน พ.ศ. 2556

วันพฤหัสบดีที่ 29 สิงหาคม พ.ศ. 2556

วัดความเร็ว cvsup แต่ละไซต์ของ FreeBSD

วัดความเร็ว cvsup แต่ละไซต์ของ FreeBSD

เคยไหม  เวลาอัพเดท port หรือ อัพเวอร์ชั่น OS FreeBSD
โดยคำสั่งพวก cvsup ports-supfile  หรือ cvsup stable-supfile  แล้วรอไปเป็นชาิติวันนี้เลยหาคำสั่งมาให้
เพื่อวัดว่าเราจะเลือกไซต์ไหนดีโดย  ให้เร็วที่สุด
ทั้งนี้ทั้งนั้น  ขึ้นอยู่กับว่า server คุณนั้นตั้งอยู่ที่ไหน วิ่งเส้นไหน inter เท่าไหร่  เส้นไหนใกล้กว่าดังนั้นค่าที่วัดได้จึงอาจจะไม่เหมือนของผม
จึงต้องเลือกใช้เองครับ

install เลย
# /usr/ports/sysutils/fastest_cvsup

แล้ว make install เลยครับ
# make install
# rehash

รอจนเสร็จแล้วก็มาใช้งานกันดูครับ
# fastest_cvsup -c all

ระบบจะวัดผลการตอบจาก cvsup server FreeBSD ทั่วโลกที่มีแล้วจับเวลามาให้เรา  เร็วที่สุด 3 อันดับครับ
>  Querying servers in countries: ar at au br ca ch cn cr cz de dk ee es fi fr gr hu ie is jp kg kr kw lt lv nl no nz ph pl pt ro ru se sg si sk sm th tld tr tw ua uk us za
==> DNS lookup timed out for cvsup.ar.freebsd.org
--> Connecting to cvsup.at.freebsd.org [137.208.3.18]...
    - server replied: OK 17 0 SNAP_16_1h CVSup server ready
    - time taken: 248.14 ms
--> Connecting to cvsup.au.freebsd.org [202.125.41.163]...

....
..
..
รอครับ  รอๆๆๆ...  แล้วจะสรุปตอนท้ายได้ดังนี้

>>  Speed Daemons:
    - 1st: cvsup.sg.freebsd.org
    - 2nd: cvsup6.jp.freebsd.org
    - 3rd: cvsup3.jp.freebsd.org

แล้วทีนี้เวลา cvsup ports-supfile  หรือ cvsup stable-supfile เราก็เลือกไซต์นี้ลงไปในไฟล์คอนฟิกเรา
ก็จะเร็วปรี๊ดดปร๊าดดั่งใจครับ  แลบลิ้น

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

วันอังคารที่ 27 สิงหาคม พ.ศ. 2556

โปรแกรมเปลียน changing-collation ( tis-620 -->utf8) ใน mysql

 โปรแกรมเปลียน changing-collation ( tis-620 -->utf8) ใน mysql

ท่านเคยสบปัญหานี้ไหม  เ็ซ็ตดาต้าเบสไว้เป็นอย่างหนึ่ง
แต่พอลงโปรแกรมต่าง ๆ ( ที่ไม่มีให้เลือก collation ) พอเปิดมาดูอีกทีิอ้าว ไม่ตรงหว่า
หรือ ท่านที่เช่าโฮส ต่างประเทศอยู่  collation มันเลยไม่เป็น utf-8 ดังใจ
ทำให้โปรแกรมเราทำงานเพี้ยนกับภาษาไทย  ต้องมาปวดหัวกับปัญหาภาษาต่างดาว   ปวดหัวตึ๊บ
ของไทยเองก็ใช่ว่าจะไม่เจอ  บางที่ดีฟอลเป็น TIS-620 เงียะ เราจะใช้ UTF-8 ก็เจอบ่อยไป

วันนี้ขอแนะนำ phoca-changing-collation
ไปอ่านรายละเอียด และดาวโหลดได้จาก http://www.phoca.cz/phoca-changing-collation
เมื่อได้ไฟล์แล้วก็ทำการแตกไฟล์  แล้วอัพขึ้นไปบนพื้นที่เราเลย  แล้วเปลียนชื่อโฟลเดอร์ให้เรียกง่ายๆ เลย เช่น callation
แล้วก็เรียก url ที่เรามีเช่น
www.mysite.com/main/collation

Database Host : ชื่อโฮส หรือไอพีเครื่องดาต้าเบส
Database User : user ของดาต้าเบส   
Database Password : password ของดาต้าเบส   
Database Name   : ชื่อดาต้าเบส
Database Collation : collation ที่ต้องการจะใช้ของไทยควรใช้เป็น utf8_general_ci


กด submit ก็เสร็จเลย
แล้วเราก็จะได้ระบบ UTF-8 ดั่งใจ

วันศุกร์ที่ 16 สิงหาคม พ.ศ. 2556

Rsync Backup ข้ามเครื่อง

Rsync Backup ข้ามเครื่อง

เซิร์ฟเวอร์เป็น FreeBSD  ลง rsync ก่อนกครับ ( 192.168.201.101 )
# cd  /usr/ports/net/rsync
# make install clean
# rehash
แอด user ที่จะใช้ในการซิงค์ที่นี้ใช้  apache
# add apache
# passwd apache

เปลี่ยน user มาเป็น  apache
# su - apache
แล้วทำการ  gent key
# ssh-keygen -t rsa
  Generating public/private rsa key pair.
Enter file in which to save the key (/home/apache/.ssh/id_rsa):    <enter ผ่าน >
Created directory '/home/apache/.ssh'.
Enter passphrase (empty for no passphrase): <enter ผ่าน >
Enter same passphrase again: <enter ผ่าน >

# cd .ssh
ก๊อป key มาใช้
# cp id_rsa.pup local.key

ทำการส่งค่าไฟล์ local.key ไปยังเครื่องแบคอัพ ด้วยการ sftp
# sftp apache@192.168.201.103

# The authenticity of host '192.168.201.103 (192.168.201.103)' can't be established.
DSA key fingerprint is 27:bd:d3:a3:e3:63:ba:01:43:ad:f1:03:2a:07:41:75.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.201.103' (DSA) to the list of known hosts.
apache@192.168.201.103's password:   <ใส่พาสเวิร์ดไป >
sftp> put local.key
Uploading local.key to /home/apache/local.key
local.key                                                                                  100%  412     0.4KB/s   00:00  
sftp> bye


####  ที่เครื่อง  backup ### ( 192.168.201.103 )
อันนี้เป็น CentOS ใช้ yum
# yum install rsync   แล้วก็รอไป
adduser ที่จะใช้ให้เหมือนกัน
# adduser apache
# passwd apache  เปลี่ยนพาสดังที่เราเซ็ต

แล้วเปลียน user
# su - apache

แล้วทำการ ssh ไปยังเครืองอื่นที่ไม่ใช่เครื่องต้นแบบ  เพอให้มันสร้าง ไดเรคโทรี่ .ssh อัตโนมัติ
$ ssh apache@192.168.201.105
apache@192.168.201.105's password:  < ใส่พาสเวิร์ด >
$ exit   เสร็จแล้วออกมา
แล้วทำาการ ก๊อปคีย์ที่ได้เก็บไว้เป็นตัวออเท็น
$ cat local.key >> .ssh/authorized_keys
$ chmod 755 .ssh/authorized_keys

### ตัว server ต้นแบบ ###
กลับมาที่ฝั่ง server ต้นแบบ  ลอง ssh ไปยังตัวแบคอัพ  มันจะไม่ถามพาสเวิร์ด
$ ssh apache@192.168.201.103
[apache@streaming01 ~]$     เรียบร้อยเข้าได้เลย

เมื่อเข้าได้แล้วต่อไปก็ใส่คำสั่ง rsync เทสได้เลยว่าได้หรือเปล่า
# rsync [ออฟชั่น] [ ต้นแบบ] [ตัวแบคอัพ]
ลองเทสเป็น
# rsync -avz ssh /DATA/ apache@192.168.201.103:/home/BACKUP/
= ทำการซิงค์ที่เครื่องต้นแบบภายใต้พาร์ท /DATA  ไปยังเครื่องแบคอัพ ip 192.168.201.103 ในพาร์ท /home/BACKUP/
ลองรันดู   ถ้าทำงานได้จริงก็ผ่านแล้วครับเอาไปใส่ใน crontab เลย  ทำวันละครั้งก็ได้ครับ
# crontab -e
โค๊ด:
0 0 * * * rsync -avz --delete ssh /DATA/ apache@192.168.201.103:/home/BACKUP/

ในการใช้งานจริงจะใส่ --delete เป็นออฟชั่นเพิ่มไปอีกเพื่อให้เวลาซิงค์หากตัวต้นแบบมีการลบไฟล์ไหนไปแล้ว  ปลายทางที่แบคอัพก็ลบตามไปด้วย

อีกอย่างที่ควรระวังคือการใส่พาร์ทระหว่าง /DATA  หรือ /DATA/  ได้ผลต่างกันนะครับระวังให้ดี
ถ้าใส่เป็น  rsync -avz --delete ssh /DATA apache@192.168.201.103:/home/BACKUP/
      = เวลามันซิ้งค์ไปที่ปลายทางมันจะสร้างไดเรคโทรี่ /DATA  ภายใต้ /home/BACKUP/
แต่ถ้าใส่เป็น  rsync -avz --delete ssh /DATA/ apache@192.168.201.103:/home/BACKUP/
   = เวลาซิงค์มันจะเอาโฟลเดอร์ย่อย  ไปไว้ใน /home/BACKUP/ เลย    
ซึ่งหากไม่มีการเปลี่ยนรูปแบบคำสั่งอาจจะไม่มีผลอะไรเท่าไหร่  แต่ถ้าวันไหนเปลียนรูปแบบคำสั่งจาก มี / ไปเป็น ไม่มี /  แล้วเราใส่ออฟชั่น  --delete แล้ว
มันจะมองว่าปลายทางไม่เหมือนเดิมมันก็ลบทิ้งเกลี้ยงเลยแล้วทับด้วย data ใหม่หรือซับย่อยของโฟลเดอร์ใหม่เลย  อันนี้ต้องระวัง

วันอังคารที่ 13 สิงหาคม พ.ศ. 2556

table ใน mysql crashed

table ใน mysql crashed

หลายท่านเจอเหตุการ์แบบนี้แน่ๆ ไม่ว่าจะเกิดจากไฟดับ หรือเครืองค้าง  กดปิดเครื่องโดยไม่ชัตดาวน์
อันเป็นสาเหตุให้ table crashed ไป
ดูในไฟล์ log  xxxxx.err จะฟ้องประมาณ Table './xxxx/xxxx' is marked as crashed and should be repaired

ซ่อมแซมแบบทั่วไปโดยใช้คำสั่ง


# mysqlcheck -o -u root -pพาสเวิร์ด --all-databases --auto-repair

- พาสเวิร์ด แทนด้วย พาสเวิร์ดของ root

แต่ก็ใช่ว่าทุกครั้งจะหายได้  บางทีไม่หายอีกต้องทำวิธีต่อไปโดยใช้ myisam แทนในการซอ่มตารางดังต่อไปนี้
ให้ cd เข้าไปยัง part database ตัวที่มีปัญหา
แล้วใช้คำสั่ง


# myisamchk -r ชื่อเทเบิลที่มีปัญหา.MYI

ดังนี้
# myisamchk -r post_question.MYI
- recovering (with sort) MyISAM-table 'post_question.MYI'
Data records: 199804
- Fixing index 1

จะทำการจัดเรียง index ใหม่ให้เข้ากับขั้อมูลที่แท้จริง
เท่านี้ก็ก็ผ่านแล้วครับ

ปัญหา kern.maxfiles limit exceeded by uid

ปัญหา kern.maxfiles limit exceeded by uid

FreeBSD ครับ อยู่ๆ ก็ ftp ไม่ได้  ssh ไม่ได้
เปิดดูคอนโซลไปก็เจอ message บานเลย


kern.maxfiles limit exceeded by uid 1001, please see tuning(7). 
kern.maxfiles limit exceeded by uid 1001, please see tuning(7). 
kern.maxfiles limit exceeded by uid 65534, please see tuning(7). 
kern.maxfiles limit exceeded by uid 65534, please see tuning(7). 
kern.maxfiles limit exceeded by uid 65534, please see tuning(7). 
kern.maxfiles limit exceeded by uid 22, please see tuning(7). 
kern.maxfiles limit exceeded by uid 22, please see tuning(7). 
....
...
..

วิธีแก้คือ เพิ่ม limit maxfiles ของ kernel ไป

 # sysctl kern.maxfiles=65534

แล้วจะเด้ง message กลับมาว่ารัค่าใหม่เรียบร้อยแล้ว
kern.maxfiles: 12328 -> 65534

เรียบร้อย 

วันจันทร์ที่ 5 สิงหาคม พ.ศ. 2556

เฉลยข้อสอบ iStockPhoto

How to pass iStockphoto Photographer Application Quiz: เฉลยข้อสอบ iStockphoto

How to pass iStockphoto Photographer Application Quiz: เฉลยข้อสอบ iStockphoto
  1. Files downloaded from iStockphoto (including yours once you pass this test) are offered with a royalty-free license, which describes how the image can and cannot be used: True
  2.  iStockphoto images are downloaded under two different kinds of royalty-free licenses: our "standard use" license, which allows for all kinds of commercial, personal, and editorial uses, and our "editorial use only" license. True
  3.  All recognizable faces in images with the standard use license require a model release, including those in crowds: True
  4. Logos are acceptable in wide angle photographs under the standard use license: False

  5. Identifiable design marks, such as the 3 stripes for Adidas or the Nike swoosh, are allowed in images under the standard use license if the name is removed: True

  6. Landmark buildings such as the Sydney Opera House require a property release to be used in images offered with the standard use license: True

  7. A model release is required for a self portrait: True

  8. The photographer can witness their own Model/Property Release:False

  9. A simple snapshot is acceptable; iStock does not require quality in composition: False

  10. It is acceptable to protest a rejection in the iStock forums: True
  11. It is acceptable to copy the composition of another photographer`s work: False
  12. Photographs should be upsampled or interpolated to the maximum XXL size: False
  13. The above example contains: Compression
  14. The above example is: Unacceptable lighting
  15. The above example is: Unacceptable texture detail