顯示具有 LINUX-安裝及移除套件 標籤的文章。 顯示所有文章
顯示具有 LINUX-安裝及移除套件 標籤的文章。 顯示所有文章

Fail2Ban & iptables & SELinux 三角習題

yum安裝及設定Fail2Ban後(來源epel),
可以看到相關的統計數據(fail2ban-client status ssh-iptables),
也會email通知目前有人在try帳密,但就是不會鎖IP
而且在iptables也看不到由Fail2Ban所加入的chain。

查看fail2ban.log看到以下的錯誤訊息。
# rpm -q fail2ban
 fail2ban-0.8.14-2.el6.noarch

# uname -r
 2.6.32-504.23.4.el6.i686

# cat /var/log/fail2ban.log
 2015-07-01 13:21:07,299 fail2ban.actions.action[32420]: ERROR iptables -n -L INPUT | grep -q 'fail2ban-SSH[ \t]' returned 100
 2015-07-01 13:21:07,299 fail2ban.actions.action[32420]: CRITICAL Unable to restore environment
 2015-07-01 14:53:19,471 fail2ban.server [32420]: INFO Stopping all jails
 2015-07-01 14:53:20,158 fail2ban.actions.action[32420]: ERROR iptables -D INPUT -p tcp --dport ssh -j fail2ban-SSH
 iptables -F fail2ban-SSH
 iptables -X fail2ban-SSH returned 300
 2015-07-01 14:53:20,243 fail2ban.jail [32420]: INFO Jail 'ssh-iptables' stopped
 2015-07-01 14:53:20,245 fail2ban.server [32420]: INFO Exiting Fail2ban

將SELinux改為Permissive 模式後 Fail2ban 就正常工作了(可以看到ssh-iptalbes的chain)
查看SElinux Alert看到以下的訊息
SELinux Is Preventing /sbin/iptables-multi-1.4.7 From Read Access On The File/rawip_socket
接下來查看iptables-multi-1.4.7的selinux context,應該為system_u:object_r:iptables_exec_t:s0。 # ls -lZ /sbin/iptables-multi-1.4.7
 -rwxr-xr-x. root root system_u:object_r:bin_t:s0 /sbin/iptables-multi-1.4.7

修正selinux context
# restorecon -R -v /sbin/
 restorecon reset /sbin/iptables-multi-1.4.7 context system_u:object_r:bin_t:s0
->system_u:object_r:iptables_exec_t:s0

# service fail2ban restart

成功囉!!!!

安裝及移除套件-YUM(續)

如何替 repo 檔安排順序?

安裝yum優先權套件 # yum install -y yum-plugin-priorities
之後在 [repo_name] 的段區中加上: failovermethod=priority
priority=N  //N=1~99,1 優先權最高

安裝及移除套件-X Window System

若 Linux 系統是最小安裝(是 mini 而不是 mini desktop)後想要安裝 X-Windows,在 yum 套件群姐安裝的協助下變的超級簡單
當然!你要先把 yum 和網路組態搞定。

網路設定:因為最小安裝沒有 setup 可用,因此要直接編輯 ifcfg-ethX,完成後重啟網路。
# vi /etc/sysconfig/network-script/ifcfg-eth0  // 最小安裝沒有 vim 可以用,但操作差不多
 DEVICE="eth0"
 BOOTPROTO="dhcp"
 HWADDR="00:0C:29:16:03:D1"
 IPV6INIT="yes"
 NM_CONTROLLED="no"   // 預設為 yes
 ONBOOT="yes"  // 預設為 no
 TYPE="Ethernet"
 UUID="ad0722c8-66bb-4d03-8dd0-8be3c6cd0d8b"

# service network restart
# ip a

YUM 設定請參考此篇

查詢 X-Windows 套件
# yum grouplist | grep --color X
 Legacy UNIX compatibility
 Legacy X Window System compatibility
 X Window System
 TeX support
 Xfce
 Xhosa Support [xh]

安裝 X-Windows 及 GNOME Desktop
# yum groupinstall [-y] "X Window System" [&> /dev/null]  // 中括號 [] 內容加上後(不含 [])會自動安裝並隱藏安裝訊息
# yum groupinstall [-y] "Desktop" [&> /dev/null]
# yum groupinstall [-y] "Chinese Support [zh]" [&> /dev/null]  // 若想要支援中文環境再安裝就好

下次啟動使用 X-Window 介面 # vim /etc/inittab  id:5:initdefault:
重開機
# reboot

安裝及移除套件-rpm

20121109 新增補充資訊
20121120 新增指令說明

RPM(Redhat Package Manager)是 Linux 必學的套件管理程式,yum 的運行也是透過 rpm,差別在於 yum 可以自動解決相依性的問題,不必使用者自行尋找安裝套件來源。

RPM相依性的問題非常麻煩,安裝完下面所有的套件後(由下而上),才能安裝套件a,而在yum出現之前,都要使用者自行解決相依性的問題。

rpm 安裝流程有下列 5 個步驟:
1. 檢查數位簽章
2. 進行相依性檢查(檢查失敗中斷安裝)
3. 執行 pre script
4. 解壓縮並複製檔案至指定路徑
5. 執行 post script

安裝


# rpm -ivh xxx.rpm  // 本地安裝
# rpm -ivh http://aaa.bbb.com/xxx.rpm  // 網路安裝

更新


參數 U 和 F 的差別:
下載 pidgin 套件並使用參數 U 和 F 來安裝
參數 F:若 pidgin 原先並未安裝,則該軟體不會安裝,若原先有安裝,就會升級(upgrade)
參數 U:若 pidgin 原先並未安裝,則該軟體會安裝在系統上,若原先有安裝,就會升級(upgrade)
# rpm -Fvh pidgin-2.7.9-5.el6.2.x86_64.rpm  // 無後續安裝步驟
# rpm -Uvh pidgin-2.7.9-5.el6.2.x86_64.rpm  // 執行安裝步驟,但相依性檢查失敗中斷安裝
 error: Failed dependencies:
 libgstfarsight-0.10.so.0()(64bit) is needed by pidgin-2.7.9-5.el6.2.x86_64
 libpurple = 2.7.9-5.el6.2 is needed by pidgin-2.7.9-5.el6.2.x86_64
 libpurple.so.0()(64bit) is needed by pidgin-2.7.9-5.el6.2.x86_64

移除


# rpm -e firefox

GPG(GNU Private Guard)key 數位簽章驗證


安裝(匯入)原廠公開金鑰: # rpm --import ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/x86_64/RPM-GPG-KEY-CentOS-6
使用原廠公開金鑰驗證該網站下載套件的數位簽章 # rpm -K firefox-10.0.10-1.el6.centos.x86_64.rpm
 firefox-10.0.10-1.el6.centos.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
# rpm -K google-chrome-stable_current_x86_64.rpm
 google-chrome-stable_current_x86_64.rpm:(SHA1) DSA sha1 md5 (GPG) NOT OK (MISSING KEYS:
 GPG#7fac5991)  // 用 CentOS 的 key 來驗證 google 的套件


查詢


查詢檔案屬於哪一個已安裝的套件: # rpm -qf /etc/ntp.conf
 ntp-4.2.4p8-2.el6.centos.x86_64

查詢套件資訊: # rpm -qi httpd
查詢所有已安裝的套件: # rpm -qa
# rpm -q httpd

查詢已安裝的套件的所有檔案及路徑: # rpm -ql ntp
 /etc/dhcp/dhclient.d
 /etc/dhcp/dhclient.d/ntp.sh
 /etc/ntp.conf
 ........

查詢套件安裝狀態: # rpm -qs httpd | tail -n4
 normal /var/www/icons/world1.gif  // normal 表示安裝正常
 normal /var/www/icons/world1.png
 normal /var/www/icons/world2.gif
 normal /var/www/icons/world2.png
 ........

查詢套件相依性: # rpm -qR httpd
 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
 rpmlib(VersionedDependencies) <= 3.0.3-1
 rtld(GNU_HASH)
 system-logos >= 7.92.1-1
 rpmlib(PayloadIsXz) <= 5.2-1
 ........

查詢套件安裝或移除腳本(script): # rpm -q --scripts httpd
查詢未安裝套件相關指令: # rpm -qp pidgin
# rpm -qpl pidgin
# rpm -qpR pidgin
# rpm -qpi pidgin
# rpm -q --scripts pidgin
補充:不能與參數 s 同時使用,因為還沒有安裝,不會有安裝時的狀態。

重新安裝套件: # rpm -ivh --replacepkgs vsftpd
補充:此參數也可以解釋為 reinstall,但並不會覆蓋原先的檔案,只是將缺少的檔案再補回去。

驗證


檢查檔案內容是否被更動過: # rpm -Vf /etc/httpd/conf/httpd.conf
 S.5....T. c /etc/httpd/conf/httpd.conf  // 若檔案未遭到改變,就不會出現此行訊息

檢查套件檔案狀態: # rm -rf /etc/vsftpd/vsftpd.conf
# rpm -V vsftpd
 missing c /etc/vsftpd/vsftpd.conf

補充:
S:file Size differs(檔案的容量大小已被改變)
M:Mode differs (includes permissions and file type)(檔案的類型或檔案的屬性 (rwx) 已被改變)
5:MD5 sum differs(加密總合已被改變)
D:Device major/minor number mismatch(裝置的主 / 次代碼已經改變)
L:readLink(2) path mismatch(Link 路徑已被改變)
U:User ownership differs(檔案的所屬人已被改變)
G:Group ownership differs(檔案的所屬群組已被改變)
T:mTime differs(檔案的建立時間已被改變)
P:caPabilities differ

c:%config configuration file.
d:%doc documentation file.
g:%ghost file (i.e. the file contents are not included in the package payload).
l:%license license file.
r:%readme readme file.
資料來源

安裝及移除套件-YUM

20121120新增指令

YUM 與 RPM 皆可安裝、移除、查詢及升級套件,差別在於 YUM 可透過網路自動下載安裝與升級的套件。

本人常用的三個伺服器
  1. 中華電信:http://mirror01.idc.hinet.net/CentOS/6.3/os/x86_64/
  2. 台灣高品質學術研究網路:http://ftp.twaren.net/Linux/CentOS/6.3/os/x86_64/
  3. 國立中山大學:ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/x86_64/
yum 組態檔設定:以中山大學伺服器為例
# vim /etc/yum.repos.d/nsysu.repo
  [nsysu]
  name=nsysu
  baseurl=ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/i386/
  enabled=1
  gpgcheck=1
  gpgkey=ftp://ftp.nsysu.edu.tw/Unix-like/CentOS/6.3/os/i386//RPM-GPG-KEY-EPEL-6

upgrade/downgrade:升級/降級套件
範例:升級 rpm 套件
# yum upgrade [-y] rpm  // -y 自動安裝
 Loaded plugins: fastestmirror, refresh-packagekit, security
 Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * epel: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: centosa5.centos.org
  ......
 Dependencies Resolved
   ==================================================================================
 Package   Arch  Version    Repository  Size
 ==================================================================================
 Updating:
 rpm      i686  4.8.0-27.el6         base         898 k
 Updating for dependencies:
 rpm-libs    i686  4.8.0-27.el6         base          313 k
 rpm-python  i686  4.8.0-27.el6        base          53 k
 Transaction Summary
 ==================================================================================
 Upgrade 3 Package(s)
 Total download size: 1.2 M
 Is this ok [y/N]: 詢問是否安裝

info:查詢套件資訊
範例:查詢 vsftpd 套件資訊
# yum info vsftpd
 Loaded plugins: fastestmirror, refresh-packagekit, security
 Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * epel: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: centosa5.centos.org
 Installed Packages
 Name : vsftpd
 Arch : i686
 Version : 2.2.2
 Release : 11.el6
 Size : 344 k
 Repo : installed
 From repo : base
 Summary : Very Secure Ftp Daemon
 URL : http://vsftpd.beasts.org/
 License : GPLv2 with exceptions
 Description : vsftpd is a Very Secure FTP daemon. It was written completely from : scratch.

search:搜尋套件
範例:搜尋 vsftpd 套件
# yum search vsftpd
 Loaded plugins: fastestmirror, refresh-packagekit, security
 Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * epel: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: centosa5.centos.org
 ============================= N/S Matched: vsftpd ============================
 vsftpd.i686 : Very Secure Ftp Daemon
 Name and summary matches only, use "search all" for everything.

provides查詢檔案位於屬於哪個套件
範例:查詢 sshd_config 屬於哪個套件
# yum provides */sshd_config
 Loaded plugins: fastestmirror, refresh-packagekit, security
 Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * epel: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: centosa5.centos.org
 openssh-server-5.3p1-81.el6.i686 : An open source SSH server daemon
 Repo : base
 Matched from:
 Filename : /etc/ssh/sshd_config

clean:清除 repolist 資料
# yum clean all
 Loaded plugins: fastestmirror, refresh-packagekit, security
 Cleaning repos: base epel extras isu updates
 Cleaning up Everything
 Cleaning up list of fastest mirrors

reinstall:重新安裝
# yum reinstall vsftpd
update/check-update:更新
# yum check-update openssh
erase/remove:移除
# yum remove vsftpd
localinstall:本地套件安裝
# yum localinstall vsftpd
群組安裝相關指令
grouplist
groupinstall
grouperase
groupinfo