Recent twitter entries...

  •  

rpm คำสั่ง install โปรแกรมใน Linux ตระกูล Redhat

0

Posted on : 26-07-2010 | By : admin | In : CentOS, Linux

ปกติถ้าใครใช้ Linux ในตระกูล Redhat คงจะคุ้นเคยกับคำสั่ง rpm

rpm เป็นคำสั่งในการ install โปรแกรมใน Redhat โดยโปรแกรมจะถูกจัดให้อยู่ในรูปของ packet สามารถดูในแผ่น install ของ Linux ได้จะพบ rpm ของ Software อยู่

รูปแบบของคำสั่ง

ดูว่ามีโปรแกรมอะไรลงอยู่บ้าง

rpm -qa

อาจจะใช้คำสั่ง grep ช่วยเพื่อแสดงแต่ที่ต้องการดู เช่น rpm -qa|grep php

การลงโปรแกรมใหม่ให้ใช้คำสั่งต่อไปนี้

rpm -ivh packagename.rpm

การลบโปรแกรมที่มีอยู่ออกใช้คำสั่งต่อไปนี้

rpm -e packagename

หากต้องการ upgrade โปรแกรมใช้คำสั่งต่อไปนี้

rpm -Uvh packagename.rpm

ถ้า package ที่เราจะลงหรือลบนั้นมีโปรแกรมอื่นใช้งานอยู่ เราจะลงไม่ได้จะขึ้นว่า failed dependencies ให้เราเติม option –nodepts ลงไปในคำสั่ง เช่น

rpm -Uvh –nodepts packagename.rpm

จะเป็นการลงโดยไม่สนใจ package อื่น แต่ต้องระวังให้มากเพราะโปรแกรมที่ link กันอยู่อาจจะทำงานไม่ได้

แก้ไข ip address ใน Linux

0

Posted on : 12-07-2010 | By : admin | In : CentOS, Linux

ใช้ได้ในตระกูล Redhat , CentOS นะครับ โดยเข้าไปที่

/etc/sysconfig/network-scripts/

แก้ไขไฟชื่อ ifcfg-eth0 สำหรับ port ethernet 0

โดยคำสั่ง #vi ifcfg-eth0

แก้ไขบรรทัดที่เขียนว่า IPADDR

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:19:B9:E5:68:82
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.12.203
NETMASK=255.255.255.0

สำหรับการแก้ไขค่า default gateway แก้ไขได้ที่ไฟล์

/etc/sysconfig/network

แก้ไขบรรทัดที่เขียนว่า GATEWAY

NETWORKING=yes

HOSTNAME=localhost.localdomain

GATEWAY=192.168.12.1

จากนั้นอย่าลืม restart network service ด้วยคำสั่ง

service network restart

ก็เป็นอันเรียบร้อย

Linux troubleshooting คำสั่งในการแก้ปัญหา Linux

0

Posted on : 04-04-2010 | By : admin | In : CentOS, Linux

เวลา server ของเรามีปัญหา โดยปกติแล้วกว่า 90% จะมาจากปัญหาพื้นฐานต่างๆ เช่น disk เต็ม , ram ไม่พอ , CPU 100%

ผมได้รวบรวมวิธีการค้นหาปัญหาที่เิกิดขึ้นใน Linux sever ( Linux troubleshooting ) ลองทำตามดูรับรองว่ามีประโยชน์มากทีเดียว

1. ใช้คำสั่ง df -h

เพื่อดู disk space ว่าเต็ม 100% หรือเปล่า นี่เป็นสิ่งแรกที่ต้องตรวจสอบ

#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
901G  901G  0G  100% / << นี่แสดงว่ามีปัญหา disk เต็ม
/dev/sdb1             903G   36G  821G   5% /backup
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                         2.0G     0  2.0G   0% /dev/shm
/var/tmpMnt          1008M   35M  922M   4% /tmp
ถ้าพบว่า disk เต็ม สามารถไปที่ / แล้วลองใช้คำสั่ง du –max-depth=1 -h เพื่อดูว่า file ไหนที่ทำให้เต็ม โดยไล่ไปทีละ directpry

2. ใช้คำสั่ง top

เพื่อดู CPU , RAM , swap file และ process ที่ใช้ CPU และ memory สูงที่สุด

top command

3. ใช้คำสั่ง tail -100 /var/log/messages

เพื่อดู log ไฟล์ของระบบว่าเกิดอะไรขึ้นเพื่อดู log ไฟล์ของระบบว่าเกิดอะไรขึ้น 100 คือ 100 บรรทัดสุดท้าย สามารถเปลี่ยนได้ตามต้องการ

4. ดู log ของ process นั้นๆ เช่น log ของ http , mysql

#df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00/dev/sdb1             903G   36G  821G   5% /backup/dev/sda1              99M   12M   83M  13% /boottmpfs                         2.0G     0  2.0G   0% /dev/shm/var/tmpMnt          1008M   35M  922M   4% /tmp

Linux ลืม password root ทำไงดี

0

Posted on : 30-03-2010 | By : admin | In : CentOS, Linux

เชื่อว่าคงจะมีบางครั้งที่หลายๆคนจำเป็นจะต้อง login เข้า server ทั้งๆที่ไม่รู้ password ของ root ( คนเก่าลาออก,admin ไม่อยู่ เป็นต้น ) หรืออาจจะเป็นความสะเพร่าของเราเองที่จำ password ที่ set เอาไว้ไม่ได้ นี่คือสิ่งที่จะต้องทำในกรณีนี้

เตรียมตัว อุปกรณ์ให้พร้อม

เตรียม Keyboard , จอ monitor ต่อเข้ากับ server ที่เราต้องการ login เข้าไป

ขั้นตอน

หลังจากต่อ Keyboard และ monitor แล้วให้ reboot เครื่อง

1. ตอนนี้เข้าหน้า GRUB menu (หน้าที่นับถอยหลัง 5 4 3 2 1 ) ให้กดปุ่มอะไรก็ได้เพื่อให้เลือก GRUฺ menu ได้

2. ที่ menu “Red Hat Enterprise Linux ที่มี kernal version ที่เราต้องการ boot ให้กด a

3. ไปที่สุดบรรทัด กด space bar 1 ทีแล้วพิมพ์ single กด enter เพื่อเข้าสู่ single mode

4. หลังจาก boot เข้าไปเรียบร้อยใช้คำสั่ง #passwd root เพื่อแก้ไข password ใหม่

5. reboot ใหม่อีกครั้งตามปกติ

centos grub

ขั้นตอนการทำ Secure /tmp ป้องกัน hacker

0

Posted on : 13-05-2009 | By : admin | In : CentOS, Linux, Security

1. สร้าง file ขนาด 512 MB สำหรับใช้เป็น /tmp

dd if=/dev/zero of=/var/TMP bs=1024 count=524288

2. สร้างเป็น ext3

mke2fs j /var/TMP

3. Backup /tmp เดิมไว้ก่อน

mv  /tmp /tmp_backup

4. สร้าง ไดเร็กทรอรี่ /tmp

mkdir /tmp

5. ลอง Mount ดู

mount -o loop,noexec,nosuid,rw /var/TMP /tmp

6. กำหนด Permission ของ /tmp

chmod 1777 /tmp

7. Restore /tmp กลับ และลบ Backup ทิ้ง

cp -R /tmp_backup/* /tmp/
rm -rf /tmp_backup

การ Format Harddisk ใหม่ใน Linux

0

Posted on : 07-05-2009 | By : admin | In : CentOS, Linux

การ Format Harddisk ใหม่ใน Linux

[root@server1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.
The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0×0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121601, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601):
Using default value 121601

Command (m for help): p

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@server1 ~]# mkfs -t ext3 /dev/sdb1

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122109952 inodes, 244190000 blocks
12209500 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
7453 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

แก้ไข /etc/fstab เพิ่ม

/dev/sdb1           /backup                 ext3    defaults        1 2