顯示具有 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

成功囉!!!!

色碼擷取器 - Gpick安裝教學(失敗版)

官網:https://code.google.com/p/gpick/
可使用 yum 安裝,來源是EPEL,但是版本當然不是最新的。
以下是安裝最新版本的步驟。

下載gpick套件,但是格式為deb檔,因此要轉換成CentOS可以安裝的格式,轉換工具為alien

# mkdir -p /data/src
# wget https://gpick.googlecode.com/files/gpick_0.2.5-1_i386.deb
# wget http://ftp.de.debian.org/debian/pool/main/a/alien/alien_8.90.tar.gz
# tar zxf alien_8.90.tar.gz
# cd alien
# perl Makefile.PL
  Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5
  /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at Makefile.PL line 2.
  BEGIN failed--compilation aborted at Makefile.PL line 2. //缺少 ExtUtils::MakeMaker 模組,透過CPAN安裝即可。
# perl Makefile.PL
# make && make install
# yum install -y rpm-build
# cd ..

# alien -r gpick_0.2.5-1_i386.deb
  Warning: Skipping conversion of scripts in package gpick: postinst postrm
  Warning: Use the --scripts parameter to include the scripts.
  gpick-0.2.5-2.i386.rpm generated

# rpm -ivh gpick-0.2.5-2.i386.rpm
  error: Failed dependencies:
    liblua5.2.so.0 is needed by gpick-0.2.5-2.i386
    libstdc++.so.6(GLIBCXX_3.4.15) is needed by gpick-0.2.5-2.i386
註:deb轉換rpm參考文獻

安裝 liblua5.2.so.0

# wget http://mirrors.kernel.org/ubuntu/pool/main/l/lua5.2/liblua5.2-0_5.2.2-1_i386.deb
# alien -r liblua5.2-0_5.2.2-1_i386.deb
# rpm -ivh liblua5.2-0-5.2.2-2.i386.rpm

查詢 GLIBCXX 版本

# find / -name libstdc++.so.6
  /usr/lib/libstdc++.so.6
# strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
  ...略
  GLIBCXX_3.4.11
  GLIBCXX_3.4.12
  GLIBCXX_3.4.13 <==很明顯沒有我們需要的版本GLIBCXX_3.4.15
  GLIBCXX_FORCE_NEW
  GLIBCXX_DEBUG_MESSAGE_LENGTH

# rpm -qf /usr/lib/libstdc++.so.6 //找尋libstdc++.so.6是哪一個套件提供的(方法2:yum whatprovides libstdc++.so.6)
  libstdc++-4.4.7-4.el6.i686

# rpm -q gcc
  gcc-4.4.7-4.el6.i686 //目前gcc版本

# rpm -q centos-release
  centos-release-6-5.el6.centos.11.1.i686 //目前作業系統版本


安裝 libstdc++.so.6(GLIBCXX_3.4.15)

# wget ftp://ftp.univie.ac.at/systems/linux/fedora/updates/20/x86_64/libstdc++-4.8.2-7.fc20.i686.rpm
# rpm -ivh libstdc++-4.8.2-7.fc20.i686.rpm
# rpm2cpio libstdc++-4.8.2-7.fc20.i686.rpm |cpio -idmv
# pwd
  /root/GLIBC/usr/lib
# ll
  lrwxrwxrwx. 1 root root 19 Mar 24 01:20 libstdc++.so.6 -> libstdc++.so.6.0.19
  -rwxr-xr-x. 1 root root 938796 Dec 12 11:26 libstdc++.so.6.0.19
# rm /usr/lib/libstdc++.so.6
# ln -s /usr/lib/libstdc++.so.6.0.19 /usr/lib/libstdc++.so.6
# strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
  ...略
  GLIBCXX_3.4.14
  GLIBCXX_3.4.15
  GLIBCXX_3.4.16
  GLIBCXX_3.4.17
  GLIBCXX_3.4.18
  GLIBCXX_3.4.19
# rpm -ivh gpick-0.2.5-2.i386.rpm
  error: Failed dependencies: //還是失敗
    libstdc++.so.6(GLIBCXX_3.4.15) is needed by gpick-0.2.5-2.i386

升級GLIBC

# rpm -qi glibc | grep "Version"
  Version : 2.12   Vendor: CentOS
# wget ftp://195.220.108.108/linux/fedora/linux/development/rawhide/i386/os/Packages/g/glibc-common-2.19.90-7.fc21.i686.rpm
# wget ftp://195.220.108.108/linux/fedora/linux/development/rawhide/i386/os/Packages/g/glibc-headers-2.19.90-7.fc21.i686.rpm
# wget ftp://195.220.108.108/linux/fedora/linux/development/rawhide/i386/os/Packages/g/glibc-devel-2.19.90-7.fc21.i686.rpm
# wget ftp://195.220.108.108/linux/fedora/linux/development/rawhide/i386/os/Packages/g/glibc-2.19.90-7.fc21.
i686.rpm
# rpm -Uvh --aid --nodeps glibc-devel-2.19.90-7.fc21.i686.rpm
# rpm -Uvh --aid --nodeps glibc-headers-2.19.90-7.fc21.i686.rpm
# rpm -Uvh --aid --nodeps glibc-2.19.90-7.fc21.i686.rpm
# rpm -Uvh --aid --nodeps glibc-common-2.19.90-7.fc21.i686.rpm
# rpm -qi glibc | grep "Version"
  Version : 2.19.90   Vendor: Fedora Project
# rpm -ivh gpick-0.2.5-2.i386.rpm
  error: Failed dependencies: //還是失敗
    libstdc++.so.6(GLIBCXX_3.4.15) is needed by gpick-0.2.5-2.i386

我想是我目前的功力還不夠解決"libstdc++.so.6(GLIBCXX_3.4.15) is needed by gpick-0.2.5-2.i386"這個問題,以後有時間再來奮戰吧!


問卷系統LimeSurvey-統計圖中文亂碼問題

由LimeSurvey系統產生PDF或HTML格式的統計圖表時,中文會出現亂碼的狀態。
WHY?那是因為缺少了中文字型檔所造成的現象。


到Limesurvey存放字型的目錄下(/limesurvey/fonts),只看到fireflysung - Chinese.ttf.txt文字檔
原來他的內容已經告訴你,要顯示中文字型請下載字型檔並放置到正確路徑下。
For package size reasons the Firefly Sung font to show Chinese characters in the statistics graphs is not included with LimeSurvey.

Please download it from http://sourceforge.jp/projects/sfnet_chinesepuppy/downloads/ChineseSupport/Fonts/fireflysung-1.3.0.tar.gz/ , unzip and put the fireflysung.tff file into the /fonts directory of your LimeSurvey installation.

放置完成後,不管重新整理幾次,圖表中文依然是亂碼,這是為什麼?
  1. config-defaults.php的設定沒有改
  2. # vim /var/www/html/limesurvey/application/config/config-defaults.php
       $config['chartfontfile']='fireflysung.ttf';  //原設定值為auto

  3. 原圖表的暫存檔沒有刪除

  4. # rm -f /var/www/html/limesurvey/tmp/*.png

  5. 再重新產出就會出現漂亮的圖表囉!

問卷系統LimeSurvey-pdf內容空白問題

由LimeSurvey系統產生PDF時,會出現空白的狀態。
因為預設語系為簡體,而輸出文字內容為繁體,而且預設字型大小也只有8px,實在有點太小了。
若有相同問題的朋友請依照以下方式修改。

如何變更字型大小

# grep --color -R "pdffontsize" /var/www/html/limesurvey/
  /var/www/html/limesurvey/application/config/config-defaults.php:$config['pdffontsize'] = 8;
# vim /var/www/html/limesurvey/application/config/config-defaults.php
  $config['pdffontsize'] = 16;

如何變更語系

# vim /var/www/html/application/third_party/tcpdf/fonts/chinese.php
  $enc='UniCNS-UTF16-H';  //原始值為UniGB-UTF16-H
  $cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'CNS1','Supplement'=>0);  //原始值為GB1及2

為何我會知道參數值要修改成什麼呢?
因為我搜尋UniGB-UTF16-H字串時,發現他在cid0cs.php內有以下3行文字:
// Chinese Simplified
$enc='UniGB-UTF16-H';
$cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'GB1,'Supplement'=>2);

而在同一個目錄下還有一個cid0ct.php的檔案,內容也有相似的3行文字:
// Chinese Traditional
$enc='UniCNS-UTF16-H';
$cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'CNS1','Supplement'=>0);

問卷系統LimeSurvey-修改按鈕文字內容及字型大小

使用預設的版面時,右下角會有一個"載入未完成問卷"的按鈕,左下角則是"離開並清除問卷"的按鈕。


***字型的大小預設是10px,而文字字串則是存放在繁體中文語系檔(.mo)內。

一開始我搜尋limesurvey目錄下(包含子目錄)所有的php內容,看看是不是有"載入未完成問卷"的字串,但只找到他的變數"Load unfinished survey",之後再用以下的指令找到了這字串的所在檔案位置。

# grep --color -R "載入未完成" /var/www/html/limesurvey/
  二進位格式檔案 /var/www/html/limesurvey/locale/zh-Hant-TW/LC_MESSAGES/zh-Hant-TW.mo 符合

***所以基本上除了按鈕的文字字串,像是limesurvey其他網頁的文字字串也都是存放內在這個檔案內。

如何編輯繁體中文語系檔

我們可以到limesurvey的官網下載最新的繁體中文語系檔(.po)進行編輯並轉換成繁體中文語系檔(.mo)。
  1. 繁體中文語系檔載點:limesurvey2-zh-tw.po
  2. po檔編輯器載點


  3. 存檔後,在同一個路徑下會產生一個limesurvey2-zh-tw.mo檔。將這個檔案複製到路徑/var/www/html/limesurvey/locale/zh-Hant-TW/LC_MESSAGES/底下,記住要先備份原始檔。
  4. # mv zh-Hant-TW.mo zh-Hant-TW.mo.bak20130807
    # wget http://myftp/limesurvey2-zh-tw.mo
    # mv limesurvey2-zh-tw.mo zh-Hant-TW.mo

  5. 按F5重新整理網頁

如何變更字型大小

# vim /var/www/html/limesurvey/upload/templates/test/template.css  //test模板名稱
  279  /* Save All button */
  280  .saveall {
  281  font-size: 16px;
  282  margin: 5px;
  283  }

問卷系統LimeSurvey

最近同事為了教育部問卷系統要暫時停擺的問題而傷透腦筋,本來建議他向計資中心求助,但得到的回應卻大失所望,所以只好親自出馬,LimeSurvey是功能強大的問卷系統,有Windows和Linux版本。

相關資料來源:
LimeSurvey官網
系統需求
LimeSurvey載點
安裝 FAQ

安裝步驟

  1. 安裝必要套件及相關模組
  2. # yum install -y httpd php mysql mysql-server phpMyAdmin  //phpMyAdmin來源為EPEL,repo檔請至EPEL官網下載安裝。
    # yum install -y php-mbstring php-mysql  // Multibyte String Functions及PDO database driver for MySQL模組
    # service httpd start
    # chkconfig httpd on
    # service httpd restart
    # vim /var/www/html/info.php
      <?php
        phpinfo();
      ?>


  3. 初始化MySQL資料庫
  4. # chkconfig mysqld on
    # service mysqld start
    # mysqladmin -u root password 12345
    # /usr/bin/mysql_secure_installation
      Enter current password for root (enter for none): 12345
      Remove anonymous users? [Y/n] Y
      Disallow root login remotely? [Y/n] n
      Remove test database and access to it? [Y/n] Y
      Reload privilege tables now? [Y/n] Y

    產生一個新的資料庫給LimeSurvey使用,可以用指令,也可以用phpMyAdmin。
    # mysql -u root -p
      Enter password:
    mysqld>CREATE DATABASE cc_survey;
      Query OK, 1 row affected (0.00 sec)
    mysqld>quit

  5. 安裝LimeSurvey
  6. # wget http://www.limesurvey.org/en/stable-release/finish/25-latest-stable-release/900-limesurvey200plus-build130708.tar.gz
    # tar zxvf limesurvey200plus-build130708.tar.gz
    # cp -r limesurvey/* /var/www/html/

    進入設定頁面時發生錯誤,因為無寫入權限

    # chmod -R 777 /var/www/html/tmp



    最低要求並未完全滿足

    # chmod 777 /var/www/html/application/config/
    # chmod -R 777 /var/www/html/upload/


    可選擇性模組還有三個未安裝:既然是可選擇性,也就是說可以不安裝就進行下一步,但還是裝一下吧! # yum list | grep --color -Ew 'php-|gd|ldap|imap'
      php-gd
      php-ldap
      php-imap
    # yum install -y php-gd php-ldap php-imap
    # service httpd restart

    這樣是不是好看多了!

    設定資料庫:欄位(資料庫名稱)就是前面資料庫設定時所新增的cc_survey




    管理端網址:http://you.domainname.com/index.php/admin/authentication/sa/login


Q&A

        當你將某一個問題的"必須回應"設定為否時,該問題在問卷畫面上會自動多出一個"不想回答"的選項,而進入所有的頁面都找不到如何讓他消失的設定,這該如何解決呢?


使用phpMyAdmin去搜尋參數值shownoanswer,並將他改為0,就不會出現了。

ntop

資料來源:軟體開箱文~~ 使用 ntop 好用的圖型化介面監控網路管理資訊

network-top 是統計目前網量流量的軟體(類似 Linux 的 top 指令),如果你的主機是網域的出入口,可以知道網域內的主機瀏覽那些網頁以及使用那些網路協定進行資料傳輸。

安裝 # yum install ntop  // 必須有 epel 安裝來源
設定系統管理者密碼,帳號預設是 admin。 # ntop -A
 Fri Dec 14 09:29:22 2012 Initializing gdbm databases
 Fri Dec 14 09:29:22 2012 Setting administrator password...

 ntop startup - waiting for user response!

 Please enter the password for the admin user:123456  // 至少 5 個字元
 Please enter the password again: 123456
 Fri Dec 14 09:29:53 2012 Admin user password has been set
 Fri Dec 14 09:29:53 2012 Admin password set...

啓動 ntop 服務測試 # /etc/init.d/ntop start
開啟防火牆 # iptables -A INPUT -i eth0 -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -I INPUT -i eth0 -p tdp --dport 80 -m state --state NEW -j ACCEPT
# iptables -I INPUT -i eth0 -p tcp --dport 3000 -m state --state NEW -j ACCEPT
# /etc/init.d/iptables save

要求登入驗證密碼,不然外部只要連上主機的 3000port 就可以查看。
  1. Admin-->Configure-->Protect URLs

  2. 輸入管理者帳密 admin/123456

  3. 新增 Protect URLs


  4. 確認 URLs 清單中有出現 * 的網頁位置。

  5. 網頁存取被拒絕
  6. 不要使用 http://localhost:3000/,使用伺服器的 IP 登入。

    查看 ntop 設定檔內容,ntop 只接受 localhost 監聽 3000port,請註解這行設定後,重啟服務。 # vim /etc/ntop.conf
     # limit ntop to listening on a specific interface and port
     --http-server 127.0.0.1:3000 --https-server 127.0.0.1:3001

    # vim /etc/ntop.conf
     # limit ntop to listening on a specific interface and port
     # --http-server 127.0.0.1:3000 --https-server 127.0.0.1:3001

    # service ntop restart


  7. 統計畫面:功能實在太多,有需要的人請自行摸索!XD

偵測遠端主機網路服務是否有開啟nmap

這裡介紹的是圖形界面的 zenmap,軟體會依照選取偵測的等級,自動調整 nmap 的參數。
套件名稱:nmap-frontend.noarch

安裝 Zenmap # yum install nmap-frontend.noarch
啟動 Zenmap,並查詢中華電信的 DNS 伺服器 168.95.1.1 # zenmap &

ISO映像檔編輯軟體-ISO Master

編輯 ISO 檔這個工作,通常要使用特定的軟體,例如 UltraISO 或 PowerISO,但這些軟體通常有 300MB 的限制,除非你花錢買,才能解除限制。

使用 Linux 作業系統的好處就是很多軟體都是免費的,而且一樣好用。
接下來介紹的 ISO Master 就是一個免費軟體。
  1. 安裝 ISO Master
  2. # yum search iso | grep --color master
     isomaster.x86_64 : An easy to use GUI CD image editor
    # yum install -y isomaster.x86_64

  3. 開啟 ISO Master,並拿 Fedora-17-x86_64-netinst.iso 示範。
  4. # isomaster &

  5. 刪除 /EFI/BOOT/BOOTX64.efi,並產生新的 ISO 檔。


  6. Ctrl + s 儲存成新的 ISO 檔


  7. 儲存中

  8. 完成新的 ISO 檔

解除root執行google Chrome限制

Chrome 載點

在 root 身份安裝完成後,開啟 Chrome browser 會出現以下訊息,google 告訢你,如果一定要以 root 身份開啟 Chrome browser,請加入下的參數 --user-data-dir


參數 --user-data-dir,是要讓你把 Chrome browser 的暫存資料,放在別的資料夾底下,不要放在 root 的家目錄底下,是 google 貼心的小限制。

新增暫存目錄
# mkdir /opt/root
編輯 chrome 圖示屬性


在 %U 之後加上 --user-data-dir=/opt/root


再點選 chrome 圖示,即可正常開啟


安裝Vmware-toos

在 VMware Player5.0 有個好用的小功能 enter unity mode就是能讓虛機中的視窗,離開原本的環境到 Windows 畫面上,就不用再實機和虛機之間切換。

VMware Easy Install 的安裝方式,會一併安裝 VMware-tools,但有時候會失敗。而且在應用程式選單的 Install VMware Tools...】也失效的情況下,只有使用 VMware OSPs 來安裝。

VMware OSPs 介紹
套件來源

使用 YUM 安裝,因為必須設定 repo 檔
# vim /etc/yum.repos.d/vmwaretools.repo
 [vmware]
 name=vmware
 baseurl=http://packages.vmware.com/tools/esx/5.1/rhel6/x86_64/
 enable=1

安裝 VMware Tools
# yum install -y vmware-tools*  // 因為不知道要安裝那些,索性全部安裝

重開機後,『enter unity mode』功能就可以用了。

ganglia分散式監視系統

一套可以監視多台主機資源的軟體,以 Multicast 方式運作(如果路由器擋 Multicast,還可以改成 Unicast)
ganglia所有版本載點

範例:
  • Master(10.10.10.139/Linux)
  • Slave(10.10.10.140/Linux)

Master(10.10.10.139/Linux)

安裝 ganglia
# yum install -y ganglia ganglia-gmetad.x86_64 ganglia-gmond.x86_64 ganglia-web.x86_64
開機時啟動
# chkconfig gmetad on
# chkconfig gmond on

修改 gmond.conf 內容
# vim /etc/ganglia/gmond.conf
 cluster {
 name = "santana"
 owner = "unspecified"
 latlong = "unspecified"
 url = "unspecified"
 }

啟動服務
# service gmond start
# service gmetad start

重啟 Apache
# service httpd restart
使用 Firefox 開啟 ganglia 網頁管理畫頁,但無法存取,因為SELinux阻擋存取。

設定SELinux
# setsebool -P httpd_can_network_connect 1

Slave(10.10.10.140/Linux)

所有安裝及設定步驟與Master相同

遠端遙控-Virtual Network Computing(VNC)

Windows 安裝 UltraVNC
Linux 安裝 TigerVNC

目標:Linux 連線至 Windows


Windows 平台設定
安裝 UltraVNC 後,開啟 UltraVNC Server,常駐程式列會出現應用程式圖示,滑鼠右鍵點選圖示,並選擇 Admin Properties 開啟屬性頁面,在此設定認證密碼為『1』


Linux 平台設定
安裝 TigerVNC
# yum install -y tigerVNC

開啟 vncview
# vncview&