[Docker] time sync with host

docker run -v /etc/localtime:/etc/localtime:ro -i -t mattdm/fedora /bin/bash

Source: stackoverflow: How to make sure docker’s time syncs with that of the host?

Posted in Docker | Comments Off on [Docker] time sync with host

[Docker] Common commands

show all containers:

docker ps -a

stop all containers:

docker kill $(docker ps -q)

remove all containers:

docker rm $(docker ps -a -q)

remove all docker images:

docker rmi $(docker images -q)

enter docker container:

docker exec -it $(container id) bash

build docker image:

docker build -t $(image name) .

show all build failure images:

docker images -f “dangling=true” -q

remove all build failure images:

docker rmi $(docker images -f “dangling=true” -q)

create docker-machine on virtualbox:

docker-machine create -d virtualbox $(machine name)

set docker environment:

eval “$(docker-machine env)”

unset docker environment:

eval “$(docker-machine env -u)”

show docker all network:

docker network ls

show docker network detail information:

docker network inspect $(docker network)

start container with forwarding port setting

docker run -p $(host_port1):$(container_port1) -p $(host_port2):$(container_port2) $(docker_image)

ex. # docker run -p 60022:22 -p 2181:2181 -p 8090:8090 -p 60000:60000 -p 60010:60010 -p 60020:60020 -p 60030:60030 qmi

start container with hostname setting

docker run –hostname $(hostname) $(docker_image)

ex. # docker run –hostname qmi_docker qmi

start container with input/output tty

docker run -it $(docker_image)

stop container

docker stop $(container id)

build image from container

docker commit $(container_id) $(docker_image)

Posted in Docker | Leave a comment

[HBase] security issue

error message:

com.a.b.c.exception.BaseDAOException: org.apache.hadoop.hbase.security.AccessDeniedException: org.apache.hadoop.hbase.security.AccessDeniedException: Insufficient permissions for user ‘Cowman’ (table=ABC, action=READ)

in jvm conf. add

“-DHADOOP_USER_NAME=webuser”

Posted in HBase, Java | Leave a comment

[Apache] wordpress permalink 404 issue

  1. edit site conf (vim /etc/apache2/sites-available/pr.site.org.conf)
<VirtualHost pr.site.org:80>       
        ServerName pr.site.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/pr.site.org
# !-- add this section
        <Directory /var/www/pr.site.org>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
# !--
        ErrorLog ${APACHE_LOG_DIR}/pr_error.log
        CustomLog ${APACHE_LOG_DIR}/pr_access.log combined
</VirtualHost>
  1. enable apache2 rewrite module
a2enmod rewrite
  1. restart apache2 service
service apache2 restart

 

Ref.

[1] Victor Hung’s Diary: 「教學」解決 WordPress 固定網址設定 404 錯誤

[2] DigitalOcean: WordPress permalinks tried everything

 

Posted in Apache, Ubuntu, WordPress | Leave a comment

[HBase] convert long value to bytes

Java code:

public static void main(String[] args) {
    String stringValue = Bytes.toStringBinary(Bytes.toBytes(1532080782183l));
    System.out.println(stringValue);
    Long longValue = Bytes.toLong(Bytes.toBytesBinary(stringValue));
    System.out.println(longValue);
}

HBase shell command:

hbase(main):056:0> Bytes.toStringBinary(Bytes.to_bytes(1532080782183))
=> "\\x00\\x00\\x01d\\xB7!{g"
hbase(main):057:0> Bytes.toLong("\x00\x00\x01d\xB7!{g".to_java_bytes)
=> 1532080782183
Posted in HBase, Java | Leave a comment

[Intellij] Checkstyle and Code Style

Checkstyle

介紹

  1. 根據定義好的規則對程式碼進行檢查,以確保程式碼的 Style 是一致的 (盡力…)
  2. Checkstyle GitHub 有提供兩種規則範例,後續套用的規則即是使用 “Google Checks” 進行修改
    • Sun Checks
    • Google Checks

安裝 Checkstyle

  1. Preferences.. ➔ Plugins ➔ Browse repositories.. -> 搜尋 “CheckStyle”
  2. 安裝 “CheckStyle-IDEA”

Checkstyle 規則文件說明

  1. checkstyle/qmi_checks.xml 為 Checkstyle 主規則檔案
    • 定義檢查的檔案格式、範圍
    • 定義排除的規則檔案位置 (通常為 suppressions.xml)
    • 定義檢查的項目,每一個項目可定義的屬性不固定,需檢視 官方說明文件
  2. checkstyle/suppressions.xml 為 Checkstyle 的例外設定
    • 針對特定檢查規則定義排除檢查的檔案

套用 Checkstyle規則

  1. 選擇 Checkstyle version: 8.12 (至少8.11, 因有 LambdaParameterName 設定)
  2. Preferences.. ➔ Other Settings ➔ Checkstyle ➔ Add Configuration File
  3. 匯入後設定為 Active

啟用 Checkstyle 即時檢查

  1. Preferences.. ➔ Editor ➔ Inspections ➔ Checkstyle ➔ Checkstyle real-time scan
  2. 預設為開啟

產生 Checkstyle 檢查報告

  1. 下載檔案
  2. 產生XML格式報告
    java -jar checkstyle-8.12-all.jar -c qmi_checks.xml {Qmi_Project} -f xml -o report.xml
  3. 使用 Mac 內建程式 “xsltproc” 將 XML 報表轉成 HTML 格式
    xsltproc -o output.html checkstyle-noframes-severity-sorted.xsl input.xml

Code Style

介紹

  1. Intellij 編輯器內建功能,根據定義好的 Schema 進行檢查
  2. 官網介紹
  3. 可透過 “Save Actions” 設定當檔案儲存時自動執行 Reformat Code 及 Optimize Imports 以符合 Code Style 規則

匯入 Code Style 設定檔案

  1. 檔案位置: checkstyle/qmicodeformat.xml
  2. Preferences.. ➔ Editor ➔ Code Style ➔ Java ➔ Schema ➔ Import Schema ➔ IntelliJ IDEA code style XML

安裝 Save Actions

  1. Preferences.. ➔ Plugins ➔ Browse repositories.. -> 搜尋 “Save Actions”
  2. 安裝 “Save Actions”

設定 Save Actions

  1. Preferences.. ➔ Other Settings ➔ Save Action ➔ General ➔勾選 “Activate save actions on save (before saving each file, performs the configured actions below)”
  2. Preferences.. ➔ Other Settings ➔ Save Action ➔ General ➔勾選 “Optimize Imports”, “Reformat file”, “Rearrange fields and methods”

備註說明

  1. 因 Code Style 的 Arrangement 功能容易跟 Checkstyle 的規則抵觸,估會將 Arrangement 的功能關閉
  2. JavaDoc 中定義 Map 時,切勿使用 “Map<Object, Object>” 等形式編寫,此會造成 Code Style 誤判而對齊調整格式,導致每次儲存都會出現變動
Posted in Intellij | Leave a comment

[Docker] The crontab is not work in docker

Source: docker容器内cron不执行

vim /etc/pam.d/crond

#

The PAM configuration file for the cron daemon

#
#

No PAM authentication called, auth modules not needed

account required pam_access.so

account sufficient pam_access.so
account include password-auth

session required pam_loginuid.so

session sufficient pam_loginuid.so
session include password-auth
auth include password-auth

required: failure of such a PAM will ultimately lead to the PAM-API returning failure but only after the remaining stacked modules (for this service and type) have been invoked.

sufficient: if such a module succeeds and no prior required module has failed the PAM framework returns success to the application or to the superior PAM stack immediately without calling any further modules in the stack. A failure of a sufficient module is ignored and processing of the PAM module stack continues unaffected.

4.1. Configuration file syntax

Posted in Docker, Linux | Leave a comment

[Git] edit commit message after push

Source: stackopenflow: Changing git commit message after push (given that no one pulled from remote)

git comment --amend
git push --force

Posted in Git | Leave a comment

[Python] fix error while loading shared libraries: libpython2.7.so.1.0

error log: /opt/rh/python27/root/usr/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

check libpython2.7.so.1.0 exist?
find . -name 'libpython2.7.so.1.0'

if the file was exist: edit the ldconfig config
echo "/opt/rh/python27/root/usr/lib64" > /etc/ld.so.conf.d/python27.conf
ldconfig

if the file was not exist: install python27
(to install python2.7 in centos 6 , source: vcloudnine: Python 2.7 for CentOS 6)
yum install centos-release-SCL
yum install python27

Posted in CentOS, Python | Leave a comment

[Git] find the file’s latest edited time

Source: stackoverflow: Find when a file was deleted in Git

$ git log -1 -- o-core/o-service/src/main/java/path/file.java
commit 0d5ab0e5d9df7d7b5906ff8db169f43b760daea0
Author: cowman cowman@mitake.com.tw
Date: Mon Dec 18 17:58:26 2017 +0800

remove file.java</code>
Posted in Git | Leave a comment