Professional Documents
Culture Documents
CentOS Book
CentOS Book
Partition table
66 Byte
1-1 MBR
3 Primary, Extended Logical
Primary 4
1 Extended Extended Logical 1-2 1-3
IDE IDE
Primary Master
/dev/hda
Primary Slave
/dev/hdb
Secondary Master
/dev/hdc
Secondary Slave
/dev/hdd
/dev/hda1, /dev/hda2 ..., /dev/hdb1,
/dev/hdb2..., /dev/hdc1, /dev/hdc2...
SCSI SCSI ID
SCSI ID 0
/dev/sda
SCSI ID 1
/dev/sdb
SCSI ID 2
/dev/sdc
SCSI ID 3
/dev/sdd
SCSI ID..
/dev/sd...
SCSI
IDE /dev/sda1, /dev/sda2..., /dev/sdb1,
/dev/sdb2..., /dev/sdc1, /dev/sdc2... SATA partition SCSI
CentOS http://linux.sothorn.org
CD DVD
Red Hat CentOS
1. CD / DVD
2. NFS NFS Network file system
CD
3. HTTP
4. FTP FTP
5. Hard Disk
6. Kickstart kickstart
/ (), /boot, swap / swap
mail
/boot
Kernel
/
/home
user
/var/mail
mail
/tmp
swap
RAM
MySQL
/boot
Kernel
/
/var/lib/mysql
MySQL
/backup
/tmp
swap
RAM
CentOS http://linux.sothorn.org
/boot 100 MB
/
3-5 GB
/tmp 256 MB
swap 2 RAM 2 GB Red Hat Enterprise
CentOS RAM 2 GB 2 RAM 2 GB 2 RAM 2
GB swap 4 GB RAM 3 GB swap 5 GB
/tmp /
/
/ () /etc, /lib, /bin, /sbin,
/dev
/tmp, /usr, /usr/local, /home, /var, /opt
/boot
/boot
CentOS http://linux.sothorn.org
3
CentOS 5.2
CentOS NFS FTP WWW
CD DVD DVD
1
CentOS
CentOS CD DVD
CentOS http://linux.sothorn.org
CD DVD OK Skip
CentOS http://linux.sothorn.org
Next
CentOS http://linux.sothorn.org
Yes
CentOS http://linux.sothorn.org
New
CentOS http://linux.sothorn.org
10
CentOS http://linux.sothorn.org
11
CentOS http://linux.sothorn.org
12
swap
CentOS http://linux.sothorn.org
13
/home
14
256 MB
/tmp
CentOS http://linux.sothorn.org
15
/var/lib/mysql Next
CentOS http://linux.sothorn.org
16
GRUB Next
edit IP DHCP
CentOS http://linux.sothorn.org
17
IP Netmask
server1.example.com, mysqlserver.hospitalname.com
CentOS http://linux.sothorn.org
18
Gateway DNS
Continue
Continue
CentOS http://linux.sothorn.org
19
Time Zone
root
CentOS http://linux.sothorn.org
20
Customize now Next
CentOS http://linux.sothorn.org
21
CentOS http://linux.sothorn.org
22
CentOS http://linux.sothorn.org
23
CentOS http://linux.sothorn.org
24
Next
CentOS http://linux.sothorn.org
25
format
CentOS http://linux.sothorn.org
26
Reboot
CentOS http://linux.sothorn.org
27
Disable Firewall
CentOS http://linux.sothorn.org
28
Disable SELinux
CentOS http://linux.sothorn.org
29
Yes
Forward
CentOS http://linux.sothorn.org
30
Continue
CentOS http://linux.sothorn.org
31
4-1
MBR GRUB
IPL MBR Boot Loader GRUB
CentOS http://linux.sothorn.org
32
# 0
titleCentOS(2.6.1892.el5)
root(hd0,0)
kernel/vmlinuz2.6.1892.el5roroot=LABEL=/rhgbquiet
initrd/initrd2.6.1892.el5.img
# 1
titleWindows
rootnoverify(hd0,0)
chainloader+1
33
init
init /sbin/init
/etc/inittab /etc/rc.d/rc.sysinit
/etc/inittab
/etc/inittab Red Hat runlevel
6 runlevel 5 runlevel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
17
19
20
21
#Defaultrunlevel.TherunlevelsusedbyRHSare:
#0halt(DoNOTsetinitdefaulttothis)
#1Singleusermode
#2Multiuser,withoutNFS(Thesameas3,ifyoudonot
have13
networking)
#3Fullmultiusermode
#4unused
#5X11
#6reboot(DoNOTsetinitdefaulttothis)
#
id:3:initdefault:
#Systeminitialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc0
l1:1:wait:/etc/rc.d/rc1
l2:2:wait:/etc/rc.d/rc2
l3:3:wait:/etc/rc.d/rc3
l4:4:wait:/etc/rc.d/rc4
l5:5:wait:/etc/rc.d/rc5
l6:6:wait:/etc/rc.d/rc6
...
3 10 runlevel 3 runlevel
5 X11 3 5 id:5:initdefault:
initdefault /etc/rc.d/rc.sysinit
, , keymaps, swap , ,
3-1
/etc/rc.d/rcX.d/ X initdefault
/etc/rc.d/rcX.d/ start script ( /etc/init.d/) service
start service start service
/etc/rc.d/rc.local start service start script
/etc/init.d Login Text mode getty Graphic mode
xdm, gdm, kdm Login Window Managers
CentOS http://linux.sothorn.org
34
Login
Login Text Mode (runlevel 3)
4-2 Login
Login (runlevel 5)
4-3 Login
CentOS http://linux.sothorn.org
35
Login
text
mode
shutdown -h now
shutdown -r now
reboot
init 6
init 0
poweroff
halt
/boot/grub/menu.lst
/etc/inittab
/etc/rc.d/rc.sysinit
/etc/rc.d/rc.local
CentOS http://linux.sothorn.org
36
5
Service
service 2 stand alone service xinetd control
stand alone service service
stand alone service
1.
2. Service
3. start script /etc/init.d
start service Red Hat Fedora service
service service {start|stop|restart|reload|status} service httpd start
/etc/init.d/ service {start|stop|restart|force-reload} /etc/init.d/httpd start
Red Hat
xinetd control service xinetd
xinetd control service
1. service xinetd
2. service
3. start script /etc/xinit.d
start service Red Hat chkconfig service on chkconfig rsync on
start script
#default:off
#description:Thersyncserverisagoodadditiontoanftp
server,asit\
#allowscrcchecksummingetc.
servicersync
{
disable
=yes
socket_type=stream
wait=no
user=root
server=/usr/bin/rsync
server_args=daemon
log_on_failure+=USERID
}
CentOS http://linux.sothorn.org
37
service
Red Hat service
1. chkconfig
5-1 chkconfig
chkconfig command line
chkconfig --list [ service]
service
chkconfig --add < service>
service
chkconfig --del < service>
service
chkconfig service on | off
- service
[root@server1~]#chkconfiglistmysqld
mysqld
0:off1:off2:on3:on4:on5:on6:off
[root@server1~]#chkconfigmysqldoff
[root@server1~]#chkconfiglistmysqld
mysqld
0:off1:off2:off3:off4:off5:off6:off
[root@server1~]#chkconfiglevel35mysqldon
[root@server1~]#chkconfiglistmysqld
mysqld
0:off1:off2:off3:on4:off5:on6:off
CentOS http://linux.sothorn.org
38
2. ntsysv
5-2 ntsysv
ntsysv Text User Interface service
spacebar * service spacebar
*
3. serviceconf / system-config-service
CentOS http://linux.sothorn.org
39
PATH
[root@server1~]#/etc/init.d/mysqldstop
StoppingMySQL:[OK]
[root@server1~]#/etc/init.d/mysqldstart
StartingMySQL:[OK]
[root@server1~]#/etc/init.d/mysqldstatus
mysqld(pid5855)isrunning...
/etc/init.d
/etc/xinet.d
/etc/init.c/*
/etc/xinet.d/*
service
chkconfig
CentOS http://linux.sothorn.org
40
6-1
6-2
CentOS http://linux.sothorn.org
41
6-3
cd
/
/ Drive C:\
user root /root root
/ () /root ( root)
/boot, /etc, /initrd, /misc, /opt, /root, /sys, /usr, /bin, /dev, /home,
/lib, /media, /mnt, /proc, /sbin, /tmp, /var
cd / /
cd /boot, cd /etc , cd /usr, cd /mnt
/ /var /var/lib/mysql cd lib/mysql
/
/
CentOS http://linux.sothorn.org
42
cd
/root /var/lib/mysql cd /var/lib/mysql
/var/lib/mysql /var/www cd /var/www
/ /var/lib/mysql cd var/lib/mysql
`
/ /etc cd etc
/root /etc/httpd/ cd /etc/httpd
/var/www/html cd /var/www/html
pwd
5-4
6-4 pwd
pwd
cd
pwd
CentOS http://linux.sothorn.org
43
7
Vi
Text Editor
Text Text Editor pico, nano, mc, Vi Vi
Text Editor Unix Vi ( "vee-eye")
Visual editor
7-1 Vi
vi
Vi vi
# vi /etc/samba/smb.conf
# vi newfilename.txt
vi Mode
vi 2
command mode
insert mode
insert mode
vi command mode
insert mode i () insert mode
vi command mode Esc
CentOS http://linux.sothorn.org
44
insert mode
a
o
O
(command mode)
insert mode command mode Esc
ZZ
:q!
:wq
1
h
1
j
1
k
1
l
1
w
^F
^B 1
^D
^U
^R ^L
CentOS http://linux.sothorn.org
45
dd
dw
de
db
d^
d$
space
ym buffer (m=)
yy
buffer
p
buffer
u
undo
.
redo
/Test
/This is test
/^Test Test
/Test$ Test
/^$
Test
This is test
Test
Test
CentOS http://linux.sothorn.org
46
8
RPM YUM
C source code
3 ./configure, make, make install
Debain ubuntu apt-get, Red Hat rpm (RPM Package Manager)
rpm
RPM
name
version
release
architecture
noarch
Package
mysql-server-5.0.45-7.el5.i386.rpm
package mysql-server
version
5.0.45-7
release
el5
architecture i386
setup-2.5.58-1.el5.noarch.rpm
noarch CPU
package ()
nstall: rpm -i
Upgrade: rpm -U
Freshen: rpm -F
/
Erase: rpm -e
CentOS http://linux.sothorn.org
47
rpm Query
rpm -q what_package what_information
-q query
-f
-p .rpm
-i
-l
rpm query
rpm -qa Package
CentOS http://linux.sothorn.org
48
Package
CentOS http://linux.sothorn.org
49
CentOS http://linux.sothorn.org
50
YUM
Yellow dog Updater, Modified (YUM)
( / / ) RPM GNU General Public License
Seth Vidal yum
Pup, Pirut ,Yumex, Yum Extender KYum Seth Vidal Red Hat
yum Red Hat
Yum Yellowdog Updater (YUP) Yellow Dog Linux Red Hat
YUM
Yum :
(multiple repositories)
depency
CentOS http://linux.sothorn.org
51
yum
yum info
CentOS http://linux.sothorn.org
52
yum deplist
CentOS http://linux.sothorn.org
53
yum install
CentOS http://linux.sothorn.org
54
yum remove
CentOS http://linux.sothorn.org
55
yum update
yum update
# yum update xterm
CentOS http://linux.sothorn.org
56
yum DVD
yum rpm A
B C yum rpm
yum yum
yum DVD
1) /etc/yum.repos.d/
2) CentOS-Base.repo #
3) CentOS-Media.repo DVD
baseurl=file:///media/CentOS_5.2_Final/
4) enabled=0 enabled=1
yum DVD
rpm
yum
:
http://www.thaiadmin.org/board/index.php?topic=41613.0
http://en.wikipedia.org/wiki/Yellow_dog_Updater,_Modified
CentOS http://linux.sothorn.org
57
9
User / Group Accounts
(multi user)
Red Hat user
useradd user option -g 1 user
Private Group User groupadd, groupdel, useradd, userdel, usermod
Private Group groupadd
groupadd
groupadd option group
-g
gid (group id)
groupdel manager
useradd
useradd option user
-d
-g
group
-m
-c
user
-u
user id
CentOS http://linux.sothorn.org
58
user
useradd -g manager -c Mr. Somchai somchai
# somchai manager Mr. Somchai
useradd -g web -c Miss Manee manee
# manee web Miss Manee
useradd -g web -c Mr. Piti piti
# piti web Mr. Piti
useradd -g hr -c Miss Chuchai chuchai
# chuchai hr Miss Chuchai
useradd -g sale -c Mr. Mana mana
# mana sale Mr. Mana
passwd somchai
passwd manee
passwd piti
passwd chuchai
passwd mana
userdel
userdel option user
-r
user /var/spool/mail
usermod
usermod option user
-c
comment user
-d
user
-e
user
-g
user
-G group1 [ ,group2,... , [groupN]
user user
-u uid uid user
-L
user
-U
CentOS http://linux.sothorn.org
59
[root@server1~]#useraddgmanagerc"Mr.Somchai"somchai
[root@server1~]#useraddgwebc"MissManee"manee
[root@server1~]#useraddgwebc"Mr.Piti"piti
[root@server1~]#useraddghrc"MissChuchai"chuchai
[root@server1~]#useraddgsalec"Mr.Mana"mana
[root@server1~]#idpiti
uid=502(piti)gid=501(web)groups=501(web)
[root@server1~]#fingerpiti
Login:pitiName:Mr.Piti
Directory:/home/pitiShell:/bin/bash
Neverloggedin.
Nomail.
NoPlan.
[root@server1~]#usermodghrcPitipiti
[root@server1~]#idpiti
uid=502(piti)gid=502(hr)groups=502(hr)
[root@server1~]#fingerpiti
Login:pitiName:Piti
Directory:/home/pitiShell:/bin/bash
Neverloggedin.
Nomail.
NoPlan.
[root@server1~]#
[root@server1~]#passwdsomchai
Changingpasswordforusersomchai.
NewUNIXpassword:
RetypenewUNIXpassword:
passwd:allauthenticationtokensupdatedsuccessfully.
[root@server1~]#usermodghrcPitiYindeepiti
[root@server1~]#usermodLpiti
[root@server1~]#
groupadd
groupmod
groupdel
useradd
usermod
userdel
passwd
id
finger
CentOS http://linux.sothorn.org
60
10
Permission
3
1.
2.
3.
ls -l
drwxrxrx
drwxrxrx
rwrr
3
8
1
root root40962006070307:20Desktop
root root40962006070108:33MyDownload
root root45292006070317:09test.php
3
r Read
w Write
x Execute
read
writer
execute
execute ()
--- : ( 0)
--x : ( 1)
r-- : ( 4)
rw- : ( 6)
r-x : ( 5)
rwx : ( 7)
CentOS http://linux.sothorn.org
61
10-1
rwxrwxrwx 9 ( 10 )
- d l ( shortcut)
3
3
3
-rwx------ : ( 700)
-rwxrwx--- : ( 770)
-rw-rw-rw- : ( 666)
-rwxr-xr-x : ( 755)
-r--r--r-- : ( 444)
chmod
chown
chgrp
CentOS http://linux.sothorn.org
62
chmod
root@server1~#touchtest.html
root@server1~#lsltest.html
rwrr1rootroot02006071211:03test.html
root@server1~#chmod755test.php
root@server1~#lsltest.html
rwxrxrx1rootroot02006071211:03test.html
root@server1~#chmod666test.html
root@server1~#lsltest.html
rwrwrw1rootroot02006071211:03test.html
root@server1~#lsltest.html
rwrwrw1rootroot02006071211:03test.html
root@server1~#chmod700test.html
root@server1~#lsltest.html
rwx1rootroot02006071211:03test.html
root@server1~#
execute
root@server1/usr/local/firefox#chmod660firefox
root@server1/usr/local/firefox#./firefox
bash:./firefox:Permissiondenied
root@server1/usr/local/firefox#chmod755firefox
root@server1/usr/local/firefox#./firefox
CentOS http://linux.sothorn.org
63
chown chgrp
root@server1~#lsltest.sql
rwxrxrx1rootroot02006071211:03test.sql
root@server1~#chgrpmysqltest.sql
root@server1~#lsltest.sql
rwxrxrx1rootmysql02006071211:03test.sql
root@server1~#chownmysqltest.sql
root@server1~#lsltest.sql
rwxrxrx1mysqlmysql02006071211:03test.sql
root@server1~#
root@server1~#lsltest.sql
rwxrxrx1rootroot02006071211:03test.sql
root@server1~#chownmysqltest.sql
root@server1~#lsltest.sql
rwxrxrx1mysqlroot02006071211:03test.sql
root@server1~#chownroottest.sql
root@server1~#lsltest.sql
rwxrxrx1rootroot02006071211:03test.sql
root@server1~#chownmysql.mysqltest.sql
root@server1~#lsltest.sql
rwxrxrx1mysqlmysql02006071211:03test.sql
chmod
chgrp
chown
CentOS http://linux.sothorn.org
64
11
System Config
Red Hat config IP
system- Tab
[root@server1~]#systemcon
systemconfigauthenticationsystemconfignfs
systemconfigdatesystemconfigpackages
systemconfigdisplaysystemconfigrootpassword
systemconfighttpdsystemconfigsamba
systemconfigkdumpsystemconfigsecuritylevel
systemconfigkeyboardsystemconfigsecurityleveltui
systemconfiglanguagesystemconfigservices
systemconfiglvmsystemconfigsoundcard
systemconfignetworksystemconfigtime
systemconfignetworkcmdsystemconfigusers
systemconfignetworkguisystemcontrolnetwork
systemconfignetworktui
Graphic Mode
65
system-config
Package Server Configuration Tools Administration Tools
system-config
CentOS http://linux.sothorn.org
66
system-config-network / neat IP
11-4 system-config-network
system-config-securitylevel
11-5 system-config-securitylevel
CentOS http://linux.sothorn.org
67
11-6 setup
CentOS http://linux.sothorn.org
68
Network TCP/IP
IP
Text Mode
IP Address
Network Red Hat /etc/sysconfig/network-scripts/
[root@server1~]#cd/etc/sysconfig/networkscripts/
[root@server1networkscripts]#ls
ifcfgeth0ifdownisdnifupaliasesifupplipifupwireless
ifcfgloifdownpostifupbnepifupplusbinit.ipv6global
ifdownifdownpppifupethifuppostnet.hotplug
ifdownbnepifdownroutesifupipppifuppppnetworkfunctions
ifdownethifdownsitifupipsecifuproutesnetworkfunctionsipv6
ifdownipppifdownslifupipv6ifupsit
ifdownipsecifdowntunnelifupipxifupsl
ifdownipv6ifupifupisdnifuptunnel
ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
BROADCAST=192.168.2.255
HWADDR=08:00:27:5A:99:F4
IPADDR=192.168.2.111
NETMASK=255.255.255.0
NETWORK=192.168.2.0
ONBOOT=yes
GATEWAY=192.168.2.254
TYPE=Ethernet
IP IPADDR
service network restart /etc/init.d/network restart IP
Name
Name /etc/resolv.conf
nameserver 203.155.33.1
IP ISP
CentOS http://linux.sothorn.org
69
neat
setup
system-config-securitylevel
system-config-network
system-config-packages
system-config-*
CentOS http://linux.sothorn.org
70
12
mount system
mount
mount point mount
mount point
/mnt /mnt/floppy , /mnt/cdrom, mount point
/media /media/cdrom, /media/hda1
mount
/dev/cdrom CD/DVD Drive
/dev/fd0
Flopy Disk
/dev/hda1
Primary Master IDE 1
/dev/sda1
SCSI 1
/dev/sda
Thumb drive USB /dev/sda
/dev/hdb mount /dev/sda
mount /dev/sda1
mount
mount options device | dir mount options device dir
71
umount CD-ROM
CD USB
umount
umount option dir | device
umount
umount /mnt/fd0
umount /mnt/cdrom
umount /mnt/thumb
mount
umount
CentOS http://linux.sothorn.org
72
13
Backup
[root@server1~]#tarxvfzmydb_backup.tar.gz
var/lib/mysql/mydb/
var/lib/mysql/mydb/db.opt
[root@server1~]#
zip
winzip
winrar zip
-r zip
[root@server1~]#ziprmydb_backup.zip/var/lib/mysql/mydb/
adding:var/lib/mysql/mydb/(stored0%)
adding:var/lib/mysql/mydb/db.opt(deflated18%)
[root@server1~]#lsl
rwrr1rootroot178743Mar2316:18mydb_backup.zip
CentOS http://linux.sothorn.org
73
unzip
[root@server1~]#unzipmydb_backup.zip
Archive:mydb_backup.zip
creating:var/lib/mysql/mydb/
inflating:var/lib/mysql/mydb/db.opt
tar
zip
unzip
CentOS http://linux.sothorn.org
74
14
df
df -h
K, M, G
[root@server1~]#dfh
FilesystemSizeUsedAvailUse%Mountedon
/dev/hda28.6G2.8G5.4G34%/
/dev/hda758G180M55G1%/var/lb/mysql
/dev/hda6251M11M228M5%/tmp
/dev/hda59.5G151M8.9G2%/home
/dev/hda199M13M81M14%/boot
tmpfs149M0149M0%/dev/shm
ps
ps (Process) ps
-e
-f
[root@server1~]#psef
UIDPIDPPIDCSTIMETTYTIMECMD
root10013:38?00:00:00init[5]
root21013:38?00:00:00[migration/0]
root31013:38?00:00:00[ksoftirqd/0]
root41013:38?00:00:00[watchdog/0]
...
| grep
CentOS http://linux.sothorn.org
75
[root@server1~]#psef|grepmysql
root42451013:39?00:00:00/bin/sh
/usr/bin/mysqld_safedatadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklogerror=/var/log/mysqld.log
pidfile=/var/run/mysqld/mysqld.pid
mysql43054245013:39?00:00:00
/usr/libexec/mysqldbasedir=/usrdatadir=/var/lib/mysql
user=mysqlpidfile=/var/run/mysqld/mysqld.pidskip
externallockingsocket=/var/lib/mysql/mysql.sock
root63806301019:02pts/100:00:00grepmysql
[root@server1~]#
kill
kill
(PID)
[root@server1 ~]# kill 4245
top
real time refresh top -d 1
refresh 1
14-1 top
CentOS http://linux.sothorn.org
76
df
ps
kill
top
CentOS http://linux.sothorn.org
77
15
crontab
crontab ,
, , , 1 crontab
service crontab
crontab Text Editor
Red Hat Vi Debian Ubuntu nano
crontab
crontab [-u user] file
crontab [-u user] { -e | -l | -r }
-e crontab user
-l crontab user
-r crontab user
crontab user Login user
-u crontab user Login
crontab Text Editor
*****
*/30 * * * *
* 20 * * *
50***
00**0
*/10 8-17 * * *
0-59
0-23 0=
1-31
1-12
0-6 0=
30
20.00-20.59 .
00.05 .
10 08.00-17.00 .
CentOS http://linux.sothorn.org
78
00***
00**0
/sbin/shutdow -r now
/path/to/your/script/script.sh
shell script
shutdown -r now script.sh shell script
CentOS http://linux.sothorn.org
79
16
Format Drive Drive
fdisk
fdisk
fdisk [-u] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
fdisk -l [-u] [device ...]
fdisk -s partition ...
fdisk -v
[root@fdisk~]#fdiskl
Disk/dev/hda:40.0GB,40020664320bytes
255heads,63sectors/track,4865cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/hda1*11310439183Linux
/dev/hda214128810241437+83Linux
/dev/hda312891353522112+82Linuxswap
[root@fdisk~]#
CentOS http://linux.sothorn.org
80
[root@fdisk~]#fdisk/dev/hda
Thenumberofcylindersforthisdiskissetto4865.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)
Command(mforhelp):m
Commandaction
atoggleabootableflag
beditbsddisklabel
ctogglethedoscompatibilityflag
ddeleteapartition
llistknownpartitiontypes
mprintthismenu
naddanewpartition
ocreateanewemptyDOSpartitiontable
pprintthepartitiontable
qquitwithoutsavingchanges
screateanewemptySundisklabel
tchangeapartition'ssystemid
uchangedisplay/entryunits
vverifythepartitiontable
wwritetabletodiskandexit
xextrafunctionality(expertsonly)
Command(mforhelp):
Command(mforhelp):n
Commandaction
eextended
pprimarypartition(14)
e
Selectedpartition4
Firstcylinder(13544865,default1354):
Usingdefaultvalue1354
Lastcylinderor+sizeor+sizeMor+sizeK(13544865,default
4865):
Usingdefaultvalue4865
n 3 Primary
Primary
Extended e 3 4 First
cylinder Enter 1354 default
CentOS http://linux.sothorn.org
81
82
CentOS http://linux.sothorn.org
83
WARNING:Rereadingthepartitiontablefailedwitherror16:
Deviceorresourcebusy.
Thekernelstillusestheoldtable.
Thenewtablewillbeusedatthenextreboot.
Syncingdisks.
root@fdisk~]#mke2fsj/dev/hda5
mke2fs1.35(28Feb2004)
max_blocks2502533120,rsv_groups=76372,rsv_gdb=596
Filesystemlabel=
OStype:Linux
Blocksize=4096(log=2)
Fragmentsize=4096(log=2)
1224000inodes,2443880blocks
122194blocks(5.00%)reservedforthesuperuser
Firstdatablock=0
Maximumfilesystemblocks=2503999488
75blockgroups
32768blockspergroup,32768fragmentspergroup
16320inodespergroup
Superblockbackupsstoredonblocks:
32768,98304,163840,229376,294912,819200,884736,1605632
Writinginodetables:done
inode.i_blocks=42920,i_size=4243456
Creatingjournal(8192blocks):done
Writingsuperblocksandfilesystemaccountinginformation:done
Thisfilesystemwillbeautomaticallycheckedevery23mountsor
180days,whichevercomesfirst.Usetune2fscoritooverride.
[root@fdisk~]#
mount mount
[root@fdisk~]#mkdir/backup
[root@fdisk~]#mount/dev/hda5/backup
[root@fdisk~]#dfh
FilesystemSizeUsedAvailUse%Mountedon
/dev/hda29.7G1.7G7.5G18%/
/dev/hda199M8.3M86M9%/boot
none125M0125M0%/dev/shm
/dev/hda59.2G54M8.7G1%/backup
[root@fdisk~]#
CentOS http://linux.sothorn.org
84
(Label) partition
e2label device [ new-label ]
label
[root@fdisk~]#e2label/dev/hda5
[root@fdisk~]#e2label/dev/hda5/backup
[root@fdisk~]#e2label/dev/hda5
/backup
[root@fdisk~]#
1 device
mount /dev/hda5, /dev/hdb1
LABEL=/backup
2 mount point
mount point
/mnt/cdrom, /mnt/usb, /mnt/
3 filesystem type
3 filesystem partition filesystem support
ext2 ext3 ext3
ReiserFS ext3 ext2 ext3
journal ext2 check
filesystem ext3 journal
reiserfs journaling ext3 ext3
swap filesystem swap partition
CentOS http://linux.sothorn.org
85
CentOS http://linux.sothorn.org
86
5 dump option
dump 5 /etc/fstab dump option
dump dump option = 0
dump 1= , 2=every other day, 0= dump
6 fsck option
fsck fsck order fsck 0=,
1=, 2-9
/etc/fstab
LABEL=/backup
/backup
ext3 defaults
/backup
ext3 defaults
/dev/hda5
CentOS http://linux.sothorn.org
87
17
Disk Quota
(multi user)
kernel
2 user quota group quota
( quota )
block ( ) inode ()
LABEL=/home
/home
ext3 defaults
12
/home
ext3 defaults,usrquota,grpquota
12
2. /home
mount -o remount /home
3.
aquota.user aquota.group
quotacheck -cm /home
touch /home/aquota.user
touch /home/aquota.group
chmod 600 /home/aquota.user
chmod 600 /home/aquota.group
4. quotaon / quotaoff
-a
/home
quotaon /home
CentOS http://linux.sothorn.org
88
5. edquota
# edquota sothorn
Disk quotas for user sothorn (uid 501):
Filesystem blocks
soft
hard inodes soft
/dev/hda3
32
4096
5120 9 0
hard
0
blocks
inode
soft
soft limit
hard limit
hard
groupquota edquota -g group edquota -g users
block
[sothorn@server1~]$ddif=/dev/zeroof=newfilebs=1Mcount=3
3+0recordsin
3+0recordsout
[sothorn@server1~]$ddif=/dev/zeroof=newfilebs=1Mcount=4
hda3:warning,userblockquotaexceeded.
4+0recordsin
4+0recordsout
[sothorn@server1~]$ddif=/dev/zeroof=newfilebs=1Mcount=5
hda3:warning,userblockquotaexceeded.
hda3:writefailed,userblocklimitreached.
dd:writing`newfile':Diskquotaexceeded
5+0recordsin
4+0recordsout
[sothorn@server1~]$
inode
Diskquotasforusersothorn(uid501):
Filesystem
blocks
soft hard inodes
/dev/hda3
32
0
0
9
soft hard
40
50
CentOS http://linux.sothorn.org
89
[sothorn@server1~]$foriin$(seq150);doechon"file${i}";touch
file${i}2>&1;done|less
cannottouch`file42':Diskquotaexceeded
file43touch:cannottouch`file43':Diskquotaexceeded
file44touch:cannottouch`file44':Diskquotaexceeded
file45touch:cannottouch`file45':Diskquotaexceeded
file46touch:cannottouch`file46':Diskquotaexceeded
file47touch:cannottouch`file47':Diskquotaexceeded
file48touch:cannottouch`file48':Diskquotaexceeded
file49touch:cannottouch`file49':Diskquotaexceeded
file50touch:cannottouch`file50':Diskquotaexceeded
50
[sothorn@server1~]$ls
file1file12file15file18file20file23file26file29file31
file34file37file4file5file8
file10file13file16file19file21file24file27file3file32
file35file38file40file6file9
file11file14file17file2file22file25file28file30file33
file36file39file41file7
[sothorn@server1~]$quota
Diskquotasforusersothorn(uid501):
Filesystemblocksquotalimitgracefilesquotalimit
grace
/dev/hda3360050*4050
[sothorn@server~]$
41 ( 9 ) 50
user set
user user
# edquota -p user1 user2 user3 user1 user2 user3
Grace Period soft limit hard limit soft
limit hard limit grace period grace period
7 grace period months, weeks, days, hours, minutes seconds
grace period edquota -t
CentOS http://linux.sothorn.org
90
18
DNS (Domain Name System)
IP (IP Address)
IP 61.19.246.165
sothorn.org DNS Server
DNS Server IP IP
DNS Server
DNS Server DNS Server
.
univercity.ac.th .th
91
BIND chroot
Bind chroot BIND
BIND CentOS
/var/named/chroot/etc/named.conf
/var/named/chroot/var/named
/etc/named.conf
CentOS http://linux.sothorn.org
92
1.
2. /etc/name.conf
3. IP Address /var/named/chroot/var/named
4. IP Address /var/named/chroot/var/named
5. start restart service named
6. /etc/resolv.conf network
7.
Server
example.intranet Name Server IP 192.168.2.111
http://www.example.intranet
http://webmail.example.intranet
phpMyAdmin
http://phpmyadmin.example.com
IP 192.168.2.101
client01.example.com
IP 192.168.2.102
client02.example.com
/var/named/chroot/etc/named.conf
CentOS 5.2 named.conf
zone"example.intranet"{
typemaster;
file"/var/named/chroot/var/named/example.intranet.zone";
};
zone"2.168.192.inaddr.arpa"{
typemaster;
file"/var/named/chroot/var/named/192.168.2.zone";
};
/etc/named.conf
/etc/named.conf
named-checkconf /etc/named.conf
CentOS http://linux.sothorn.org
93
[root@server1~]#namedcheckconf/var/named/chroot/etc/named.conf
/var/named/chroot/etc/named.conf:11:'mastor'unexpected
[root@server1~]#namedcheckconf/var/named/chroot/etc/named.conf
[root@server1~]#
IP Address
example.intranet.zone IP Address
/var/named/chroot/var/named
$TTL 86400
@INSOAexaple.intranet.root.example.intranet.(
1997022700;Serial
28800;Refresh
14400;Retry
3600000;Expire
86400);Minimum
@
INNSns1
INMX10mail
INA192.168.2.111
INA192.168.2.111
INA192.168.2.111
INA192.168.2.111
INA192.168.2.111
INA
192.168.2.101
INA192.168.2.102
ns1
webmail
www
phpmyadmin
client01
client02
IP Address (192.168.2.zone)
192.168.2.zone IP Address
/var/named/chroot/var/named
$TTL 86400
@INSOAexaple.intranet.root.example.intranet.(
1997022700;Serial
28800;Refresh
14400;Retry
3600000;Expire
86400);Minimum
NSns1.example.intranet.
111
111
111
111
101
102
PTR
PTR
PTR
PTR
PTR
PTR
ns1.example.intranet.
www.example.intranet.
webmail.example.intranet.
phpmyadmin.example.intranet.
client01.example.intranet.
client02.example.intranet.
CentOS http://linux.sothorn.org
94
named
named /etc/init.d/named restart service named restart
DNS Client
DNS Client
DNS Client /etc/resolv.conf nameserver 192.168.2.111
[root@server1 ~]# /etc/init.d/network restart
dig,
nslookup host
[root@server1~]#digexample.intranet
;<<>>DiG9.3.4P1<<>>example.intranet
;;globaloptions:printcmd
;;Gotanswer:
;;>>HEADER<<opcode:QUERY,status:NOERROR,id:61465
;;flags:qraardra;QUERY:1,ANSWER:1,AUTHORITY:1,ADDITIONAL:1
;;QUESTIONSECTION:
;example.intranet.
;;ANSWERSECTION:
example.intranet.
IN
86400 IN
A
A
192.168.2.111
;;AUTHORITYSECTION:
example.intranet.
86400 IN
NS
ns1.example.intranet.
;;ADDITIONALSECTION:
ns1.example.intranet. 86400 IN
192.168.2.111
;;Querytime:4msec
;;SERVER:192.168.2.111#53(192.168.2.111)
;;WHEN:WedMar2503:59:272009
;;MSGSIZErcvd:84
CentOS http://linux.sothorn.org
95
[root@server1~]#digwebmail.example.intranet
;<<>>DiG9.3.4P1<<>>webmail.example.intranet
;;globaloptions:printcmd
;;Gotanswer:
;;>>HEADER<<opcode:QUERY,status:NOERROR,id:47455
;;flags:qraardra;QUERY:1,ANSWER:1,AUTHORITY:1,ADDITIONAL:1
;;QUESTIONSECTION:
;webmail.example.intranet. IN
;;ANSWERSECTION:
webmail.example.intranet.86400 IN
;;AUTHORITYSECTION:
example.intranet.
86400 IN
NS
ns1.example.intranet.
;;ADDITIONALSECTION:
ns1.example.intranet. 86400 IN
192.168.2.111
192.168.2.111
;;Querytime:4msec
;;SERVER:192.168.2.111#53(192.168.2.111)
;;WHEN:WedMar2504:00:442009
;;MSGSIZErcvd:92
host
[root@server1named]#hostclient01.example.intranet
client01.example.intranethasaddress192.168.2.101
[root@server1named]#hostclient02.example.intranet
client02.example.intranethasaddress192.168.2.102
[root@server1named]#hostclient03.example.intranet
Hostclient03.example.intranetnotfound:3(NXDOMAIN)
CentOS http://linux.sothorn.org
96
TTL
@
IN
Serial
Refresh
Retry
Expire
SOA
NS
A
CNAME
MX
PTR
(Time to Live)
example.intranet /etc/named.conf
Primary Master Secondary Master
Primary Master Secondary Master DNS
Primary Secondary
Primary
(refresh) Primary
Start of authority
Name Server record SOA
Address record IP Address
Canonical name (Alias name)
Mail server exchange
Pointer Record IP Address
CentOS http://linux.sothorn.org
97
19
Apache Virtual Host
17 Virtual Host webmail.example.intranet
phpmyadmin.example.intranet Apache
Apache /etc/httpd/conf/httpd.conf Virtual Host 2
( IP ) IP (1 IP 1 IP 1 )
Virtual Host ( IP )
1) /etc/httpd/conf/httpd.conf
NameVirtualHost192.168.2.111:80
<VirtualHost192.168.2.111:80>
ServerAdminwebmaster@example@example.intranet
DocumentRoot/var/www/html/
ServerNameexample.intranet
ErrorLoglogs/www.example.intraneterror_log
CustomLoglogs/www.example.intranetaccess_logcommon
</VirtualHost>
<VirtualHost192.168.2.111:80>
ServerAdminwebmaster@example.intranet
DocumentRoot/var/www/html/phpMyAdmin
ServerNamephpMyadmin.example.intranet
ErrorLoglogs/phpmyadmin.example.intraneterror_log
CustomLoglogs/dummyhost.example.intranetaccess_logcommon
</VirtualHost>
<VirtualHost192.168.2.111:80>
ServerAdminwebmaster@example.intranet
DocumentRoot/var/www/html/webmail
ServerNamewebmail.example.intranet
ErrorLoglogs/webmail.example.intraneterror_log
CustomLoglogs/webmail.example.intranetaccess_logcommon
</VirtualHost>
2) httpd.conf index.html
[root@server1~]#cd/var/www/html/
[root@server1html]#mkdirwebmail
[root@server1html]#mkdirphpMyAdmin
[root@server1webmail]#echo"Welcometomywebmail.">index.html
[root@server1webmail]#cd../phpMyAdmin
[root@server1webmail]#cd../phpMyAdmin/
[root@server1phpMyAdmin]#echo"ThisismyphpMyAdmin.">index.html
[root@server1phpMyAdmin]#
CentOS http://linux.sothorn.org
98
3) service
[root@server1~]#/etc/init.d/httpdrestart
[root@server1~]#servicehttpdrestart
[root@server1~]#/etc/init.d/httpdrestart
Stoppinghttpd:[OK]
Startinghttpd:[OK]
[root@server1~]#
19-1 http://www.example.intranet
http://webmail.example.intranet
19-2 http://webmail.example.intranet
CentOS http://linux.sothorn.org
99
http://phpmyadmin.example.intranet
19-3 http://phpmyadmin.example.intranet
Virtual Host IP (1 IP 1 IP 1 )
1) IP Address /etc/sysconfig/network-scripts /
ifcfg-eth0 ifcfg-eth0 :1 IP 192.168.2.112 1 IP
TYPE=Ethernet
DEVICE=eth0:1
BOOTPROTO=none
NETMASK=255.255.25520
IPADDR=192.168.2.112
USERCTL=no
IPV6INIT=no
PEERDNS=yes
CentOS http://linux.sothorn.org
100
system-config-network Ethernet
19-4 Ethernet
2) /etc/init.d/network restart service network restart
ifconfig
[root@server1~]#ifconfig
eth0Linkencap:EthernetHWaddr08:00:27:5A:99:F4
inetaddr:192.168.2.111Bcast:192.168.2.255Mask:255.255.255.0
inet6addr:fe80::a00:27ff:fe5a:99f4/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:7568errors:0dropped:0overruns:0frame:0
TXpackets:7506errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:3250897(3.1MiB)TXbytes:885729(864.9KiB)
Interrupt:11Baseaddress:0xc020
eth0:1Linkencap:EthernetHWaddr08:00:27:5A:99:F4
inetaddr:192.168.2.112Bcast:192.168.2.255Mask:255.255.255.0
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
Interrupt:11Baseaddress:0xc020
101
3) DNS /var/named/chroot/var/named/example.intranet.zone
server2
INA192.168.2.112
/var/named/chroot/var/named/192.168.2.zone
112PTRserver2.example.intranet.
6) server2 index.html
[root@server1~]#cd/var/www/html/
[root@server1html]#mkdirserver2
[root@server1html]#cdserver2
[root@server1server2]#echo"Welcometoserver2">index.html
7) httpd /etc/init.d/httpdrestart
servicehttpdrestart
19-5 http://server2.example.intranet
CentOS http://linux.sothorn.org
102
20
MySQL
MySQL () SQL. MySQL
MySQL AB
MySQL MySQL 2
David Axmark, Allan Larsson Michael "Monty" Widenius.
(Sun Microsystems, Inc.) MySQL AB
MySQL AB
: http://th.wikipedia.org/wiki/MySQL
MySQL CentOS
CentOS MySQL system-config-packages
103
[root@server1~]#chkconfigmysqldon
[root@server1~]#servicemysqldstart
InitializingMySQLdatabase:
StartingMySQL:
[OK]
[OK]
MySQL MySQL
Initializing MySQL database: MySQL MySQL
MySQL
user root
user root
user mysqladmin -u root password mypassword mypassword
user root mypassword
[root@server1~]#mysqladminurootpasswordmypassword
[root@server1~]#mysqlurootp
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis4
Serverversion:5.0.45Sourcedistribution
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>
MySQL
mysql>\q
Bye
[root@server1~]#
mysql>exit
Bye
[root@server1~]#
CentOS http://linux.sothorn.org
104
2 -p
[root@server1~]#mysqlurootpmypassword
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis6
Serverversion:5.0.45Sourcedistribution
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>
[root@server1~]#mysqlurootp
Enterpassword:
ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(using
password:YES)
[root@server1~]#
MySQL
[root@server1~]#mysqladmincreatnewdburootp
Enterpassword:
[root@server1~]#mysqlurootp
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis12
Serverversion:5.0.45Sourcedistribution
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>showdatabases;
++
|Database|
++
|information_schema|
|mysql|
|newdb|
|test|
++
4rowsinset(0.00sec)
mysql>
backup
mysql newdb < /path/to/file.sql -u root -p
[root@server1~]#mysqlnewdb</root/file.sqlurootp
Enterpassword:
CentOS http://linux.sothorn.org
105
Backup dump
[root@server1~]#mysqldumpdbname>/root/file_backup.sqlurootp
Enterpassword:
[root@server1~]#mysqlurootp
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis12
Serverversion:5.0.45Sourcedistribution
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>usemysql;
Readingtableinformationforcompletionoftableandcolumnnames
YoucanturnoffthisfeaturetogetaquickerstartupwithA
Databasechanged
mysql>UPDATEmysql.userSETPassword=PASSWORD('newpassword')WHERE
User='root';
QueryOK,0rowsaffected(0.00sec)
Rowsmatched:3Changed:0Warnings:0
mysql>flushprivileges;
QueryOK,0rowsaffected(0.00sec)
mysql>
mysql>SETPASSWORDFOR'root'@'localhost'=PASSWORD('newpassword);
newpassword
where user
user
MySQL user root
user user
mysql>grantallprivilegeson*.*tosothorn@'%';
QueryOK,0rowsaffected(0.00sec)
mysql>updateusersetPassword=password('password')where
User='sothorn';
QueryOK,1rowaffected(0.00sec)
Rowsmatched:1Changed:1Warnings:0
mysql>flushprivileges;
QueryOK,0rowsaffected(0.00sec)
CentOS http://linux.sothorn.org
106
user sothorn
(%) (*.*) db.* mydb.*
root@amdx2:~#mysqlh192.168.2.111usothornp
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis
Serverversion:5.0.45Sourcedistribution
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>
root MySQL
user root MySQL
[root@server1~]#/etc/init.d/mysqldstop
[root@server1~]#/usr/bin/mysqld_safeuser=rootskipgranttables&
[root@server1~]#mysql
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis2
Serverversion:5.0.45Sourcedistribution
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>UPDATEmysql.userSETPassword=PASSWORD('newpassword)WHERE
User='root';
mysql>FLUSHPRIVILEGES;
mysq>\q
[root@server1~]#mysqladminshutdown
[root@server1~]#/etc/init.d/mysqldstart
MySQL MySQL
skipgranttables MySQL
update
MySQL
CentOS 5.2 MySQL 5.0.45
http://dev.mysql.com/downloads/mysql/5.1.html
107
CPU CPU
1) mysqldump
2) MySQL /etc/init.d/mysqld stop
3) MySQL CentOS5.2 yum remove mysql-server
4)
[root@server1 mysql_install]# ls
MySQL-client-5.1.32-0.glibc23.i386.rpm
MySQL-debuginfo-5.1.32-0.glibc23.i386.rpm
MySQL-devel-5.1.32-0.glibc23.i386.rpm
MySQL-embedded-5.1.32-0.glibc23.i386.rpm
MySQL-server-5.1.32-0.glibc23.i386.rpm
MySQL-shared-5.1.32-0.glibc23.i386.rpm
MySQL-shared-compat-5.1.32-0.glibc23.i386.rpm
MySQL-test-5.1.32-0.glibc23.i386.rpm
MySQL
[root@server1mysql_install]#mysqlurootp
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis2
Serverversion:5.1.32MySQLCommunityServer(Copyright20002008MySQL
AB,2008SunMicrosystems,Inc.Allrightsreserved.Useissubject
Type'help;'or'\h'forhelp.Type'\c'toclearthebuffer.
mysql>
CentOS http://linux.sothorn.org
108
21
Apache+PHP phpMyAdmin
html
PHP MySQL,
PostgreSQL
CentOS Apache2
httpd
Web Server+PHP
Apache PHP system-config-package
Web Server
21-1 system-config-package
CentOS http://linux.sothorn.org
109
Optional
21-2
PHP
Close Apply
CentOS http://linux.sothorn.org
110
CentOS http://linux.sothorn.org
111
21-4 PHP
PHP MySQL
connect.php /var/www/html
<?php
$link=mysql_connect('localhost','root','mypassword');
if(!$link){
die('Couldnotconnect:'.mysql_error());
}
echo'Connectedsuccessfully';
mysql_close($link);
?>
Browser
Browser URL http://www.exaple.intranet/connect.php
112
phpMyAdmin
phpMyAdmin PHP MySQL
Web Browser
http://www.phpmyqdmin.net
21-6 www.phpmyadmin.net
phpMyAdmin 3.1.x CentOS 5.2 CentOS 5 .2 PHP
5.1 phpMyadmin 3.1.x phpMyAdmin
2.11.x phpMyAdmin-2.11.9.5-all-languages.tar.gz
/var/www/html
[root@server1~]#tarxvfzphpMyAdmin2.11.9.5alllanguages.tar.gz|
more
phpMyAdmin2.11.9.5alllanguages/
phpMyAdmin2.11.9.5alllanguages/scripts/
phpMyAdmin2.11.9.5alllanguages/scripts/find_unused_messages.sh
phpMyAdmin2.11.9.5alllanguages/scripts/remove_control_m.sh
phpMyAdmin2.11.9.5alllanguages/scripts/langcleanup.sh
[root@server1~]#mvphpMyAdmin2.11.9.5alllanguages
/var/www/html/phpMyAdmin
CentOS http://linux.sothorn.org
113
Browser
Browser URL http://phpmyadmin.example.intranet/
21-7 phpMyAdmin
20-7
/var/www/html/phpMyAdmin config.inc.php vi text editor
[root@server1~]#cd/var/www/html/phpMyAdmin/
[root@server1~]#cpconfig.sample.inc.phpconfig.inc.php
[root@server1~]#viconfig.inc.php
config.inc.php $cfg['blowfish_secret']
$cfg['blowfish_secret']='fsdfsdf';
CentOS http://linux.sothorn.org
114
21-9 phpMyAdmin
phpNuke, Joomla, Drupal, eGroupware
CentOS http://linux.sothorn.org
115
22
Postfix Mail Server
Postfix mail
SMTP(Simple Mail Transfer Protocol) TCP/IP
E-mail
inet_interfaces = localhost
mail mail mail server
inet_interfaces = all
CentOS http://linux.sothorn.org
116
mail server
9) user1 mail
[root@server1~]#suuser1
[user1@server1~]$mail
Mailversion8.16/6/93.Type?forhelp.
"/var/spool/mail/user1":1message1new
>N1root@example.intraneThuMar2621:1414/465"TestMail"
&1
Message1:
Fromroot@example.intranetThuMar2621:14:112009
XOriginalTo:user1@example.intranet
DeliveredTo:user1@example.intranet
To:user1@example.intranet
Subject:TestMail
Date:Thu,26Mar200921:14:11+0700(ICT)
From:root@example.intranet(root)
Test
&
CentOS http://linux.sothorn.org
117
11) Log
Mar2621:20:52server1postfix/pickup[8916]:72FA61C3920:uid=500from=<user1>
Mar2621:20:52server1postfix/cleanup[9147]:72FA61C3920:message
id=<20090326142052.72FA61C3920@example.intranet>
Mar2621:20:52server1postfix/qmgr[8917]:72FA61C3920:from=<user1@example.intranet>,size=310,
nrcpt=1(queueactive)
Mar2621:20:52server1postfix/local[9149]:72FA61C3920:to=<user2@example.intranet>,relay=local,
delay=0.13,delays=0.09/0.02/0/0.03,dsn=2.0.0,status=sent(deliveredtomailbox)
Mar2621:20:52server1postfix/qmgr[8917]:72FA61C3920:removed
Test
&
SquirrelMail
SquirrelMail PHP
http://www.squirrelmail.org/
Squirrelmail IMAP squirrelmail
IMAP mail dovecot
1) dovecot
[root@server1~]#yuminstalldovecot
[root@server1~]#chkconfigdovecoton
[root@server1~]#servicedovecotstart
/etc/init.d/dovecotstart
[root@server1~]#
dovecot
CentOS http://linux.sothorn.org
118
2) Squirrelmail
[root@server1~]#tarxvfzsquirrelmail1.4.17.tar.gz
[root@server1~]#cdsquirrelmail1.4.17
[root@server1squirrelmail1.4.17]#cpR*/var/www/html/webmail/
[root@server1squirrelmail1.4.17]#cd/var/www/html/webmail/config
[root@server1config]#cpconfig_default.phpconfig.php
[root@server1config]#cd/var/local/
[root@server1local]#mkdirpsquirrelmail/data
[root@server1local]#chmod777squirrelmail/data
CentOS http://linux.sothorn.org
119
SquirrelMail
22-2 SquirrelMail
SquirrelMail
Plugins
webmail OpenWebmail, NOCC Webmail, IlohaMail
CentOS http://linux.sothorn.org
120
23
SSH SFTP
telnet telnet
Secure Shell (SSH)
Secure Shell (SSH)
SSH telnet
Secure File Transfer Protocol (SFTP)
FTP SSH sftp-server
sftp linux
Windows SSH winscp
SSH Secure File Transfer Client
ssh sftp Red Hat
Firewall
ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-w local_tun[:remote_tun]] [user@]hostname [command]
ssh
[root@client1~]#sshlroot192.168.2.111
root@192.168.2.111'spassword:
Lastlogin:FriMar2718:23:352009from192.168.2.111
[root@client1~]#
[root@client1~]#sshlroot192.168.2.111shutdownhnow
root@192.168.2.111'spassword:
Lastlogin:FriMar2718:23:352009from192.168.2.111
ssh
SSH Client
Putty SSH Secure Shell Client
CentOS http://linux.sothorn.org
121
Putty
23-1 Putty
SSH Secure Shell Client
CentOS http://linux.sothorn.org
122
sftp
sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
[-o ssh_option] [-P sftp_server_path] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
ftp [[user@]host[:file [file]]]
sftp [[user@]host[:dir[/]]]
sftp -b batchfile [user@]host
sftp
Server (Download)
root@amdx2:~#sftproot@192.168.2.111
Connectingto192.168.2.111...
root@192.168.2.111'spassword:
sftp>ls
mydb_backup.tar.gz
sftp>getmydb_backup.tar.gz
getmydb_backup.tar.gz
Fetching/root/mydb_backup.tar.gztomydb_backup.tar.gz
/root/mydb_backup.tar.gz100%2080.2KB/s
00:00
sftp>
Server (Upload)
root@amdx2:~#ls
VirtualBox2.1.241885Linux_amd64.run
sftp>bye
root@amdx2:~#sftproot@192.168.2.111
Connectingto192.168.2.111...
root@192.168.2.111'spassword:
sftp>lls
VirtualBox2.1.241885Linux_amd64.run
sftp>putVirtualBox2.1.241885Linux_amd64.run
UploadingVirtualBox2.1.241885Linux_amd64.runto/root/VirtualBox
2.1.241885Linux_amd64.run
VirtualBox2.1.241885Linux_amd64.run100%37MB3.1MB/s
00:12
sftp>
sftp
sftp
client WinSCP, SSH Secure File transfer Client
CentOS http://linux.sothorn.org
123
WinSCP
23-3 winscp
SSH Secure File transfer Client
CentOS http://linux.sothorn.org
124
SFTP
sftp gFTP
23-5 gFTP
CentOS http://linux.sothorn.org
125
24
NFS Server
Network File System (NFS) Sun Microsystems 1984
NFS Server
Red Hat NFS NFS
NFS portmap
[root@server1~]#chkconfigportmapon
[root@server1~]#serviceportmapstart
Startingportmap:[OK]
[root@server1~]#chkconfignfson
[root@server1~]#servicenfsstart
StartingNFSservices:[OK]
StartingNFSquotas:[OK]
StartingNFSdaemon:[OK]
StartingNFSmountd:[OK]
[root@server1~]# [OK]
NFS Server
/etc/exports
/var/ftp/pub
192.168.1.0/255.255.255.0(ro,sync,no_root_squash)
/var/ftp/pub
192.168.1.0/255.255.255.0
IP Address
options
rw
ro
async
sync
all_squash
anonymous
root_squash
root anonymous
no_root_squash
root root
anonuid=uid
uid
anongid=gid
gid
no_wdelay
http://www.troubleshooters.com/linux/nfs.htm
CentOS http://linux.sothorn.org
126
NFS Server
[root@server1~]#exportfs
/var/ftp/pub192.168.1.0/255.255.255.0
[root@server1~]#
[root@server1~]#showmounte192.168.1.1
Exportlistforlocalhost:
/var/ftp/pub192.168.1.0/255.255.255.0
NFS Client
server
NFS Client mount mount
15
mount
[root@server1~]# mkdir /mnt/nfs
[root@server1~]# mount 192.168.1.1:/var/ftp/pub /mnt/nfs
mount nfs
mount
mount /etc/fstab /etc/fstab 15
192.168.1.1:/var/ftp/pub /mnt/nfsnfs
defaults
CentOS http://linux.sothorn.org
127
25
Server Arno's Script
Firewall iptables
kernel iptables
Firewall
system-configsecurity-level
Server
iptables Arno's Script Arno van Amersfoort
Electronics/Computer Engineering arno
http://rocky.eld.leidenuniv.nl/
CentOS http://linux.sothorn.org
128
Arno's script
http://rocky.eld.leidenuniv.nl/iptables-firewall/arno-iptables-fir ewall_1.8.6c.tar.gz
arno-iptables-firewall_1.8.6c.tar.gz
[root@server1~]#tarxvfzarnoiptablesfirewall_1.9.0b.tar.gz
arnoiptablesfirewall_1.9.0b/
arnoiptablesfirewall_1.9.0b/bin/
arnoiptablesfirewall_1.9.0b/bin/arnofwfilter
arnoiptablesfirewall_1.9.0b/bin/arnoiptablesfirewall
arnoiptablesfirewall_1.9.0b/etc/
[root@server1~]#cdarnoiptablesfirewall_1.9.0b
[root@server1arnoiptablesfirewall_1.9.0b]#ls
bincontribgpl_license.txtREADMEuninstall.sh
CHANGELOGetcinstall.shshare
[root@server1arnoiptablesfirewall_1.9.0b]#./install.sh
Whatisyourexternalinterface(aka.internetinterface)(multiple
interfacesshouldbecommaseparated)?eth0
DoesyourexternalinterfacegetitsIPthroughDHCP?(Y/N)N
Doyouwanttobepingablefromtheinternet?(Y/N)Y
WhichTCPportsdoyouwanttoallowfromtheinternet?(ie.22=SSH,
80=HTTP,etc.)(commaseparatemultipleports)?2280
WhichUDPportsdoyouwanttoallowfromtheinternet?(ie.53=DNS,
etc.)(commaseparatemultipleports)?53
Doyouhaveaninternal(akaLAN)interfacethatyouwanttosetup?(Y/N)
N
Doyouwanttheinitscripttobeverbose(printoutwhatit'sdoing)?
(Y/N)Y
Arno's Script
Arno's Script
[root@server1arnoiptablesfirewall_1.9.0b]#chkconfigiptablesoff
[root@server1arnoiptablesfirewall_1.9.0b]#chkconfigarnoiptables
firewallon
[root@server1arnoiptablesfirewall_1.9.0b]#/etc/init.d/arnoiptables
firewallstart
IPTABLES iptables -L
port
/etc/arno-iptablesfirewall/firewall.conf /etc/arno-iptables-firewall/firewall.conf
Proxy Firewall Endian IPCop
/etc/arno-iptables-firewall/firewall.conf
IPTABLES /etc/arno-iptables-firewall.conf
CentOS http://linux.sothorn.org
129
/etc/arno-iptables-firewall/firewall.conf
EXT_IF="eth0"
EXT_IF
eth0 eth1 eth2
OPEN_ICMP="1"
OPEN_ICMP ping OPEN_ICMP="1"
ping OPEN_ICMP="0" ping
OPEN_TCP="22 80"
OPEN_TCP Port TCP port
OPEN_UDP="53"
OPEN_UDP Port UDP OPEN_TCP
CentOS http://linux.sothorn.org
130
26
SAMBA
Samba
smbclient linux, unix
Samba system-config-packages
CentOS http://linux.sothorn.org
131
[root@server1~]#useraddpiti
[root@server1~]#passwdpiti
Changingpasswordforuserpiti.
NewUNIXpassword:
BADPASSWORD:itisbasedonadictionaryword
RetypenewUNIXpassword:
passwd:allauthenticationtokensupdatedsuccessfully.
[root@server1~]#smbpasswdapiti
NewSMBpassword:
RetypenewSMBpassword:
startsmbfilepwent_internal:file/etc/samba/smbpasswddidnotexist.
Filesuccessfullycreated.
Addeduserpiti.
[root@server1~]#servicesmbstart
StartingSMBservices:[OK]
StartingNMBservices:[OK]
[root@server1~]#
server
\\192.169.1.111 Username password
CentOS http://linux.sothorn.org
132
Login
/etc/samba/smb.conf
[ourshare]
comment=ShareFolder
path=/share
validusers=piti
public=no
writable=yes
Samba
[root@server1~]#servicesmbrestart
ShuttingdownSMBservices:[OK]
ShuttingdownNMBservices:[OK]
StartingSMBservices:[OK]
StartingNMBservices:[OK]
[root@server1~]#
CentOS http://linux.sothorn.org
133
4
1. (pr) 1 somsri
2. (web) 2 somchai, suchart
3. (sale) 1 somwang
4. (support) 1 saisamorn
Samba Server pr, web, sale support
(manager)
CentOS http://linux.sothorn.org
134
User
[root@server1~]#groupaadmanager
[root@server1~]#groupaadpr
[root@server1~]#groupaadweb
[root@server1~]#groupaddsale
[root@server1~]#groupaddsupport
[root@server1~]#useraddgmanagermanager
[root@server1~]#useraddgprsomsri
[root@server1~]#useraddgwebsomchai
[root@server1~]#useraddgwebsuchart
[root@server1~]#useraddgsalesomwang
[root@server1~]#useraddgsupportsaisamorn
[root@server1~]#usermodGpr,web,sale,supportmanager
[root@server1~]#passwdmanager
[root@server1~]#passwdsomsri
[root@server1~]#passwdsomchai
[root@server1~]#passwdsuchart
[root@server1~]#passwdsomwang
[root@server1~]#passwdsaisamorn
[root@server1~]#smbpasswdamanager
[root@server1~]#smbpasswdasomsri
[root@server1~]#smbpasswdasomchai
[root@server1~]#smbpasswdasuchart
[root@server1~]#smbpasswdasomwang
[root@server1~]#smbpasswdasaisamorn
[root@server1~]#mkdir/depts
[root@server1~]#mkdirp/depts/{pr,web,sale,support}
[root@server1~]#groupaddpr
[root@server1~]#groupaddweb
[root@server1~]#groupaddsale
[root@server1~]#groupaddsupport
[root@server1~]#chgrppr/depts/pr
[root@server1~]#chgrpweb/depts/web
[root@server1~]#chgrpsale/depts/sale
[root@server1~]#chgrpsupport/depts/support
[root@server1~]#chmod770/depts/pr
[root@server1~]#chmod770/depts/web
[root@server1~]#chmod770/depts/sale
[root@server1~]#chmod770/depts/support
[root@server1~]#chmodg+s/depts/*
CentOS http://linux.sothorn.org
135
/etc/samba/smb.conf
[pr]
comment=ShareforPR
path=/depts/pr
validusers=managersomsri
public=no
writable=yes
[web]
comment=ShareforWeb
path=/depts/web
validusers=managersomchaisuchat
public=no
writable=yes
[sale]
comment=ShareforSale
path=/depts/sale
validusers=managersomwang
public=no
writable=yes
[support]
comment=ShareforSupport
path=/depts/support
validusers=managersaisamorn
public=no
writable=yes
user comment
#[homes]
;comment=HomeDirectories
;browseable=no
;writable=yes
Samba
[root@server1~]#/etc/init.d/smbrestart
ShuttingdownSMBservices:[OK]
ShuttingdownNMBservices:[OK]
StartingSMBservices:[OK]
StartingNMBservices:[OK]
[root@server1~]#
CentOS http://linux.sothorn.org
136
Samba
Samba 2 Global Global
[global] global
[home] [printers] [xxx] xxx
; (semi-colon) # (hash)
#
;
# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
; comment = Fred's Service
; path = /usr/somewhere/private
; valid users = fred
; public = no
; writable = yes
; printable = no
Samba 4
security
security = share user
security = user username password samba
security = server security = user username password
Samba server
security = domain Samba Windows Domain
primary domain controller (PDC) Samba server
Public = yes Guest ok = yes /etc/samba/smbd.conf
CentOS http://linux.sothorn.org
137
user
user set password password
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
encrypt passwords = yes user login /etc/samba/smbpasswd
user /etc/samba/smbpasswd
smbpasswd -a user smbpasswd somchai
password user smbpasswd user smbpasswd somchai
smbpasswd smbpasswd help encrypt passwords = no password
/etc/pasword
Networking Options
Network IP Address
hosts allow = 192.168.1.
hosts deny = 192.168.1.226/255.255.255.255
hosts deny = ALL EXCEPT 192.168.1.
192.168.1. () Samba
192.168.1. 0/255.255.255.0 192.168.1.0/24 IP
192.168.1.1-192.168.1.254
Samba configuration host allow, hosts deny
1. hosts allow hosts deny Samba
( hosts allow = ALL)
2. hosts allow, hosts deny [global]
hosts allow, deny
138
Samba permission
option Samba permission
valid users = somchai suchart @web
( @
group)
** valid users invalid users
invalid users
invalid users = lertsak @guest
writable = yes
writeable = yes
write ok = yes
read only = no
read list = choawalit kitisak
read list list write list, read only, writeable read only
139
hosts equiv =
/etc/samba/smb.conf hosts equiv
( hosts.equiv
Unix)
http://www.thaicert.org/paper/unix_linux/samba.php
smbclient
smbclient client
smbclient // IP Address/ -U username%password
root@sothorn:~#smbclient//192.168.1.111/prUmanager%password
Domain=[OURINTRANET]OS=[Unix]Server=[Samba3.0.101.4E]
smb:\>ls
.D0SatMar2813:53:302009
..D0ThuMar2615:43:342009
new_file_in_pr.txtA0SatMar2813:52:552009
63002blocksofsize131072.39053blocksavailable
smb:\>?
?altnamearchiveblocksizecancel
case_sensitivecdchmodchowndel
dirduexitgetgetfacl
hardlinkhelphistorylcdlink
lowercaselsmaskmdmget
mkdirmoremputneweropen
printpromptputpwdq
queuequitrdrecursereget
renamereputrmrmdirsetmode
statsymlinktartarmodetranslate
volumevuidlogonlistconnectshowconnect
!
smb:\>
Samba
CentOS http://linux.sothorn.org
140
27
linux rescue
linux rescue CentOS CD DVD
rescue
CD DVD rescue
linux rescue
CD DVD CentOS
CentOS http://linux.sothorn.org
141
CentOS http://linux.sothorn.org
142
Network Yes No
CentOS http://linux.sothorn.org
143
mount /mnt/sysimage
Continue mount Read-Only
Skip
/mnt/sysimage OK
CentOS http://linux.sothorn.org
144
OK / CD
chroot /mnt/sysimage
CentOS http://linux.sothorn.org
145
/etc/fstab mount
mount
CentOS http://linux.sothorn.org
146
linux rescue
CentOS http://linux.sothorn.org
147
CentOS
CentOS http://linux.sothorn.org
148
1
2
3 CentOS
4
5 Service
6
7 Vi
8 RPM Yum
9 User / Group Accounts
10 Permission Directory
11 System Config
12 mount system
13 Backup
14
15 crontab
16
17 Disk Quota
18 DNS (Domain Name System)
19 Apache Virtual Host
20 MySQL
21 Apache+PHP
22 Postfix Mail Server
23 SSH SFTP
24 NFS Server
25 Server Arno's Script
26 SAMBA
27 linux rescue
1
3
5
31
36
40
43
46
57
60
64
70
72
74
77
79
87
90
97
102
108
115
120
125
127
130
140
CentOS http://linux.sothorn.org
149
-
. .
() 2
3615621
1 .. 2540 - 30 .. 2541
1 .. 2541 - 31 .. 2543
1 .. 2543 - 26 .. 2550 Hospital OS
.. 2542 (http://www.linuxsiam.com)
12 2549 3 6
2550 7
2552 9
http://linux.sothorn.org
http://www.bansuanporpeang.com
CentOS http://linux.sothorn.org
150
...
http://linux.sothorn.org
937-0-05817-6
sothorn@gmail.com
CentOS http://linux.sothorn.org