03 Services Configuration
Sherbimet
Per te garantuar nje sistem te sigurte eshte e rendesishme qe te kontrollojme aksesin tek sherbimet. Sistemi mund te kete nevoje qe te lejoje akses te hapur per disa nga sherbimet per shembull httpd por duhet te mos lejoje kapjen e sherbimeve te tjera nga perdorues te paautorizuar. Si rregull nese serveri nuk do ta ofroje nje sherbim eshte mire qe ai te c'aktivizohet per te shmangur ndonje thyerje te mundshme te sigurise.
Ne kete leksion do te shpejgojme konceptin e "Niveleve te ekzekutimit " ose Run-Level, percaktimin e sherbimeve qe do te ekzekutohen ne sejcilin nga nivelet e ekzekutimit si edhe se si te konfigurojme sherbimet.
Nivelet e ekzekutimit, Run-Level
Nje nivel ekzektuimi eshte nje gjendje ( state ose mode) qe percaktohet nga sherbimet qe do te ekzekutohen ne ate nivel. Ka 7(shtate) nivele ekzekutimi te numeruar duke nisur nga 0
Per te pare ne cilin nivel ekzekutimi eshte duke u ekzekutuar sistemi mund te perdorim komanden runlevel,
[root@localhost student]# runlevel
N 5
[root@localhost student]#
Komanda me part tregon qe sistemi po ekzekutohet ne full multi user mode me nderfaqe grafike.
Niveli baze i ekzekutimit ( default run level ) mund te percaktohet duke modifikuar skedarin /etc/inittab
[root@localhost student]# cat /etc/inittab
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
[root@localhost student]#
Skedari i mesiperm /etc/inittab percakton si nivel baze te ekzekutimit nivelin 5, multi user mode me nderfaqe grafike.
Per te ndryshuar nivelin baze te ekzekutimit mjfaton qe te editojme kete skedar me nje editor teksti.
Ndryshimi do te aplikohet kur sistemi te rindizet.
Ushtrim
1- Ndryshoni nivelin baze te ekzekutimit nga 5 ne 3 ( multiuser mode me nderfaqe tekst)
2- reboot makinen
3- logohuni ne sistem me perdoruesin root password: student
4 - Jeni ne text mode
5- hapni skedarin /etc/inittab me editorin nano ( nano /etc/inittab)
6- rivendosni nivelin e ekzekutimit 5 ( multi user mode me nderfaqe grafike )
7- reboot makinen
8- jeni ne graphic mode
Konfigurimi i sherbimeve
Per te konfiguruar sherbimet RedHat Linux ka disa mjete:
Programi Grafik Service Configuration
Komanda ntsysv
Komanda chkconfig
Programi grafik Service Configuration
Ndersa jemi ne moden grafike, Nga menuja kryesore klikojme System -> Administration -> Services
Butoni Customize na lejon qe te percaktojme qe per sherbimin e selektuar te percaktojme ne cilat nivele ekzekutimi mund te ekzekutohet:
Tabela me poshte tregon gjendjet e mundshme te nje service
Nje sherbim mund te jete enable dhe running , ose mund te jete enabled dhe not running.
Enabled ose Disabled percaktojne nese sherbimi eshte i lejuar per nivelin korrent te ekzekutimit , ndersa gjendja ( running, not running) percakton qe nese sherbimi eshte enabled eshte ene ekzekutim apo jo.
Komanda ntsysv
Komanda ntsysv ofron nje ndefaqe te thjeshte tekstuale per te percaktuar cili nga sherbimet do te ekzekutohet ne nje nivel ekzekutimi.
Per ta therritur kete program shkruajme ntsysv ne linjen e komandes:
[root@localhost student]# ntsysv
dhe do te hapet programi pamja e te ciliet eshte e ngjashme me pamjen e meposhtme:
Si rregull ntsysv percakton sherbimet qe do te aktivizohen per niveln korrent te ekzekutimit.
Por eshte e mundur qe te therritet programi duke i percaktuar si argument nje nivel ekzekutimi duke percaktuar cilat sherbime do te aktivizohen ne ate nivel:
Sintaksa e komandes ne kete rast eshte
ntsysv --level runlevels
Per shembull mund te therrasim ntsysv qe te percaktoje sherbimet qe do te lejohen ne nivelet 3 dhe 5:
[root@localhost student]# ntsysv --level 35
do te hapte serish editorin por per nivelet 3 dhe 5.
Ne dallim nga Service Configuration utility , komanda ntsysv eshte disponibel edhe ne nivelin 3 te ekzekutimit ( text mode interface)
Ushtrim
Kalojeni sistemin ne nivelin e ekzekutimit 3 dhe therritni aty ntsysv per nivelet 3 dhe 5.
Komanda chkconfig
Komanda chkconfig qe na lejon te percaktojme ne cilin nivel ekzekutimi duam ta startojme nje sherbim te caktuar si edhe qe te listojme te gjithe sherbimet disponibel.
chkconfig eshte e ngjashme me ntsysv por nuk ofron nderfaqe grafike tekstuale.
Per shembull per te listuar te gjithe sherbimet dhe nivelet ku ata jane te aktivizuar mund te perdorim opsioni list, si me poshte:
[root@localhost student]# chkconfig --list
NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
.............................................................................
xinetd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
xinetd based services:
tftp: on
...................................
[root@localhost student]#
E njejta gje ndodh edhe nese therrasim vetem chkconfig.
Cdo rresht i rezultatit ka emrin e sherbimit dhe me pas vijon statusi i tij ne sejcilin nga nivelet e ekzekutimit (psh 0:off tregon qe ne nivelin 0 nuk eshte i aktivizuar)
mund ta filtrojme rezultatin vetem per ato sherbime qe interesohemi duke perdorur grep ose duke i kerkuar chkconfig te na jape informacion per nje sherbim te caktuar si opsion te komandes.
Shembull duke perdorur grep
[root@localhost student]# chkconfig --list | grep ftp
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
tftp: on
[root@localhost student]#
Shembull duke perdorur opsionet e komandes chkconfig
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost student]#
Aktivizimi i nje sherbimi
Komanda chkconfig e aktivizon nje sherbim ne nivelet 2,3,4,5 nese niveli nuk percaktohet ne menyre eksplicite ne opsionet e komandes.
Per te aktivizuar nje sherbim ne nivelet 2,3,4,5 mund te perdorim chkconfig on
Shembulli me poshte c'aktivizon sherbimin vsftpd nga nivelet 2,3,4,5 dhe me pas e ri aktivizon ate ne keto nivele:
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost student]# chkconfig vsftpd off
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost student]# chkconfig vsftpd on
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost student]#
Nese duam qe te aktivizojme ( ose c'aktivizojme nje sherbim ) ne ne nivel te caktuar atehere duhet te perdorim opsionin --level me nivelet per te cilat duam te aktivizojme sherbimin.
Shembulli me poshte fillimisht e caktivizon sherbimin vsftpd ne nivelin 5 dhe me pas e riaktivizon ate ne kete nivel:
Verifikojme qe sherbimi eshte i aktivizuar ne nivelet 3 dhe 5
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
E c'aktivizojme sherbimin ne nivelet 3 dhe 5
[root@localhost student]# chkconfig vsftpd off on --level 35
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:off 4:on 5:off 6:off
Verifikojme status in e sherbimit.
[root@localhost student]# service vsftpd status
vsftpd (pid 1730) is running...
Ndonese sherbimi eshte c'aktivizuar ne nivelin 5 ai eshte enede ne ekzekutim. Ne fakt konfigurimi qe kemi aplikuar do te aplikohet ne momentin qe rindizet makina.
[root@localhost student]# chkconfig vsftpd on on --level 35
[root@localhost student]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost student]#
Ushtrim
verifikoni qe sherbimi httpd eshte running..
C'aktivizoni sherbimin httpd per nivelin 5.
verifikoni statusin e sherbimi pas ketij veprimi
Rindizni makinen
Verifikoni statusin e sherbimit httpd.
Riaktivizoni sherbimin httpd ne nivelin 5.
startoni sherbimin me service http start.
Ekzekutimi i sherbimeve
Komanda service na mundeson qe te verifikojme statusin e ekzekutimit te nje sherbimi, te startojme , te stopojme dhe te ristarojme nje sherbim.
Shembujt me poshte ilustojne keto funksione:
[root@localhost student]# service httpd status
httpd (pid 2464) is running...
[root@localhost student]# service httpd stop
Stopping httpd: [ OK ]
[root@localhost student]# service httpd status
httpd is stopped
[root@localhost student]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
[root@localhost student]# service httpd status
httpd (pid 2518) is running...
[root@localhost student]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
[root@localhost student]# service httpd status
httpd (pid 2553) is running...
[root@localhost student]#
Ndersa komanda service --status-all shfaq gjendjen e te gjithe sherbimeve:
[root@localhost student]# service --status-all
iptables: Firewall is not running.
vsftpd (pid 1730) is running...
.......................................
xinetd (pid 1719) is running...
[root@localhost student]#