顯示具有 SYS 標籤的文章。 顯示所有文章
顯示具有 SYS 標籤的文章。 顯示所有文章

2018年10月29日 星期一

在 CentOS / RHEL 7 上,安裝 FreedIPA 服務

學習目標:
  • 在 CentOS / RHEL 7 Linux 作業系統上,安裝 FreeIPA 服務!
  • 需要先架設好自有 DNS Server !
安裝設定流程:
  1. 安裝相關必要軟體安裝工作!
    # yum -y upgrade
    # reboot
    
  2. 設定主機名稱:
    # hostnamectl set-hostname dns.example.com
    # echo "192.168.100.120 dns.example.com dns" >> /etc/hosts
    # echo "nameserver 127.0.0.1" > /etc/resolv.conf
    
  3. 安裝 IPA Server 套件軟體!
    # yum install -y ipa-server ipa-server-dns
    
  4. 進行設定 IPA Server 工作!
    # ipa-server-install --setup-dns
    (以下就依實際需要修改!)
    Server host name [dns.example.com]:
    Please confirm the domain name [example.com]:
    Please provide a realm name [EXAMPLE.COM]:
    Directory Manager password:
    Password (confirm):
    IPA admin password: 
    Password (confirm):
    Do you want to configure DNS forwarders? [yes]:
    Do you want to configure these servers as DNS forwarders? [yes]: no
    Enter an IP address for a DNS forwarder, or press Enter to skip:
    Do you want to search for missing reverse zones? [yes]:
    Continue to configure the system with these values? [no]: yes
    ...略...
    (看到以下項目,表示安裝成功!)
    ==============================================================================
    Setup complete
    
    Next steps:
     1. You must make sure these network ports are open:
      TCP Ports:
        * 80, 443: HTTP/HTTPS
        * 389, 636: LDAP/LDAPS
        * 88, 464: kerberos
        * 53: bind
      UDP Ports:
        * 88, 464: kerberos
        * 53: bind
        * 123: ntp
    
     2. You can now obtain a kerberos ticket using the command: 'kinit admin'
        This ticket will allow you to use the IPA tools (e.g., ipa user-add)
        and the web user interface.
    
    Be sure to back up the CA certificates stored in /root/cacert.p12
    These files are required to create replicas. The password for these
    files is the Directory Manager password
    
  5. 進行初始化設定:
    # kinit admin
    Password for admin@EXAMPLE.COM:
    
  6. 進行檢查列表:
    # klist
    Ticket cache: KEYRING:persistent:0:0
    Default principal: admin@EXAMPLE.COM
    
    Valid starting       Expires              Service principal
    2018-10-29T12:25:08  2018-10-30T12:24:57  krbtgt/EXAMPLE.COM@EXAMPLE.COM
    
  7. 更改常用的 shell :
    # ipa config-mod --defaultshell=/bin/bash 
    
  8. 設定防火牆!
    # firewall-cmd --add-service={http,https,freeipa-ldap,freeipa-ldaps,dns,ntp,kerberos} --permanent
    # firewall-cmd --reload
    

參考文獻:
  • https://www.server-world.info/en/note?os=CentOS_7&p=ipa&f=1
  • https://www.howtoing.com/how-to-set-up-centralized-linux-authentication-with-freeipa-on-centos-7

2017年7月15日 星期六

在 CentOS / RHEL7 上架設 OpenHPC 系統

學習目標:
  • 利用 OpenHPC 套件,架設高效能電腦(HPC)!
  • OpenHPC 官方示範架構圖:

  • 共要準備六部主機:SMS 一部,Compute Node 四部,以及一部 Storage Server 提供 iSCSI 或是 NFS 儲存空間!各主機準備兩張網卡!
  • 練習用網路設定參數:compute network 172.16.1.0/24,storage network 10.1.1.0/24

操作流程:
  1. 將各主機安裝 CentOS 7.3 版本的 Linux 作業系統!
    • 需要安裝 EPEL 軟體庫套件!

  2. 預先設定 SMS 主機上相關系統參數:
    # vim /etc/hosts
    172.16.1.1 sms sms.example.com
    172.16.1.11 node1 node1.example.com
    172.16.1.12 node2 node2.example.com
    172.16.1.13 node3 node3.example.com
    172.16.1.14 node4 node4.example.com
    10.1.1.100 storage storage.example.com
    
    # hostnamectl set-hostname sms.example.com
    # setenforce 0
    # systemctl disable firewalld
    # systemctl stop firewalld
    
  3. 在 SMS 主機上,安裝 OpenHPC 上的軟體庫套件:
    # yum install http://build.openhpc.community/OpenHPC:/1.3/CentOS_7/x86_64/ohpc-release-1.3-1.el7.x86_64.rpm
    
  4. 可在 SMS 主機上,安裝 OpenHPC 套件的模版 Scripts,加快其他節點安裝:
    # yum -y install docs-ohpc
    (稍後再談...)
    
  5. 在 SMS 主機上,安裝 OpenHPC 準備需要使用的套件:
    # yum -y install ohpc-base ohpc-warewulf
    
  6. 為了時間同步,在 SMS 主機上須要啟動 ntpd 服務:
    # systemctl enable ntpd.service
    # echo "server time.google.com" >> /etc/ntp.conf
    # systemctl restart ntpd
    
  7. 在 SMS 主機上,安裝資源管理套件:
    # yum -y install pbspro-server-ohpc
    
  8. 在 SMS 主機上,安裝 InfiniBand 支援套件:
    # yum -y groupinstall "InfiniBand Support"
    # yum -y install infinipath-psm
    # systemctl start rdma
    
  9. 在 SMS 主機上,設定其他相關設定檔:
    #vim /etc/warewulf/provision.conf
    network device = enp0s8
    
    # vim /etc/xinetd.d/tftp
    disable = no
    
    # systemctl restart xinetd
    # systemctl enable mariadb
    # systemctl restart mariadb
    # systemctl enable httpd
    # systemctl restart httpd
    
  10. 在 SMS 主機上,建立初始基本系統影像檔(for compute node):
    # export CHROOT=/opt/ohpc/admin/images/centos7.3
    # wwmkchroot centos-7 $CHROOT
    
  11. 在 SMS 主機上,增加 OpenHPC 元件給 client 端使用:
    # yum -y --installroot=$CHROOT install ohpc-base-compute
    # cp -p /etc/resolv.conf $CHROOT/etc/resolv.conf
    # yum -y --installroot=$CHROOT install pbspro-execution-ohpc
    
    # vim $CHROOT/etc/pbs.conf
    PBS_SERVER=sms.example.com
    
    # chroot $CHROOT opt/pbs/libexec/pbs_habitat
    
    # vim $CHROOT/var/spool/pbs/mom_priv/config
    $clienthost sms
    
    # echo "\$usecp *:/home /home" >> $CHROOT/var/spool/pbs/mom_priv/config
    # chroot $CHROOT systemctl enable pbs
    
    # yum -y --installroot=$CHROOT groupinstall "InfiniBand Support"
    # yum -y --installroot=$CHROOT install infinipath-psm
    # chroot $CHROOT systemctl enable rdma
    
    # yum -y --installroot=$CHROOT install ntp
    
    # yum -y --installroot=$CHROOT install kernel
    
    # yum -y --installroot=$CHROOT install lmod-ohpc
    
  12. 在 SMS 主機上,客製化系統設定:
    # wwinit database
    # wwinit ssh_keys
    # cat ~/.ssh/cluster.pub >> $CHROOT/root/.ssh/authorized_keys
    
    # echo "172.16.1.1:/home /home nfs nfsvers=3,rsize=1024,wsize=1024,cto 0 0" >> $CHROOT/etc/fstab
    # echo "172.16.1.1:/opt/ohpc/pub /opt/ohpc/pub nfs nfsvers=3 0 0" >> $CHROOT/etc/fstab
    # echo "/home *(rw,no_subtree_check,fsid=10,no_root_squash)" >> /etc/exports
    # echo "/opt/ohpc/pub *(ro,no_subtree_check,fsid=11)" >> /etc/exports
    # exportfs -a
    # systemctl restart nfs-server
    # systemctl enable nfs-server
    
    # chroot $CHROOT systemctl enable ntpd
    # echo "server 172.16.1.1" >> $CHROOT/etc/ntp.conf
    
  13. 在 SMS 主機上,增加鎖定記憶體限制設定:
    # perl -pi -e 's/# End of file/\* soft memlock unlimited\n$&/s' /etc/security/limits.conf
    # perl -pi -e 's/# End of file/\* hard memlock unlimited\n$&/s' /etc/security/limits.conf
    
    # perl -pi -e 's/# End of file/\* soft memlock unlimited\n$&/s' $CHROOT/etc/security/limits.conf
    # perl -pi -e 's/# End of file/\* hard memlock unlimited\n$&/s' $CHROOT/etc/security/limits.conf
    
  14. 在 SMS 主機上,增加 BeeGFS 檔案系統:
    # wget -P /etc/yum.repos.d https://www.beegfs.io/release/beegfs_6/dists/beegfs-rhel7.repo
    # yum -y install kernel-devel gcc
    # yum -y install beegfs-client beegfs-helperd beegfs-utils
    
    # perl -pi -e "s/^buildArgs=-j8/buildArgs=-j8 BEEGFS_OPENTK_IBVERBS=1/" \
    /etc/beegfs/beegfs-client-autobuild.conf
    
    # /opt/beegfs/sbin/beegfs-setup-client -m sms.example.com
    # systemctl start beegfs-helperd
    # systemctl start beegfs-client (要安裝 kernel-devel 才會正常啟動!另外,也可能需要自行架設 BeeGFS 儲存節點)
    
    # wget -P $CHROOT/etc/yum.repos.d https://www.beegfs.io/release/beegfs_6/dists/beegfs-rhel7.repo
    # perl -pi -e "s/^buildEnabled=true/buildEnabled=false/" $CHROOT/etc/beegfs/beegfs-client-autobuild.conf
    # rm -f $CHROOT/var/lib/beegfs/client/force-auto-build
    # chroot $CHROOT systemctl enable beegfs-helperd beegfs-client
    # cp /etc/beegfs/beegfs-client.conf $CHROOT/etc/beegfs/beegfs-client.conf
    # echo "drivers += beegfs" >> /etc/warewulf/bootstrap.conf
    
參考文獻
  • https://github.com/openhpc/ohpc/releases/download/v1.3.1.GA/Install_guide-CentOS7-Warewulf-PBSPro-1.3.1-x86_64.pdf
  • https://www.beegfs.io/wiki/BasicConfigurationFirstStartup

2017年6月7日 星期三

在 CentOS 7 / RHEL 7上,安裝 LibreNMS 服務

學習目標:
  • 安裝 LibreNMS 套件,以利監控系統狀況!
操作流程:
  1. 安裝 DataBase 相關套件:
    # yum install mariadb-server mariadb
    # systemctl start mariadb
    # firewall-cmd --permanent --add-service=mysql
    # firewall-cmd --reload
    # mysql_secure_installation
    
  2. 建立 DataBase 內容:
    # mysql -uroot -p
    MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> exit;
    
  3. 設定 DataBase 相關參數內容:
    # vim /etc/my.cnf.d/server.cnf
    (只新增必要的..)
    [mysqld]
    innodb_file_per_table=1
    sql-mode=""
    :
    
  4. 設定 DataBase 啟動:
    # systemctl enable mariadb  
    # systemctl restart mariadb
    
  5. 安裝與設定 Apache 與相關套件:
    # yum install epel-release
    # rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
    # yum install php70w php70w-cli php70w-gd php70w-mysql php70w-snmp php70w-pear php70w-curl php70w-common httpd net-snmp mariadb ImageMagick jwhois nmap mtr rrdtool MySQL-python net-snmp-utils cronie php70w-mcrypt fping git
    
    # pear install Net_IPv4-1.3.4
    # pear install Net_IPv6-1.2.2b2
    
  6. 編修 php.ini 時區設定值:
    #vim /etc/php.ini
    date.timezone = "Asia/Taipei"
    
  7. 在系統上新增 LibreNMS 的專屬使用者:
    # useradd librenms -d /opt/librenms -M -r
    # usermod -a -G librenms apache
    
  8. 下載 LibreNMS 套件:
    # cd /opt
    # git clone https://github.com/librenms/librenms.git librenms
    
  9. 設定 Web 站台相關設定:
    #cd /opt/librenms
    #mkdir rrd logs
    #chmod 775 rrd
    # vim /etc/httpd/conf.d/librenms.conf
    <VirtualHost *:80>
      DocumentRoot /opt/librenms/html/
      ServerName  librenms.example.com
      CustomLog /opt/librenms/logs/access_log combined
      ErrorLog /opt/librenms/logs/error_log
      AllowEncodedSlashes NoDecode
      <Directory "/opt/librenms/html/">
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
      </Directory>
    </VirtualHost>
  10. 更動 SELinux 設定:
    # yum install policycoreutils-python
    # semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/logs(/.*)?'
    # semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?'
    # restorecon -RFvv /opt/librenms/logs/
    # setsebool -P httpd_can_sendmail=1
    # setsebool -P httpd_can_network_connect=1
    
  11. 防火牆設定:
    # firewall-cmd --zone=public --add-service=http
    # firewall-cmd --permanent --zone=public --add-service=http
    
  12. 啟動 Apache:
    # systemctl enable httpd
    # systemctl restart httpd
    
  13. 利用 firefox 打開網頁:
    (網址:http://librenms.example.com)
    PS:少裝一些套件時,網頁提醒你要 run ./scripts/composer_wrapper.php install --no-dev 時,請切回文字介面執行提示的指令!

    按下圖中的 Next Stage
  14. 輸入資料庫帳密:

    需要稍等一些時間,讓程式自動建立資料庫內相關表格!

    若無任何錯誤,即可新增使用者!
  15. 使用者新增之後,即可產生設定檔:

  16. 接下來的 config.php 檔案內容,可以手動建立:
    放置目錄 /opt/librenms/

    手動新增檔案後,即可按下 finish !
  17. 接下來即可登入系統:
  18. 登入畫面:

  19. 手動修正 config.php 內容:
    #vim /opt/librenms/config.php
    (加入下列設定...)
    $config['fping'] = "/sbin/fping";
    
  20. 修改 SNMP 設定參數:
    #cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
    #vim /etc/snmp/snmpd.conf
    (把 RANDOMSTRINGGOESHERE 改成你想要的名稱...)
    com2sec readonly  default    public # 原來是 RANDOMSTRINGGOESHERE
    syslocation Taipei, Taiwan # 原來是 Rack, Room, Building, City, Country [GPSX,Y]
    syscontact root@localhost # 原來是 Your Name 
    
  21. LibreNMS 官方很貼心的準備了一支 Shell Scripts 程式,用來偵作業系統平台,可裝可不裝:
    #curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
    #chmod +x /usr/bin/distro
    #systemctl restart snmpd
    #systemctl enable snmpd
    
  22. LibreNMS 官方也很貼心的準備了一個工作排程Shell Scripts 程式:
    #cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
    
  23. LibreNMS 官方也很貼心的準備了一個轉檔的Shell Scripts 程式,用來轉出 logs 目錄下的記錄檔:
    #cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
    
  24. 最後一些小動作:
    #chown -R librenms:librenms /opt/librenms
    #systemctl enable httpd mariadb
    #cd /opt/librenms
    #./validate.php
    
  25. 完成後,記得登入,將 localhost 作為你預設的第一個監控的主機!

    參考文獻:
  • http://docs.librenms.org/Installation/Installation-CentOS-7-Apache/#db-server
  • http://jasontools.blogspot.tw/2017/06/librenms-networkmanager-good.html
  • https://docs.librenms.org/Installation/Installation-CentOS-7-Nginx/

2017年5月25日 星期四

在 CentOS 7 / RHEL 7上,安裝 SNMP 服務

學習目標:
  • 安裝 SNMP 服務,以利系統監控!
操作流程:
  1. 系統安裝相關套件:
    # yum install net-snmp net-snmp-utils
    
  2. 修改設定檔內容:
    # mv /etc/snmp/snmp.conf /etc/snmp/snmp.org
    # vim /etc/snmp/snmp.conf
    com2sec local            localhost       public
    com2sec localnet         192.168.0.0/16  public  (public建議修改為其他的帳號)
    
    group   MyRWGroup v1            local
    group   MyROGroup v1            localnet
    
    group   MyROSystem v1           local
    group   MyROSystem v2c          local
    group   MyROSystem usm          local
    
    group   MyROGroup v1            localnet
    group   MyROGroup v2c           localnet
    group   MyROGroup usm           localnet
    
    group   MyRWGroup v1            local
    group   MyRWGroup v2c           local
    group   MyRWGroup usm           local
    
    view    systemview    included   .1.3.6.1.2.1.1
    view    systemview    included   .1.3.6.1.2.1.25.1.1
    view    all    included   .1 80
    
    access  MyROGroup ""      any       noauth    prefix  all none none
    access  MyRWGroup ""      any       noauth    prefix  all all  all
    
    # 位置及裝置資訊
    sysName monitor_server1  (主機裝置名稱)
    syslocation Taiwan_Taipei_IDC   (所在位置資訊)
    syscontact lubida@hiname.net (聯絡人資訊)
    
  3. 處理一下 SELinux 的限制:
    # chcon --reference=snmpd.org snmpd.conf
    
  4. 開啟防火牆設定:
    # firewall-cmd --permanent --add-port=161/udp
    # firewall-cmd --reload
    
  5. 啟動 SNMP 服務:
    # systemctl start snmpd.service
    # systemctl enable snmpd.service
    # systemctl status snmpd.service
    
  6. 利用指令,查詢一下 snmp 是否有正常輸出資料:
    # netstat -auntp | grep snmp
    # snmpwalk -c public -v 2c 192.168.0.1 
    

參考文獻:
  • http://blog.jangmt.com/2015/09/centos-7-snmpd-centos-7-snmp-install.html
  • http://blog.ilc.edu.tw/blog/index.php?op=printView&articleId=650585&blogId=25793
  • https://www.svennd.be/how-to-install-snmp-service-on-centos-7-2/

2017年5月24日 星期三

在CentOS/RHEL7上,安裝 Netdata 監控程式

學習目標:
  • 安裝 netdata ,以利系統監控!
操作流程:
  1. 系統事先安裝相關套件:
    # yum install epel-release
    # yum install autoconf automake curl gcc git libmnl-devel libuuid-devel lm_sensors make MySQL-python nc pkgconfig python python-psycopg2 PyYAML zlib-devel
    
  2. 利用 git 取得 netdata 套件:
    # cd /opt
    # git clone https://github.com/firehol/netdata.git --depth=1
    
  3. 利用 netdata 套件中的安裝程式,進行軟體編譯與安裝:
    # cd netdata
    # ./netdata-installer.sh
    
  4. 安裝 netdata 套件過程中,可指定安裝目錄:
    按下Enter,就會按照上述設定,進行安裝工作!
  5. 開啟 Kernel 的 KSM 功能:
    # echo 1 >/sys/kernel/mm/ksm/run
    # echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
    
  6. 開啟防火牆設定:
    # firewall-cmd --permanent --add-port=19999/tcp
    # firewall-cmd --reload
    
  7. 打開瀏覽器,輸入IP位置以及 19999 port: http://127.0.0.1:19999
  8. 啟動與關閉 Netdata 服務:
    # systemctl start netdata
    # systemctl stop netdata
    

參考文獻:
  • https://github.com/firehol/netdata/wiki/Installation
  • http://blog.itist.tw/2017/05/real-time-performance-monitoring-with-netdata-on-raspberry-pi.html
  • https://www.digitalocean.com/community/tutorials/how-to-set-up-real-time-performance-monitoring-with-netdata-on-ubuntu-16-04

2016年9月20日 星期二

在 CentOS7/RHEL7 上安裝 Nagios (for Apache)

設定提要:
  • 利用 Nagios 即時監控系統資源運作情形!
  • 利用 Apache 作為 Web 平台!可參考這一篇,安裝 LAMP 平台!
Server 端(監控端)快速設定流程:
  1. 利用 yum 進行 EPEL 套件安裝升級:
    #yum udpate epel-release
    
  2. 安裝 Nagios 與 Plugin 套件:
    #yum install nagios nagios-plugins-* httpd-tools
    
  3. 編寫相關 Nagios 的設定檔:
    # vim /etc/httpd/conf.d/nagios.conf
    (增加下列設定:)
    Require ip 127.0.0.1 192.168.100.0/24
    
  4. 設定 Web 帳密驗證:
    #htpasswd /etc/nagios/passwd nagiosadmin
    
  5. 起動 Nagios :
    #systemctl enable nagios
    #systemctl start nagios
    #systemctl restart httpd
    
  6. 利用 firefox ,連到網頁: http://自己的IP/nagios ,即可看見網頁!
Client 端(被監控端)快速設定流程:
  1. 在 Client 端主機上,利用 yum 進行 EPEL 套件安裝升級:
    #yum udpate epel-release
    
  2. 在 Client 端主機上,安裝 NRPE 與 Plugin 套件:
    #yum install nrpe nagios-plugins-*
    
  3. 在 Client 端主機上,編寫相關 NRPE 的設定檔:
    # vim /etc/nagios/nrpe.cfg
    (增加下列設定:)
    allowed_hosts=127.0.0.1,192.168.100.250
    dont_blame_nrpe=1
    command[check_users]=/usr/lib64/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
    command[check_load]=/usr/lib64/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
    command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
    command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
    
  4. 在 Client 端主機上,起動 NRPE :
    #systemctl enable nrpe
    #systemctl start nrpe
    
  5. 在 Client 端主機上,打開防火牆設定:
    #firewall-cmd --add-port=5666/tcp --permanent
    #firewall-cmd --reload
    
  6. 在 Server 端主機上,安裝 Nagios 的 NRPE Plugin 套件:
    #yum install nagios-plugins-nrpe
    
  7. 在 Server 端主機上,修改 Nagios 相關設定:
    #vim /etc/nagios/objects/commands.cfg
    (在檔尾加入下列設定:)
    define command{
            command_name check_nrpe
            command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
    }
    
  8. 在 Server 端主機上,編寫被監控端的監控設定:
    #vim /etc/nagios/conf.d/node01.cfg
    
    define host{
        use                    linux-server
        host_name              node01
        alias                  node01
        address                192.168.100.1
        }
    define service{
        use                    generic-service
        host_name              node01
        service_description    PING
        check_command          check_ping!100.0,20%!500.0,60%
        }
    
    define service{
        use                    generic-service
        host_name              node01
        service_description    Root Partition
        check_command          check_nrpe!check_disk\!20%\!10%\!/
        }
    
    define service{
        use                    generic-service
        host_name              node01
        service_description    Current Users
        check_command          check_nrpe!check_users\!20\!50
        }
    
    define service{
        use                    generic-service
        host_name              node01
        service_description    Total Processes
        check_command          check_nrpe!check_procs\!250\!400\!RSZDT
        }
    
    define service{
        use                    generic-service
        host_name              node01
        service_description    Current Load
        check_command          check_nrpe!check_load\!5.0,4.0,3.0\!10.0,6.0,4.0
        }
    
  9. 在 Server 端主機上,重新起動 Nagios :
    #systemctl restart nagios
    
參考文獻:
  • https://www.server-world.info/en/note?os=CentOS_7&p=nagios&f=1

在 CentOS7/RHEL7 上安裝 Nagios (for Nginx)

設定提要:
  • 利用 Nagios 即時監控系統資源運作情形!
  • 利用 Nginx 作為 Web 平台
快速設定流程:
  1. 利用 yum 進行相關套件安裝:
    #yum -y httpd-tool gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip spawn-fcgi perl-FCGI fcgi fcgi-devel
    
  2. 設定 Nagios 專用帳號與群組:
    #useradd nagios
    #passwd nagios
    #groupadd nagcmd
    #usermod -a -G nagcmd nagios
    #usermod -a -G nagcmd nginx
    
  3. 下載 Nagios 的最新版本:
    # cd /tmp
    #wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
    #wget https://nagios-plugins.org/download/nagios-plugins-2.1.3.tar.gz
    
  4. 解開 Nagios 壓縮檔:
    #tar zxvf nagios-4.2.1.tar.gz
    #tar zxvf nagios-plugins-2.1.3.tar.gz
    
  5. 編譯 Nagios 原始碼:
    #cd nagios-4.2.1
    #./configure --sysconfdir=/etc/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd
    #make all
    #make install
    #make install-init
    #make install-commandmode
    
  6. 編譯 Nagios-plugins 原始碼:
    #cd ../nagios-plugins-2.1.3
    #./configure --with-nagios-user=nagios --with-nagios-group=nagios
    #make all
    #make install
    
  7. 修改 Nagios 相關設定檔:
    #vim /etc/nagios/nagios.cfg
    (修改下列設定:)
    log_file=/var/log/nagios/nagios.log
    
  8. 配合設定檔,新增目錄及檔案:
    #mkdir /var/log/nagios
    #touch /var/log/nagios/nagios.log
    #chown -R nagios:nagios /var/log/nagios/
    
  9. 新增帳密,鎖住 Nagios 網頁:
    #htpasswd -cb /etc/nagios/htpasswd.users nagiosadmin !AGoodPassword
    
  10. 設定 fcgiwrap:
    #cd /etc/yum.repos.d/
    #wget https://copr.fedorainfracloud.org/coprs/jorti/fcgiwrap/repo/epel-7/jorti-fcgiwrap-epel-7.repo
    #yum install fcgiwrap
    #vim /etc/init.d/fcgiwrap
    (編寫內容如下:)
    #!/usr/bin/perl
    
    use strict;
    use warnings FATAL => qw( all );
    
    use IO::Socket::UNIX;
    
    my $bin_path = '/usr/sbin/fcgiwrap';
    my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
    my $num_children = $ARGV[1] || 1;
    
    close STDIN;
    
    unlink $socket_path;
    my $socket = IO::Socket::UNIX->new(
        Local => $socket_path,
        Listen => 100,
    );
    
    die "Cannot create socket at $socket_path: $!\n" unless $socket;
    
    for (1 .. $num_children) {
        my $pid = fork;
        die "Cannot fork: $!" unless defined $pid;
        next if $pid;
    
        exec $bin_path;
        die "Failed to exec $bin_path: $!\n";
    }
    (存檔後離開)
    # chmod +x /etc/init.d/fcgiwrap 
    #vim /etc/rc.local
    (加入下列該行指令:)
    sudo -u nginx /etc/init.d/fcgiwrap
    
  11. 設定 Nginx 內容:
    #cd /etc/yum.repos.d/
    
    
  12. 起動 Nagios :
    #
    #chmod +x /etc/init.d/nagios
    #chkconfig --add nagios
    #service nagios start
    
參考文獻:
  • http://www.phpini.com/linux/rhel-centos-7-install-nagios
  • https://assets.nagios.com/downloads/nagioscore/docs/Nagios-Core-Installing-On-Centos7.pdf
  • http://unix.rocks/2014/nginx-and-nagios-a-howto/
  • https://copr.fedorainfracloud.org/coprs/jorti/fcgiwrap/
  • https://blog.linuxeye.com/312.html
  • http://idevit.nl/node/93

2016年8月2日 星期二

在 CentOS7 / RHEL7 上使用 Collectd 外掛套件

設定目標:
  • 開啟 Collectd 外掛程式,即時監控多部系統主機資源運作情形!
  • 相關 Collectd 套件安裝方式,請參考這一篇內容
快速設定流程:
  1. 利用 yum 進行相關套件安裝(Server、Client端均需要安裝):
    #yum -y install collectd-netlink
    
  2. 編修 Server 端設定:
    #vim /etc/collectd.conf
    LoadPlugin network
    <Plugin network>
       Listen "192.168.1.63"
       <Listen "192.168.1.63">
          SecurityLevel None
       </Listen>
    </Plugin>
    
  3. 重新啟動 Collectd 服務:(Server)
    #systemctl restart collectd
    
  4. 設定 SELinux:(Server)
    #setsebool -P collectd_tcp_network_connect on
    
  5. 設定防火牆:(Server)
    #firewall-cmd --permanent --add-port=udp/25826
    #firewall-cmd --permanent --add-port=tcp/25826
    #firewall-cmd --reload
    
  6. 編修 Client 端設定:
    vim /etc/collectd.conf
    LoadPlugin network
    <Plugin network>
         Server "192.168.1.63"
         <Server "192.168.1.63">
                SecurityLevel None
         </Server>
    </Plugin>
    
  7. 重新啟動 Collectd 服務:(Client)
    #systemctl restart collectd
    
  8. 設定 SELinux:(Client)
    #setsebool -P collectd_tcp_network_connect on
    
  9. 驗證方式(Server、Client端均可使用):
    #netstat -tunlp | grep collect
    

2016年7月30日 星期六

在 CentOS7/RHEL7 上使用 Collectd 套件

設定目標:
  • 即時監控系統資源運作情形!
快速設定流程:
  1. 利用 yum 進行相關套件安裝:
    #yum -y install collectd.x86_64 collectd-web collectd-rrdtool collectd-notify_email
    
  2. 啟動 Collectd 服務:
    #systemctl enable collectd
    #systemctl start collectd
    
  3. 複製 Collectd 的網頁檔案至網頁目錄:
    #cd /usr/share/nginx/html/
    #git clone https://github.com/pommi/CGP.git
    #mv CGP Collectd
    
  4. 打開 Firefox 查看網頁即可!
    # firefox http://localhost/Collectd
    
    ※注意:本次實作未考慮 SELinux 的影響!
  5. 若考慮 SELinux 的限制,需使用下列指令:
    #setenforce 0
    # grep php-fpm /var/log/audit/audit.log | audit2allow -M mypol
    # semodule -i mypol.pp
    # grep rrdtool /var/log/audit/audit.log | audit2allow -M mypol
    # semodule -i mypol.pp
    #setenforce 1
    
    ※注意:上述步驟需要不停的重試,直到網站運作正常為止!
Plugin套件快速設定流程:
※以收集 Nginx 連線資料為例:
  1. 安裝 Nginx for Collectd 套件:
    #yum -y install collectd-nginx
    
  2. 查詢 nginx 是否有支援 stub_status 模組:
    #nginx -V 2>&1 | sed 's,--,n--,g' | grep stub_status
    
  3. 修改 Collectd 設定檔:
    #vim /etc/collectd.d/nginx.conf
    <LoadPlugin nginx>
          URL "http://192.168.5.104/nginx_status?auto"
          User "nginx"
    #      Password "secret"
    #      CACert "/etc/ssl/ca.crt"
    </plugin>
    
    
  4. 修改 Nginx 設定檔:
    # vim /etc/nginx/conf.d/default.conf
    (追加設定:)
    location /nginx_status {
          stub_status on;
          access_log off;
          allow 192.168.4.0/23;
          deny all;
        }
    
    
  5. 重新啟動相關服務
    #systemctl restart collectd
    #systemctl restart nginx
    
  6. 設定 SELinux:
    #setsebool -P collectd_tcp_network_connect on
    
  7. 打開 firefox 查看結果!

參考文獻:

2016年7月25日 星期一

在 CentOS7/RHEL7 上架設 Piwik

設定目標:
  • 在 Centos 7 上安裝 Piwik 套件,監控 Web 主機網路流量!
    • 請參考這一篇的設定,架設好 Web Server!
    • 請參考這一篇的設定,架設好 Mariadb Server !
快速設定流程:

  1. 上網抓下 piwik 套件:
    #wget https://builds.piwik.org/piwik.zip
    
  2. 解開 piwik 套件:
    #unzip piwik.zip
    
  3. 建立 piwik 快取目錄:
    # mkdir -p /var/www/html/piwik/tmp/cache/tracker/
    # chmod -R 777 /var/www/html/piwik/tmp/
    
  4. 利用 firefox 來進行安裝 piwik 的工作:
    #firefox 127.0.0.1/piwik
    

  5. 開始進行安裝畫面:

  6. 按照網頁上的要求,給予適當的設定:

  7. 輸入 MySQL 資料庫相關設定:

  8. 設定好資料庫相關資料後,會建行表格建立:

  9. 輸入管理者帳密:

  10. 輸入站台相關資料:

  11. Piwik 團隊提醒使用者,為了方便追踪流量,可以把下列程式,放入網頁程式入!如果需要用於大流量的網站,必須要求助 Piwik 團隊,他們會給予更快的程式碼!

  12. 安裝完成:

  13. 登入畫面的介面:

參考文獻:

  1. https://piwik.org/docs/installation/

2016年7月23日 星期六

Linux 系統效能監控

參考文獻:

  1. https://www.nagios.org/projects/
  2. http://www.brendangregg.com/linuxperf.html
  3. http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html
  4. https://en.wikipedia.org/wiki/List_of_performance_analysis_tools
  5. http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html
  6. http://www.drupal001.com/2012/07/system-monitor-collectd/
  7. http://www.tecmint.com/linux-performance-monitoring-with-collectl-tool/

2016年7月4日 星期一

XFS 檔案系統與 LVM

LVM 的使用
  • 查看系統內容:
    #lvs
    #pvs
    #vgs
    

參考資料:
  • http://jamyy.us.to/blog/2015/09/7673.html
  • http://dywang.csie.cyut.edu.tw/dywang/rhel7/node60.html

2016年5月29日 星期日

在 CentOS7/RHEL7 上設定 RAID 磁碟陣列系統

設定目標:
  • 在 Centos 7 上安裝設定 RAID 服務!
快速設定流程:
  1. 利用 yum 安裝
    #yum install 
    

參考文獻:

  1. https://wiki.centos.org/HowTos/SoftwareRAIDonCentOS5

2016年4月5日 星期二

在 CentOS7/RHEL7上,安裝 EPEL 套件

快速設定:
  1. EPEL相關網頁:
    https://fedoraproject.org/wiki/EPEL

  2. 取得 EPEL 的 repo 檔套件:
    #wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    
  3. 安裝 EPEL 的 repo 檔套件:
    #rpm -ivh epel-release-latest-7.noarch.rpm
    

在 CentOS7/RHEL7 上利用 YUM 管理軟體

利用別人的軟體倉儲
  • 快速設定:
    1. 設定軟體倉儲所在位址與相關設定:
      #vim /etc/yum.repos.d/centos7.repo
      [centos]
      name=CentOS7 FTP Site
      baseurl=ftp://ftp.stu.edu.tw/Linux/CentOS/7.2.1511/os/x86_64/
      enabled=1
      gpgcheck=1
      
    2. 測試與更新:
      # yum -y update
      # yum search postgresql
      
  • 設定項目說明:
  • 實作範例:
    1. 設定 OpenStack 雲端套件:
      #vim /etc/yum.repos.d/centos7_openstack.repo
      [OpenStack]
      name=CentOS7 OpenStack Cloud Site
      baseurl=ftp://ftp.stu.edu.tw/Linux/CentOS/7.2.1511/cloud/x86_64/openstack-liberty/
      enabled=1
      gpgcheck=0
      
    2. 安裝 OpenStack packstack 套件:
      # yum install openstack-packstack
      

2016年3月29日 星期二

XFS 檔案系統管理

Quota (磁碟配額) 的使用
  • 安裝 quota 套件:
    #yum -y install quota
    
  • 使用 xfs_quota 指令與格式
    xfs_quota [option] [mount_point]
    
    [option]
    • -x:專家模式
    • -c:配合專家模式,在後面追加下列指令:
      • print:列出目前主機內的檔案系統參數資料
      • df:與系統指令 df 功能相同
      • report:列出 quota 資料,可用參數包含 -ugr (user/group/project) 及 -bi (block/inode)
      • state:顯示目前 quota 資訊
      • limit:限制配額空間,針對 user/group 來限制
          指令格式limit [-ug] b[soft|hard]=N i[soft|hard]=N name
          bsoft/bhard : block 限制值,後面可以加上空間單位
          isoft/ihard : inode 限制值
          name:用戶/群組名稱
      • timer:設定 grace time
          指令格式timer [-ug] [-bir] Ndays
    [mount_point]
    • 檔案系統掛載點
  • 使用範例與測試:
    範例一:
    1. 編輯 /etc/fstab 檔案,加入 quota 功能:
      #vim /etc/fstab
      UUID=XXXX  /webhome  xfs  defaults,usrquota,grpquota  0  0
      
    2. 重新掛載檔案系統:
      #mount -o remount -a
      
    3. 查看所有相關的訊息:
      #xfs_quota -x -c "print"
      #xfs_quota -x -c "df -h" /home
      #xfs_quota -x -c "report -ubih" /home
      #xfs_quota -x -c "state"
      
    4. 編寫設定:
      #xfs_quota -x -c "limit -u bsoft=1024M bhard=1500M user1" /webhome
      #xfs_quota -x -c "timer -u -b 30days" /webhome
      
    5. 測試:
      #su - user1
      $dd if=/dev/zero of=/webhome/123.img bs=1M count=1300
      $ls -al /webhome/123.img
      $exit
      #xfs_quota -x -c "report -ubh" /webhome
      

2015年12月17日 星期四

RHEL7 防火牆設定

firewalld 服務概觀
  • RHEL7 預設使用 firewalld 服務管理主機層級的防火牆服務

  • firewalld 管理核心的 netfilter 功能,下轄三個指令與服務:
    • iptables
    • ip6tables
    • ebtables

    ※PS:以上三種服務會互相干擾,須要使用 systemctl mask 指令來隔開!

  • firewalld 區分所有的流量進到 zone (區域)裡面,而每個 zone 裡面,均有不同的 rule (規則)!

  • firewalld 區分進來的封包該進到哪一個 zone,其運作邏輯如下列順序:
    1. 若進來的封包,其來源位址符合某一 zone 內的某一針對來源位址所設定的規則,則該封包將被繞送經過該 zone !
    2. 若接受封包進來的介面符合某一 zone 內所設定的過濾器,則使用該 zone 進行封包過濾!
    3. 其他狀況,使用 Default Zone !! 通常 Default Zone 名為 public ,但管理者可指定其他的 zone 為 Default Zone!

  • firewalld 預設的 zone:
    名稱 預設內容
    trusted 允許所有進入的流量
    home 退回進入的流量!除了與出去的流量相關封包,或是 ssh, mdns, ipp-client, samba-client, 或者 dhcpv6-client 等預設的服務!
    internal 退回進入的流量!除了與出去的流量相關封包,或是 ssh, mdns, ipp-client, samba-client, 或者 dhcpv6-client 等預設的服務!(預設值與home相同!)
    work 退回進入的流量!除了與出去的流量相關封包,或是 ssh, ipp-client, 或者 dhcpv6-client 等預設的服務!
    public 退回進入的流量!除了與出去的流量相關封包,或是 ssh, 或者 dhcpv6-client 等預設的服務!為所有新增網路卡介面的 Default Zone!
    external 退回進入的流量!除了與出去的流量相關封包,或是 ssh 等預設的服務!要出去的 IPv4 流量封包被轉到這裡,將會進行 IP 來源位置的偽裝!
    dmz 退回進入的流量!除了與出去的流量相關封包,或是 ssh 等預設的服務!
    block 退回所有進入的流量!除了與出去的流量相關封包!
    drop 排除所有進入的流量!除了與出去的流量相關封包!

管理 firewalld 服務
  • 管理 firewalld 有下列三種方式:
    1. 使用 firewall-cmd 文字指令!
    2. 使用 firewall-config 圖形介面!
    3. 使用 /etc/firewalld/ 目錄下的檔案!

  • 當 firewalld 套件被安裝好之後, firewall-cmd 即已經存在!

  • 參數使用須知:
    • 使用的參數中,如未指定 --permanent,則預設會是 runtime 狀態!如未指定 zone 名稱,則所有規則,將用在 public zone 上!
    • 如果使用 --permanent 參數後,要立即生效,則必須下 firewall-cmd --reload 指令,重新導入規則內容!
    • 如果只是暫時使用的規則,可以設定 --timeout= 參數!時間到,自動移除!

  • 常用參數列表:
    參數名稱 內容說明
    --get-default-zone
    --set-default-zone=
    --get-zones 列出所有的 zone !!
    --get-services 列出所有預設的服務!
    --get-active-zones 列出所有正在使用中的 zone ,連同介面以及來源資訊!
    --add-source= [--zone=] 繞送由該 IP address 或 network/netmask 進來的封包,進入指定的 zone !!
    --remove-source= [--zone=] 移除由上項新增的規則!
    --add-interface= [--zone=] 繞送由該介面進來的封包,進入指定的 zone !!
    --change-interface= [--zone=] 將上項新增的規則,更換指定的 zone !!
    --list-all [--zone=] 列出某一 zone 內所有的介面、來源設定、服務設定以及 ports 的設定!
    --list-all-zones 列出所有 zone 內所有的介面、來源設定、服務設定以及 ports 的設定!
    --add-service= [--zone=] 允許流量進入該服務
    --remove-service= [--zone=] 移除由上項新增的規則!
    --add-port= [--zone=] 允許流量進入該埠!協定可以是 tcp、udp、icmp 等等
    --remove-port= [--zone=] 移除由上項新增的規則!

  • 範例:
    • # firewall-cmd --set-default-zone=dmz
    • # firewall-cmd --permanent --zone=internal --add-source=192.168.0.0/24
    • # firewall-cmd --permanent --zone=internal --add-service=mysql
    • # firewall-cmd --reload

  • firewalld 設定目錄:
    • /etc/firewalld
    • /usr/lib/firewalld
    • 若兩目錄內有相同檔案名稱,將只使用 /etc/firewalld 目錄內的檔案!

使用 firewalld 客製化規則

  • 管理員還有其他兩項方式,可以滿足管理防火牆的需求:direct rules 以及 rich rules !!

  • Direct Rules
    • 允許管理員直接手動寫 {ip,ip6,eb}tables 規則到 firewalld 所管理的防火牆內容中!
    • 但當強力的規則無法出現在規則列表中,這些規則將很難管理!
    • Direct Rules 的使用彈性比起標準的規則或是 Rich Rules,都是比較差的!
    • Direct Rules 只要不是嵌入在 zone 內,就會在 firewalld 規則之前被導入引用!
    • 範例:
      # firewall-cmd --direct --permanent --add-chain ipv4 raw blacklist
      # firewall-cmd --direct --permanent --add-rule ipv4 raw PREROUTING 0 -s 192.168.1.0/24 -j blacklist
      # firewall-cmd --direct --permanent --add-rule ipv4 raw blacklist 0 -m limit --limit 1/min -j LOG --log-prefix "blacklisted "
      # firewall-cmd --direct --permanent --add-rule ipv4 raw blacklist 1 -j DROP

  • Rich Rules
    • Rich Rules 給予管理員一種撰寫防火牆規則的方式!而該方式是無法用基本防火牆的語法來達成。
    • 語法上,不僅可以使用基本的允許/拒絕功能,還可以使用記錄、製作port 轉向、IP 偽裝、或是速率上的限制!
    • 基本語法:
      rule
        [source] 
        [destination]
        service|port|protocol|icmp-block|masquerade|forward-port
        [log]
        [audit]
        [accept|reject|drop]

    • 設定格式:rule option=value
      • family=ipv4 | ipv6
      • source | destination address=<CIDR>
      • service name=http | ftp ...| <SERVICE_NAME>
      • port port=<PORT NUMBER>
      • protocol=tcp | udp |...

    • 規則判斷順序:每個 zone 內的判斷順序均相同!
      1. 為該 zone 所設定的任何 port 轉換與偽裝規則!
      2. 針對該 zone 所設定的記錄規則!
      3. 為該 zone 所設定的允許規則!
      4. 為該 zone 所設定的拒絕規則!
    • 如果有封包不符合任何 zone 內的任何規則,將該封包將會被拒絕!
    • Rich Rules 配合 firewall-cmd 指令的常用參數:
      參數名稱 內容說明
      --add-rich-rule='<RULE>' 新增<RULE>到指定的 zone 內!
      --remove-rich-rule='<RULE>' 移除指定 zone 內的<RULE>!
      --query-rich-rule='<RULE>' 查詢指定 zone 內的<RULE>!
      --list-rich-rule='<RULE>' 列出指定 zone 內的所有<RULE>!

    • 範例:
      # firewall-cmd --permanent --zone=classroom --add-rich-rule='rule family=ipv4 source address=192.168.1.111/32 reject'
      # firewall-cmd --add-rich-rule='rule service name=ftp limit value=2/m accept'
      # firewall-cmd --permanent --add-rich-rule='rule protocol value=esp drop'
      # firewall-cmd --permanent --zone=vnc --add-rich-rule='rule family=ipv4 source address=192.168.1.0/24 port port=7900-7905 protocol=tcp accept

  • Rich Rule 的使用記錄
    • 使用 syslogd :
      # log [prefix="<PREFIX TEXT>"] [level=<LOGLEVEL>] [limit value="<RATE/DURATION>"]

    • 使用 auditd :

    • 可以做限制,避免檔案空間被塞滿!



使用 firewalld 網路 NAT 功能

  • 練習:把 4321 port 轉到 80 port (只針對 192.168.1.0/24 網段)
    # firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=192.168.1.0/24 forward-port port=4321 protocol=tcp to-port=80'

管理 SELinux Port 標籤

2015年11月12日 星期四

目錄特殊權限設定(1)

SetGID ::

1. # mkdir /opt/test1
2. # chmod 2770 /opt/test1
3. # chgrp  engineers  /opt/test1

NTP 網路校時

CentOS7/RHEL7

  1. # yum install -y chrony
  2. # vim /etc/chrony.conf
  3.         server  1.1.1.1  iburst
  4. # systemctl enable chronyd.service
  5. # systemctl start chronyd
  6. # chronyc sourcestats

可參考資料:http://technote.aven-network.com/821/using-chrony-adjust-clock

2015年11月10日 星期二

BTRFS 介紹

https://www.ibm.com/developerworks/cn/linux/l-cn-btrfs/