2016年5月22日 星期日

在 CentOS7/RHEL7 上架設 PostgreSQL Server

快速設定流程:
  1. 安裝 PostgreSQL Server 套件:
    #yum install postgresql postgresql-server postgresql-contrib
    
  2. 初始化 PostgreSQL Database:
    #postgresql-setup initdb
    
  3. 修改認證設定檔:
    #vim /var/lib/pgsql/data/pg_hba.conf
    (將下列設定改成 md5 驗證方式)
    host    all             all             127.0.0.1/32            md5
    host    all             all             ::1/128                 md5
    
  4. 啟動 PostgreSQL Server:
    #systemctl start postgresql
    #systemctl enable postgresql
    
  5. 開啟防火牆設定:
    #firewall-cmd --permanent --add-service=postgresql
    #firewall-cmd --reload
    
※補充操作:
  1. 切換至 postgres 使用者:
    #su - postgres
    
  2. 執行 PostgresSQL Shell:
    $psql
    
  3. 設定 postgres 使用者密碼:
    postgres=# \password postgres 
    
  4. 離開 PostgresSQL Shell:
    postgres=# \q
    

參考文獻:

  1. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-centos-7
  2. http://www.liquidweb.com/kb/how-to-install-and-connect-to-postgresql-on-centos-7/
  3. http://blog.xuite.net/towns/hc/323035660-PostgreSQL+%E5%AE%89%E8%A3%9D%E3%80%81%E8%A8%AD%E5%AE%9A%E8%88%87%E7%AE%A1%E7%90%86

在 CentOS7/RHEL7 上架設 DHCP Server

快速設定流程:
  1. 安裝 DHCP 套件:
    #yum install dhcp
    
  2. 複製範例設定檔:
    #cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
    
  3. 編輯設定檔:
    #vim /etc/dhcp/dhcpd.conf
    [...省略...]
    ### 設定子網段與 IP 位置配發範圍 ###
     subnet 192.168.5.0 netmask 255.255.255.0 {
     range 192.168.5.100 192.168.5.200;
    
    ### 指定 DNS IP 位置 ### 
     option domain-name-servers 168.95.1.1, 8.8.8.8;
    
    ### 指定網域名稱 ###
     option domain-name "example.com";
    
    ### 指定預設閘道與相關的路由協定 ###
     option routers 192.168.5.254;
     option broadcast-address 192.168.5.255;
    
    ### 指定租約更新時間 ###
     default-lease-time 600;
     max-lease-time 7200;
    }
    
    ### 指定特定主機的 IP 位置,避免該 IP 位置被配發出去 ###
    host mailserver {
     hardware ethernet 00:0C:29:05:A7:CB; 
     fixed-address 192.168.5.110; 
    } 
    
    [...省略...]
    
  4. 啟動 DHCP Server:
    #systemctl restart dhcpd
    #systemctl enable dhcpd
    
  5. 開啟防火牆設定:
    #firewall-cmd --permanent --add-service=dhcp
    #firewall-cmd --reload
    

參考文獻:

  1. http://www.server-world.info/en/note?os=CentOS_7&p=dhcp
  2. http://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/install-and-configure-dhcp-server-on-centos-7-ubuntu-14-04.html

在 CentOS7/RHEL7 上架設 OpenVPN Server

Server端快速設定流程:
  1. 安裝 EPEL 套件:
    #yum install epel-release
    
  2. 安裝 OpenVPN 以及快速加密套件:
    #yum install -y openvpn easy-rsa
    
  3. 利用 OpenVPN 範例檔,加快設定速度:
    #cp /usr/share/doc/openvpn-*/sample/sample-config-files/server.conf /etc/openvpn
    
  4. 開啟 /etc/openvpn/server.conf, 修改以下設定::
    #vim /etc/openvpn/server.conf
    ### 修改 "dh" 設定:
    dh dh2048.pem
    
    ### 找到 "redirect-gateway def1 bypass-dhcp" 並將它解註解:
    push "redirect-gateway def1 bypass-dhcp"
    
    ### 修改 DNS 伺服器設定:
    push "dhcp-option DNS 8.8.8.8"
    push "dhcp-option DNS 8.8.4.4"
    
    ### 修改 "user" 及 "group" 設定:
    user nobody
    group nobody
    
    ### 註解 tls 認證功能 #### 
    #tls-auth ta.key 0 
    
    ### 開啟標頭壓縮功能 ####
    comp-lzo
    
  5. 建立 Easy RSA 設定檔目錄、及建立相關設定檔:
    # mkdir -p /etc/openvpn/easy-rsa/keys
    # cp -rf /usr/share/easy-rsa/2.0/* /etc/openvpn/easy-rsa
    # cp /etc/openvpn/easy-rsa/openssl-1.0.0.cnf /etc/openvpn/easy-rsa/openssl.cnf
    
  6. 修改 /etc/openvpn/easy-rsa/vars 設定值:
    #vim /etc/openvpn/easy-rsa/vars
    export KEY_COUNTRY=TW
    export KEY_PROVINCE=Taiwan
    export KEY_CITY=Kaohsiung
    export KEY_ORG="Happy Heaven"
    export KEY_EMAIL="test@gmail.com"
    export KEY_CN=""
    export KEY_NAME=""
    
  7. 用 Easy RSA 產生金鑰:
    # cd /etc/openvpn/easy-rsa
    # source ./vars
    # ./clean-all
    # ./build-ca
    # ./build-key-server server
    # ./build-dh
    
  8. 將金鑰複製到 OpenVPN 目錄:
    #cd /etc/openvpn/easy-rsa/keys
    #cp dh2048.pem ca.crt server.crt server.key /etc/openvpn
    
  9. 在 OpenVPN Server 產生 Client 端的認證金鑰:
    # cd /etc/openvpn/easy-rsa
    # ./build-key client
    
  10. 設定防火牆:
    #firewall-cmd --permanent --add-service=openvpn
    #firewall-cmd --permanent --add-masquerade
    #firewall-cmd --reload
    
  11. 編修 /etc/sysctl.conf:
    #vim /etc/sysctl.conf
    net.ipv4.ip_forward = 1
    
  12. 重新導入 /etc/sysctl.conf:
    # sysctl -p
    
  13. 啟動 OpenVPN:
    #systemctl restart NetworkManager
    #systemctl -f enable openvpn@server
    #systemctl start openvpn@server
    

※補充建議:
  1. 請事先安裝好 HTTP Server,並且啟動!
  2. 複製下列三個檔案到 /var/www/html/keys 目錄下:
    #mkdir /var/www/html/keys
    #cp /etc/openvpn/easy-rsa/keys/ca.crt /etc/openvpn/easy-rsa/keys/client.crt /etc/openvpn/easy-rsa/keys/client.key /var/www/html/keys
    
  3. 編修 client.ovpn 檔案:
    #vim /var/www/html/keys/client.ovpn
    client
    dev tun
    proto udp
    remote your_server_ip 1194
    resolv-retry infinite
    nobind
    persist-key
    persist-tun
    comp-lzo
    verb 3
    ca /opt/keys/ca.crt
    cert /opt/keys/client.crt
    key /opt/keys/client.key
    
  4. 修正檔案權限設定:
    #cd /var/www/html/keys
    #chown apache.apache *
    #restoreconf -R /var/www/html
    

Client 端快速設定流程:
傋註:以 Linux 作業系統為例!
  1. 下載 Server 端上的四個檔案:
    #mkdir /opt/keys
    #cd /opt/keys
    #wget http://192.168.5.244/keys/client.crt
    #wget http://192.168.5.244/keys/ca.crt
    #wget http://192.168.5.244/keys/client.key
    #wget http://192.168.5.244/keys/client.ovpn
    ##restoreconf -R /opt/keys
    
  2. 安裝 OpenVPN :
    #yum install -y openvpn
    
  3. 連線 OpenVPN :
    #openvpn –config /path/to/client.ovpn
    
  4. 補充說明 client.ovpn 放入 key 值的設定 :
    #vim client.ovpn
    在檔案最下方,刪去 ca、cert、key 三行設定!
    接下來,加入下列設定....
    <ca>
    (把 ca.crt 檔案內容完整複製過來...)
    </ca>
    <key>
    (把 client.key 檔案內容完整複製過來...)
    </key>
    <cert>
    (把 client.crt 檔案內容完整複製過來...)
    </cert>

參考文獻:

  1. http://www.phpini.com/linux/centos-7-install-openvpn-server
  2. http://www.tecmint.com/setup-openvpn-server-with-linux-and-windows-clients-in-centos-rhel/
  3. http://dreamtails.pixnet.net/blog/post/30797812-centos-7-install-openvpn

2016年5月18日 星期三

在 CentOS7/RHEL7 上設定 iSCSI (二)

Target 快速設定流程:
  1. 安裝相關套件:
    #yum install iscsi-initiator-utils
    
  2. 編輯 Initiator 名稱:
    #vim /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.2016-05.com.example:server2
    
  3. 啟動 Initiator 服務:
    #systemctl enable iscsi
    #systemctl restart iscsi
    
  4. 利用 iscsiadm 登入 iSCSI :
    #iscsiadm -m discovery -t st -p 192.168.5.244
    #iscsiadm -m node -T iqn.2016-05.com.example:server1.disk01 -p 192.168.5.244 -l
    
  5. 掛載 iSCSI 分出來的硬碟空間:
    #lsblk
    #tail /var/log/messages
    #fdisk /dev/sdb
    #mkfs -t ext4 /dev/sdb1
    #blkid /dev/sdb1
    #vim /etc/fstab
      UUID=xxxx   /mnt/data  ext4 _netdev 0 0
    
  6. 利用 iscsiadm 登出 iSCSI :
    #iscsiadm -m node -T iqn.2016-05.com.example:server1.disk01 -p 192.168.5.244 -u
    

2016年5月17日 星期二

在 CentOS7/RHEL7 上設定 iSCSI (一)

Target 快速設定流程:
  1. 安裝相關套件:
    #yum -y install targetcli
    
  2. 打開防火牆設定:
    #firewall-cmd --permanent --add-port=3260/tcp
    #firewall-cmd --reload
    
  3. 啟動 iSCSI Target 服務:
    #systemctl enable target
    #systemctl start target
    
  4. 建立資料夾內影像檔,提供本次設定:
    #mkdir /iscsi_disks
    #dd if=/dev/zero of=/iscsi_disks/disk01.img bs=1M count=1024
    
  5. 使用專屬管理 console 介面:
    # targetcli
    
  6. 建立一個檔案名稱,連結影像檔:
    /> cd backstores/fileio
    /backstores/fileio> create server1.disk01 /iscsi_disks/disk01.img
    
  7. 建立 iSCSI target 名稱:
    /backstores/fileio> cd /iscsi
    /iscsi> create iqn.2016-05.com.example:server1.disk01
    
  8. 建立 ACL 名稱:
    /iscsi> cd iqn.2016-05.com.example:server1.disk01/tpg1/acls/
    /iscsiiqn.2016-05.com.example:server1.disk01/tpg1/acls/> create iqn.2016-05.com.example:server2
  9. 連結 LUN:
    /iscsiiqn.2016-05.com.example:server1.disk01/tpg1/acls/> cd iqn.2016-05.com.example:server1.disk01/tpg1/luns/
    /iscsiiqn.2016-05.com.example:server1.disk01/tpg1/luns/> create /backstores/fileio/server1.disk01
  10. 建立 portal:
    /iscsiiqn.2016-05.com.example:server1.disk01/tpg1/acls/> cd iqn.2016-05.com.example:server1.disk01/tpg1/portals/
    /iscsiiqn.2016-05.com.example:server1.disk01/tpg1/portals/> create 192.168.5.243
    
  11. 存檔、離開:
    /iscsiiqn.2016-05.com.example:server1.disk01/tpg1/acls/> cd / 
    /> saveconfig
    /> exit
    

在 CentOS7/RHEL7 上安裝設定 Power DNS(一)

  • 事先準備事項:
    • MariaDB 服務設定,請參考這一篇的設定!
    • Httpd 服務設定,請參考這一篇的設定!
    • EPEL 服務設定,請參考這一篇的設定!
快速設定流程:
  1. 安裝相關套件:
    #yum -y install pdns pdns-backend-mysql
    
  2. 設定 MariaDB 內容:
    # mysql -u root -p
    MariaDB [(none)]> CREATE DATABASE powerdns;
    MariaDB [(none)]> GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY 'powerdns123';
    MariaDB [(none)]> FLUSH PRIVILEGES;
    
    MariaDB [(none)]> USE powerdns;
    MariaDB [powerdns]> CREATE TABLE domains (
                     -> id INT auto_increment,
                     -> name VARCHAR(255) NOT NULL,
                     -> master VARCHAR(128) DEFAULT NULL,
                     -> last_check INT DEFAULT NULL,
                     -> type VARCHAR(6) NOT NULL,
                     -> notified_serial INT DEFAULT NULL,
                     -> account VARCHAR(40) DEFAULT NULL,
                     -> primary key (id)
                     -> )ENGINE = INNODB, CHARSET=utf8;
    MariaDB [powerdns]> CREATE UNIQUE INDEX name_index ON domains(name);
    
    MariaDB [powerdns]> CREATE TABLE records (
                     -> id INT auto_increment,
                     -> domain_id INT DEFAULT NULL,
                     -> name VARCHAR(255) DEFAULT NULL,
                     -> type VARCHAR(6) DEFAULT NULL,
                     -> content VARCHAR(255) DEFAULT NULL,
                     -> ttl INT DEFAULT NULL,
                     -> prio INT DEFAULT NULL,
                     -> change_date INT DEFAULT NULL,
                     -> disabled TINYINT(1) DEFAULT 0,
                     -> ordername VARCHAR(255) BINARY DEFAULT NULL,
                     -> auth TINYINT(1) DEFAULT 1,
                     -> primary key(id)
                     -> )ENGINE = INNODB, CHARSET=utf8;
    MariaDB [powerdns]> CREATE INDEX rec_name_index ON records(name);
    MariaDB [powerdns]> CREATE INDEX nametype_index ON records(name,type);
    MariaDB [powerdns]> CREATE INDEX domain_id ON records(domain_id);
    
    MariaDB [powerdns]> CREATE TABLE supermasters (
                     -> ip VARCHAR(25) NOT NULL,
                     -> nameserver VARCHAR(255) NOT NULL,
                     -> account VARCHAR(40) DEFAULT NULL
                     -> )ENGINE = INNODB, CHARSET=utf8;
    
    MariaDB [powerdns]> quit;
    
  3. 編修相關設定檔內容:
    #vim /etc/pdns/pdns.conf
    launch=gmysql
    gmysql-host=localhost
    gmysql-user=powerdns
    gmysql-password=user-pass
    gmysql-dbname=powerdns
    
  4. 開啟防火牆設定:
    #firewall-cmd --permanent --add-service=dns
    #firewall-cmd --permanent --add-service=mysql
    #firewall-cmd --reload
    
  5. 啟動服務:
    # systemctl enable pdns.service 
    # systemctl start pdns.service 
    
  6. 安裝 poweradmin 套件:
    # cd /var/www/html/
    # wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz 
    # tar xfv poweradmin-2.1.7.tgz
    # mv poweradmin-2.1.7 pdns
    
  7. 設定 SELinux 設定:
    #restorecon -R /var/www/html/
    
  8. 開啟設定網頁:
    #firefox http://localhost/pdns/install/
    

在 CentOS7/RHEL7 上安裝設定 LDAP Server(二)

進階設定目標:
  • 將公鑰遞給客戶端,用以建立 TLS 連線方式,使用 LDAP Server!
進階設定流程:
  1. 切換目錄至 /etc/openldap/certs/:
    #cd /etc/openldap/certs/
    
  2. 複製公鑰至公開目錄,方便客戶端取得:
    #cp cert.pem /var/www/html/example-ca.crt
    
  3. 小心 SELinux 問題:
    #restorecon -R /var/www/html
    
  4. 重新啟動 Apache 服務:
    #systemctl restart httpd
    

客戶端設定:
    圖形介面安裝設定:
  1. 首先安裝認證設定圖形介面套件:
    #yum -y install authconfig-gtk
    
  2. 在 Gnome 圖形介面下,打開認證設定軟體:
    #authconfig-gtk &