搜尋此網誌

2015年12月9日 星期三

redmine 3.1.0 BASH Syntax Highlighting


Install:


[root@redmine redmine]# cd vendor/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/scanners

[root@redmine scanners]# wget https://raw.githubusercontent.com/pejuko/coderay_bash/master/lib/coderay/scanners/bash.rb

[root@redmine scanners]# systemctl reload httpd.service



Usage:

<pre><code class="bash">
          if [ "$TMP_MONTH" -le 0 ]; then
        THRESHOLD_YEAR=`echo $(( $CURRENT_YEAR - 1 ))`
        THRESHOLD_MONTH=`echo $(( 12 + TMP_MONTH ))`
else
        THRESHOLD_YEAR=$CURRENT_YEAR
        THRESHOLD_MONTH=$TMP_MONTH
fi
return 0;
}
</code></pre>

Optional:


[root@redmine redmine]# vim vendor/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/helpers/file_type.rb

# near line 79 add
    TypeFromExt = {
      'bash'   => :bash,
      'c'         => :c,
      'cfc'      => :xml,
      'cfm'     => :xml,
      'clj'       => :clojure,
      'css'      => :css,
      'diff'     => :diff,
      'dpr'      => :delphi,
      ...............

[root@redmine redmine]# systemctl restart httpd.service



2015年9月4日 星期五

CentOS7 安裝Opentack - Keystone

環境準備

目前Openstack最新版本為KILO,先安裝KILO的Repository:


安裝Mariadb :
[root@keystone ~]# yum install mariadb mariadb-server MySQL-python -y


修改my.cnf :
[root@keystone ~]# vim /etc/my.cnf
[mysqld]
...
# near line 10 add
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8


啟動MariaDB並初始化設定:
[root@keystone ~]# systemctl enable mariadb.service
[root@keystone ~]# systemctl start mariadb.service
[root@keystone ~]# mysql_secure_installation


建立keystone資料庫,並新增一個keystone的使用者 :
[root@keystone ~]# mysql -u root -p 
MariaDB [(none)]> CREATE DATABASE keystone;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'YOURPASSWORD';


安裝Keystone


安裝套件 :
[root@keystone ~]# yum install openstack-keystone httpd mod_wsgi python-openstackclient memcached python-memcached  -y


新版的安裝建議使用apache的wsgi模組啟動keystone,因此安裝httpd與mod_wsgi這兩個套件。



設定keystone.conf :
[root@keystone ~]# vim /etc/keystone/keystone.conf

#line 12 uncomment 
admin_token = YOURTOKEN

# line 419 uncomment
connection = mysql://keystone:YOURPASSWORD@localhost/keystone

# line 1126 uncomment
servers = localhost:11211

# line 1496 uncomment
driver = keystone.contrib.revoke.backends.sql.Revoke

# line 1685 uncomment
provider = keystone.token.providers.uuid.Provider

# line 1688 uncomment
driver = keystone.token.persistence.backends.memcache.Token


啟動memcached :
[root@keystone ~]# systemctl enable memcached.service 
[root@keystone ~]# systemctl start memcached.service 


初始化Keystone 資料庫 :
[root@keystone ~]# su -s /bin/sh -c "keystone-manage db_sync" keystone 



設定apache mod_wsgi


新增一個wsgi的apache設定檔 :
[root@keystone ~]# vim  /etc/httpd/conf.d/wsgi-keystone.conf

# add following
Listen 5000
Listen 35357
<VirtualHost *:5000>
 WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
 WSGIProcessGroup keystone-public
 WSGIScriptAlias / /var/www/cgi-bin/keystone/main
 WSGIApplicationGroup %{GLOBAL}
 WSGIPassAuthorization On
 LogLevel info
 ErrorLogFormat "%{cu}t %M"
 ErrorLog /var/log/httpd/keystone-error.log
 CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>
<VirtualHost *:35357>
 WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
 WSGIProcessGroup keystone-admin
 WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
 WSGIApplicationGroup %{GLOBAL}
 WSGIPassAuthorization On
 LogLevel info
 ErrorLogFormat "%{cu}t %M"
 ErrorLog /var/log/httpd/keystone-error.log
 CustomLog /var/log/httpd/keystone-access.log combined

</VirtualHost>


建立執行的資料夾,並下載執行檔 :
[root@keystone ~]# mkdir -p /var/www/cgi-bin/keystone
[root@keystone ~]# curl http://git.openstack.org/cgit/openstack/keystone/plain/httpd/keystone.py?h=stable/kilo | tee /var/www/cgi-bin/keystone/main /var/www/cgi-bin/keystone/admin


修改權限並啟動apache :
[root@keystone ~]# chown -R keystone:keystone /var/www/cgi-bin/keystone
[root@keystone ~]# chmod 755 /var/www/cgi-bin/keystone/*

[root@keystone ~]# systemctl enable httpd.service
[root@keystone ~]# systemctl start httpd.service


到目前為止我們已經將Keystone的服務設定完畢,接下來我們將新增一個admin的使用者。


新增admin使用者


載入keystone的管理token :

[root@keystone ~]# vim ~/.keystone-admin-token
# add following
export OS_TOKEN=YOURTOKEN
export =http://localhost:35357/v2.0

[root@keystone ~]# source ~/.keystone-admin-token



建立一個keystone的service :
[root@keystone ~]# openstack service create --name keystone --description "OpenStack Identity" identity


建立Endpoint ,若前端有Load balance的伺服器,則改成Load balance伺服器的IP或DNS名稱:
[root@keystone ~]# openstack endpoint create \
--publicurl http://192.168.10.221:5000/v2.0 \
--internalurl http://192.168.10.221:5000/v2.0 \
--adminurl http://192.168.10.221:35357/v2.0 \
--region RegionOne \
identity


建立一個admin的project與user,並設定密碼:
[root@keystone ~]# openstack project create --description "Admin Project" admin
[root@keystone ~]# openstack user create --password-prompt admin
User Password: YOURADMINPASSWORD
Repeat User Password: YOURADMINPASSWORD


建立一個admin的role,並將admin user加到此role :
[root@keystone ~]# openstack role create admin
[root@keystone ~]# openstack role add --project admin --user admin admin


新增admin的user後,要先將之前載入的keystone環境變數清掉,才能進行後面的測試 :
[root@keystone ~]# unset OS_TOKEN
[root@keystone ~]# unset OS_URL


測試


新增並載入admin user登入的環境變數檔 :
[root@keystone ~]# vim ~/.keystone-admin

# add following
export OS_PROJECT_DOMAIN_ID=default
export OS_USER_DOMAIN_ID=default
export OS_PROJECT_NAME=admin
export OS_TENANT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=YOURADMINPASSWORD
export OS_AUTH_URL=http://localhost:35357/v3

[root@keystone ~]# source ~/.keystone-admin


查看user屬於哪一個Project與Role :
[root@keystone ~]# openstack user role list
+------------------------------------------------+--------+----------+---------+
| ID                                                          | Name | Project | User   |
+------------------------------------------------+--------+----------+---------+
| c3704f46fa2846e99a8060f4a451d177 | admin | admin  | admin |
+------------------------------------------------+--------+----------+---------+




















2015年9月3日 星期四

Ubuntu 14.10 安裝Hadoop 2.7.1 (3 nodes)

環境準備


下載Hadoop 2.7.1:

hadoop@hadoop1:~$ wget http://ftp.tc.edu.tw/pub/Apache/hadoop/core/hadoop-2.7.1/hadoop-2.7.1.tar.gz
hadoop@hadoop1:~$ tar -zxvf hadoop-2.7.1.tar.gz
hadoop@hadoop1:~$ mv hadoop-2.7.1 hadoop


設定/etc/hosts:
hadoop@hadoop1:~$ vim /etc/hosts
#add following
192.168.10.221 hadoop1
192.168.10.222 hadoop2
192.168.10.223 hadoop3


產生SSH key:
hadoop@hadoop1:~$ ssh-keygen -t rsa -N "" -f /home/hadoop/.ssh/id_rsa
hadoop@hadoop2:~$ ssh-keygen -t rsa -N "" -f /home/hadoop/.ssh/id_rsa
hadoop@hadoop3:~$ ssh-keygen -t rsa -N "" -f /home/hadoop/.ssh/id_rsa


用ssh-copy-id指令,將key複製到hadoop1 :
hadoop@hadoop1:~$ ssh-copy-id hadoop1
The authenticity of host 'hadoop1 (192.168.10.221)' can't be established.
ECDSA key fingerprint is ff:53:68:f0:42:d1:39:4d:fe:29:42:66:3b:ad:3a:0d.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@hadoop1's password: YOURPASSWORD

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'hadoop1'"
and check to make sure that only the key(s) you wanted were added.

hadoop@hadoop2:~$ ssh-copy-id hadoop1
hadoop@hadoop3:~$ ssh-copy-id hadoop1


最後將hadoop1的authorized_keys複製到其它hadoop node上:
hadoop@hadoop1:~$ scp ~/.ssh/authorized_keys hadoop2:~/.ssh/authorized_keys
hadoop@hadoop1:~$ scp ~/.ssh/authorized_keys hadoop3:~/.ssh/authorized_keys

測試:
hadoop@hadoop1:~$ ssh hadoop1
hadoop@hadoop1:~$ ssh hadoop2
hadoop@hadoop1:~$ ssh hadoop3


確認JAVA有安裝:
hadoop@hadoop1:~$ java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.10.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)


設定環境變數

編輯~/.bashrc,設定JAVA_HOME與Hadoop環境變數:
hadoop@hadoop1:~$ vim ~/.bashrc
# add following
export JAVA_HOME=`readlink -f /usr/bin/java | sed 's:/bin/java::g'`

export HADOOP_HOME=/home/hadoop/hadoop
export HADOOP_PREFIX=$HADOOP_HOME
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"

複製到其它Hadoop node上:
hadoop@hadoop1:~$ scp ~/.bashrc hadoop2:~
hadoop@hadoop1:~$ scp ~/.bashrc hadoop3:~

修改Hadoop HDFS設定檔


hadoop-env.sh :
hadoop@hadoop1:~$ cd hadoop
hadoop@hadoop1:~/hadoop$ vim etc/hadoop/hadoop-env.sh
# line 25 modify
export JAVA_HOME=`readlink -f /usr/bin/java | sed 's:/bin/java::g'`


slaves :
hadoop@hadoop1:~/hadoop$ vim etc/hadoop/slaves
hadoop1
hadoop2
hadoop3


hdfs-site.xml :
hadoop@hadoop1:~/hadoop$ vim etc/hadoop/hdfs-site.xml
#line 19 modify
<configuration>
    <property>
       <name>dfs.replication</name>
       <value>1</value>
     </property>

    <property>
       <name>dfs.blocksize</name>
       <value>268435456</value>
     </property>
     <property>
       <name>dfs.namenode.name.dir</name>
       <value>file:///home/hadoop/hdfs/namenode</value>
     </property>
     <property>
       <name>dfs.datanode.data.dir</name>
       <value>file:///home/hadoop/hdfs/datanode</value>
     </property>
</configuration>

core-site.xml :
hadoop@hadoop1:~/hadoop$ vim etc/hadoop/core-site.xml
#line 19 modify:
<configuration>
      <property>
           <name>fs.defaultFS</name>
           <value>hdfs://hadoop1:9000</value>
      </property>
      <property>
           <name>io.file.buffer.size</name>
           <value>131072</value>
      </property>
</configuration>


將設定檔修改儲存後以rsync複製到其它Hadoop node上:
hadoop@hadoop1:~/hadoop$ rsync -av ~/hadoop hadoop2:~
hadoop@hadoop1:~/hadoop$ rsync -av ~/hadoop hadoop3:~


啟動 HDFS


將HDFS初始格式化:
hadoop@hadoop1:~/hadoop$ source ~/.bashrc
hadoop@hadoop1:~/hadoop$ hdfs namenode -format


啟動:
hadoop@hadoop1:~/hadoop$ start-dfs.sh



在啟動的過程中可能會出現下面的訊息,請輸入yes:
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is ff:53:68:f0:42:d1:39:4d:fe:29:42:66:3b:ad:3a:0d.
Are you sure you want to continue connecting (yes/no)? yes


網址列輸入「http://localhost:50070」,在「Datanodes」頁面應該要能看到三台HDFS nodes:




建立user資料夾:
hadoop@hadoop1:~/hadoop$ hadoop fs -mkdir /user
hadoop@hadoop1:~/hadoop$ hadoop fs -ls /
drwxr-xr-x   - hadoop supergroup          0 2015-09-04 14:06 /user


修改YARN與MapReduce設定


yarn-site.xml :
hadoop@hadoop1:~/hadoop$ vim etc/hadoop/yarn-site.xml
# line 15 modify
<configuration>
    <property>
        <name>yarn.resourcemanager.resource-tracker.address</name>
        <value>hadoop1:8031</value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.address</name>
        <value>hadoop1:8030</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>hadoop1:8032</value>
    </property>

    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
    <property>
        <name>yarn.nodemanager.local-dirs</name>
        <value>${hadoop.tmp.dir}/nm-local-dir</value>
    </property>
    <property>
        <name>yarn.nodemanager.log-dirs</name>
        <value>${yarn.log.dir}/userlogs</value>
    </property>
</configuration>


mapred-site.xml :
hadoop@hadoop1:~/hadoop$ cp etc/hadoop/mapred-site.xml.template etc/hadoop/mapred-site.xml
hadoop@hadoop1:~/hadoop$ vim etc/hadoop/mapred-site.xml
# line 19 modify
<configuration>
    <property>
       <name>mapreduce.framework.name</name>
       <value>yarn</value>
    </property>
</configuration>


將hadoop資料夾重新sync到其它Hadoop node上:
hadoop@hadoop1:~/hadoop$ rsync -av ~/hadoop hadoop2:~
hadoop@hadoop1:~/hadoop$ rsync -av ~/hadoop hadoop3:~


啟動YARN


hadoop@hadoop1:~/hadoop$ start-yarn.sh


網址列輸入「http://localhost:8088」,在「nodes」頁面應該要能看到三台Hadoop nodes:




執行Job

hadoop@hadoop1:~/hadoop$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar pi 10 1000
.....
.....省略.....
.....
Job Finished in 69.767 seconds
Estimated value of Pi is 3.14080000000000000000















CentOS7 - MariaDB 10 資料庫加密


MariaDB 從 10.1.3版開始支援table encryption,官方建議使用mariadb 10.1.4以上版本。

MariaDB Encryption 以table為最小的加密單位,據官方文件說啟用加密效能約下降10%,目前支援的 storage engine有InnoDB、XtraDB 和Aria。

雖然說它是加密的,但原理似乎跟Linux的LUKS硬碟加密差不多,在啟動MariaDB的時候需要有加密的Key檔,沒有Key檔就不能啟動,跟LUKS一樣都是在防止硬碟遭竊取時被打開來看,這樣說起來不是用硬碟加密就好了?(誤


環境準備

首先要先準備MariaDB官方的Yum Repository File :


目前(20150903)官方預設是使用Mariadb 10.0版,因此我們要將baseurl修改一下:

[root@jyc-blog ~]# cat /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安裝

用Yum安裝:
[root@jyc-blog ~]# yum install MariaDB-server MariaDB-client

啟動

跟Mariadb 5版不同,10版的服務名稱為mysql,且要用chkconfig設定開機啟動:
[root@jyc-blog ~]# systemctl start mysql.service
[root@jyc-blog ~]# chkconfig mysql on

接下來做一些簡單的設定:
[root@jyc-blog ~]# mysql_secure_installation

產生Key檔

首先用openssl這個指令產生:
[root@jyc-blog ~]# openssl enc -aes-256-cbc -k YOURPASSWORD -P -md sha1
salt=A1A4F8EF1CC6D09E
key=5D56081334F9252ABD4D641AC640907317604A8B3CA92BC94FD6769C0F746628
iv =F39393DD5C735D2B0614356C413569D4

Key檔的格式為: <key-id>;<iv>;<key> 

預設MariaDB會找編號為"1"的Key,因此我們將這把Key的id指定為"1",並將Key檔儲存在/etc/my.cnf.d :
[root@jyc-blog ~]# cd /etc/my.cnf.d/
[root@jyc-blog my.cnf.d]# vim keys.txt

#add following
1;F39393DD5C735D2B0614356C413569D4;5D56081334F9252ABD4D641AC640907317604A8B3CA92BC94FD6769C0F746628


再來將keys.txt加密,後面MariaDB讀取的就是加密後的Key檔:
[root@jyc-blog my.cnf.d]# openssl enc -aes-256-cbc -md sha1 -k YOURPASSWORD -in keys.txt -out keys.enc


MariaDB支援兩種加密演算法: AES_CBC和AES_CTR,官方建議使用AES_CTR,但需要較新的openssl版本 。


修改mariadb設定檔

編輯/etc/my.cnf.d/server.conf :
[root@jyc-blog my.cnf.d]# vim server.conf

# line 12 add following
default-storage-engine = innodb

plugin_dir=/usr/lib64/mysql/plugin
plugin-load-add=file_key_management.so

file-key-management
file_key_management_encryption_algorithm=aes_cbc
file_key_management_filename = /etc/my.cnf.d/keys.enc
file_key_management_filekey = YOURPASSWORD 
innodb-encrypt-log=ON
innodb-encryption-threads=4
innodb-encrypt-tables=FORCE
innodb-default-encryption-key-id=1


說明:
file_key_management.so : MariaDB Encryption的Plugin。
innodb-encrypt-log : 官方建議啟用,似乎比較安全。
innodb-encrypt-tables : [ON | OFF | FORCE],若設定成FORCE,建立table時設定ENCRYPTED=NO會建立失敗。


設定完後儲存,再將MariaDB重新啟動:
[root@jyc-blog ~]# systemctl restart mysql.service

測試

檢查是否有載入file_key_management plugin:
[root@jyc-blog ~]# mysql -u root -p -e "SHOW PLUGINS SONAME 'file_key_management.so';"
Enter password:
+---------------------+--------+------------+------------------------+---------+
| Name                | Status | Type       | Library                | License |
+---------------------+--------+------------+------------------------+---------+
| file_key_management | ACTIVE | ENCRYPTION | file_key_management.so | GPL     |
+---------------------+--------+------------+------------------------+---------+


查看plugin的各個參數:
[root@jyc-blog ~]# mysql -u root -p -e "show variables like '%encrypt%';"
Enter password:
+------------------------------------------------------+------------+
| Variable_name                                                 | Value      |
+-------------------------------------------------------+-----------+
| aria_encrypt_tables                                           | OFF        |
| encrypt_tmp_disk_tables                                  | OFF        |
| encrypt_tmp_files                                              | ON         |
| file_key_management_encryption_algorithm  | aes_cbc   |
| innodb_default_encryption_key_id                  | 1              |
| innodb_encrypt_log                                          | ON          |
| innodb_encrypt_tables                                      | FORCE   |
| innodb_encryption_rotate_key_age                  | 1              |
| innodb_encryption_rotation_iops                     | 100          |
| innodb_encryption_threads                               | 4              |
+-------------------------------------------------------+------------+


建立資料庫和資料表: 
[root@jyc-blog ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.1.6-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE encrypted;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> use encrypted;
Database changed
MariaDB [encrypted]> CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, col1 VARCHAR(100)) ENGINE=Innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
Query OK, 0 rows affected (0.02 sec)


#查看table是不是有加密: 
MariaDB [encrypted]> SHOW TABLE STATUS ;
+-----------------------------------------------------------------+
| Create_options                                                               |
+-----------------------------------------------------------------+
| `ENCRYPTED`=YES `ENCRYPTION_KEY_ID`=1  |
+-----------------------------------------------------------------+

# 測試innodb-encrypt-tables=FORCE是否生效,將ENCRYPTED修改為NO:
MariaDB [encrypted]> ALTER test ENCRYPTED=NO;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test ENCRYPTED=NO' at line 1












2015年9月1日 星期二

iptables阻檔特定國家連線 - 使用Xtables-addons xt_geoip

Xtables-addons是一套iptables/ip6tables的模組擴充軟體,它與patch-o-matic(-ng)相同,都是用來擴充iptables/ip6tables的功能,兩者的差別在於patch-o-matic(-ng)需要將kernel重新編譯,Xtables-addons不需要,在管理與維運上可以簡化許多工作,且patch-o-matic(-ng)已經好幾年沒有更新了。

Xtables-addons的模組清單可以參考這個網址: http://xtables-addons.sourceforge.net/modules.php

各個模組的使用方法可參考:  man Xtables-addons


Xtables-addons安裝

Xtables-addons雖然不需要重新編譯Kernel,但不同版本的Xtables-addons各自有支援的kernel,因此在安裝前需要查看系統Kernel版本:

[root@jyc-blog ~]# uname -r
3.10.0-229.11.1.el7.x86_64

Xtables-addons與kernel版本的對應: 

2.7與2.8版以上只支援Kernel 4+,因此我們下載2.6版 : 


安裝前有一些相依套件要先安裝:

[root@jyc-blog xtables-addons-2.6]# yum install gcc gcc-c++ make automake unzip zip xz kernel-devel-`uname -r` iptables-devel perl-Text-CSV_XS -y


編譯:

[root@jyc-blog xtables-addons-2.6]# ./configure ; make ; make install


xt_geoip module

xt_geoip模組的功能是用來比對封包的來源或目的地的國家,它支援ipv4和ipv6。

它使用的資料庫是MaxMind GeoLite版,因為是免費的所以比較慢,更新時間為每個月的第一個星期二。


開始使用前我們要先下載geoip資料庫:

[root@jyc-blog xtables-addons-2.6]# cd geoip/
[root@jyc-blog geoip]# ./xt_geoip_dl

執行完後會多出兩個檔案:GeoIPCountryWhois.csv與GeoIPv6.csv。
xt_geoip_dl是xtables-addons內建的工具,還有另一個工具用來將CSV檔轉換成Binary格式:

[root@jyc-blog geoip]# ./xt_geoip_build GeoIPCountryWhois.csv  GeoIPv6.csv

轉換後產生兩個資料夾BE和LE,要將這兩個資料夾搬到iptables搜尋的目錄:

[root@jyc-blog geoip]# mkdir -p /usr/share/xt_geoip
[root@jyc-blog geoip]# mv BE/ LE/ /usr/share/xt_geoip

也可以將指令簡化成:
[root@jyc-blog geoip]# ./xt_geoip_build -D /usr/share/xt_geoip *.csv

查看安裝是否成功:
[root@jyc-blog geoip]# lsmod | grep xt_geoip
xt_geoip               12775  3


xt_geoip Usage:
--src-cc, --source-country country[,country...]
--dst-cc, --destination-country country[,country...]


範例:
[root@jyc-blog ~]# iptables -N GEOIP_REJECT
[root@jyc-blog ~]# iptables -I GEOIP_REJECT -m geoip --src-cc CN,KR,KP -j DROP
[root@jyc-blog ~]# iptables -I INPUT -j GEOIP_REJECT
[root@jyc-blog ~]# iptables -I INPUT -m geoip --src-cc TW -j ACCEPT


xt_geoip的國碼是根據ISO-3166的格式,可以參考


定期更新geoip資料庫

[root@jyc-blog bin]# cat xt_geoip.sh
#!/bin/bash
XTABLE_PATH="/usr/local/src/xtables-addons-2.6"

cd ${XTABLE_PATH}/geoip
./xt_geoip_dl
./xt_geoip_build -D /usr/share/xt_geoip *.csv




修正SELinux權限 


[root@jyc-blog ~]# chcon -vR --user=system_u /lib/modules/$(uname -r)/extra/*
[root@jyc-blog ~]# chcon -vR --type=lib_t /lib64/xtables/*

修正完後再手動將xt_geoip模組載入

[root@jyc-blog ~]# modprobe xt_geoip







2015年8月17日 星期一

Swift/Ceph S3 API Comparison

General S3 REST API Support

Feature
Ceph
Swift
List Bucket Objects
V
V
Bucket ACLs
X
X
Bucket Lifecycle
X
X
Bucket Policy
X
X
Bucket Location
V
X
Bucket Logging
?
X
Bucket Notification
X
X
Bucket Object Versions
V
X
Bucket Request Payment
X
X
Bucket Versioning
V
X
Bucket Website
X
X


Amazon S3 REST API Compatability

Feature
Ceph
Swift
DELETE Bucket
V
V
DELETE Bucket lifecycle
X
X
DELETE Bucket policy
?
X
DELETE Bucket website
X
X
GET Bucket (List Objects)
V
V
GET Bucket acl
V
X
GET Bucket lifecycle
X
X
GET Bucket policy
?
X
GET Bucket location
X
V
GET Bucket logging
?
V
GET Bucket notification
X
X
GET Bucket Object versions
X
X
GET Bucket requestPayment
X
X
GET Bucket versioning
X
X
GET Bucket website
X
X
HEAD Bucket
V
V
List Multipart Uploads
V
X
PUT Bucket
V
V
PUT Bucket acl
V
X
PUT Bucket lifecycle
X
X
PUT Bucket policy
?
X
PUT Bucket logging
?
X
PUT Bucket notification
X
X
PUT Bucket requestPayment
X
X
PUT Bucket versioning
X
X
PUT Bucket website
X
X
DELETE Object
V
V
Delete Multiple Objects
V
V
GET Object
V
V
GET Object ACL
V
X
GET Object torrent
X
X
HEAD Object
V
V
POST Object
V
X
PUT Object
V
V
PUT Object acl
V
X
PUT Object - Copy
V
V
Initiate Multipart Upload
V
V
Upload Part
V
V
Upload Part - Copy
?
V
Complete Multipart Upload
V
V
Abort Multipart Upload
V
V
List Parts
V
V



Ref: