Category Archives: Source

Hadoop配置ファイルのサンプルコード

サンプルコード:
<?xml version=”1.0″?>
<?xml-stylesheet type=”text/xsl” href=”configuration.xsl”?>
<configuration>
<property>
<name>io.sort.factor</name>
<value>10</value>
<description>The number of streams to merge at once while sorting
files. This determines the number of open file handles.</description>
</property>
<property>
<name>dfs.name.dir</name>
<value>${hadoop.tmp.dir}/dfs/name</value>
<description>Determines where on the local filesystem the DFS name
nodeshould store the name table(fsimage). ……</description>
</property>
<property>
<name>dfs.web.ugi</name>
<value>webuser,webgroup</value>
<final>true</final>
<description>The user account used by the web interface.
Syntax: USERNAME,GROUP1,GROUP2, ……</description>
</property>
</configuration>

DIVで複数の列を同じ高さに揃えるサンプルプログラム

DIVコード:
.detail_row {
overflow :hidden;
font-size :16px;
}
.detail_col_one, .detail_col_two, .detail_col_three, .detail_col_four,.one-row-label, .one-row-content {
margin-bottom :-2000px;
padding-bottom :2000px;
}
.detail_col_one, .detail_col_three, .one-row-label {
width : 80px;
text-align: right;
font-weight: bold;
}
.detail_col_two, .detail_col_four {
padding-left: 8px;
width: 35%;
}
.detail_col_two:hover, .detail_col_four:hover, .one-row-content:hover {
background-color: #EFFEFD;
/* font-size: 14px; */
}
.detail_col_one, .detail_col_two, .detail_col_three, .detail_col_four, .one-row-label, .one-row-content {
float :left;
line-height: 170%;
}
.one-row-content {
padding-left: 8px;
width : 80%;
}
<div class=”detail_row”>
<div class=”detail_col_one”>
<nobr><fmt:message key=”AddressBook.Detail.Mobile” /> :</nobr>
</div>
<div id=”viewMobile” class=”detail_col_two”></div>
<div class=”detail_col_three”>
<nobr><fmt:message key=”AddressBook.Detail.Email” /> :</nobr>
</div>
<div id=”viewEmail” class=”detail_col_four”></div>
</div>
<div class=”detail_row”>
<div class=”one-row-label”>
<nobr><fmt:message key=”AddressBook.Detail.Jobdesc” /> :</nobr>
</div>
<div id=”viewJobdesc” class=”one-row-content”></div>
</div>

rubyにおけるhashの実装プログラム

rubyコード:
h = {‘a’=>’aaa’,2=>’bbb’}
h.each do |a,b|
puts a.to_s+”–“+b.to_s
end

WildFlyの System V init スクリプト

次のスクリプトを実行してCentOS/RHELに自動的にWildFlyサーバーが起動
shellコード:
/etc/init.d/wildfly.sh

#!/bin/bash

: ${JAVA_HOME:=/usr/lib/jvm/jdk-7u51}
export JAVA_HOME

: ${SCALA_HOME:=/opt/scala-2.10.2}
export SCALA_HOME

PROC_LOCATION=/opt/wildfly-8.0.0.Final
PROC_NAME=’WildFly App Server’
PROC_USER=wildfly
PROC_APP=wildfly
SLEEPTIME=8

export WILDFLY_HOME=${PROC_LOCATION}

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/${PROC_APP}.pid

PREFIX_CMD=
## PREFIX_CMD=’echo =>’

SUDO_CMD=/usr/bin/sudo

case “$1” in
start)
echo “Starting service ${PROC_NAME}”
${PREFIX_CMD} mkdir -p /var/log/${PROC_APP}
${PREFIX_CMD} chown -R ${PROC_USER} /var/log/${PROC_APP}
${PREFIX_CMD} ${SUDO_CMD} -u ${PROC_USER} -E ${WILDFLY_HOME}/bin/standalone.sh >> /var/log/${PROC_APP}/${PROC_APP}.log &
exit $?
;;

stop)
echo “Stopping service ${PROC_NAME}”
ProcessId=`ps auwwx | grep -v awk | awk ‘/’${PROC_USER}’/ && /org.jboss.as.standalone/ { print $2 }’`
${PREFIX_CMD} kill ${ProcessId}
exit $?
;;

restart)
$0 stop
echo “Zzz … $SLEEPTIME secs”
sleep $SLEEPTIME
$0 start
;;

probe|status)
ProcessId=`ps auwwx | grep -v awk | awk ‘/’${PROC_USER}’/ && /org.jboss.as.standalone/ { print $0 }’`
if [ “x${ProcessId}” != “x” ]; then
echo $ProcessId
else
echo “No process is running.”
fi
;;

*)
echo “Usage: $0 start | stop | restart | probe | status”
exit 1
;;

esac

#End

setenv.shに「-XX:+UseCompressedOops」を追加するプログラム

shellコード:
#!/bin/bash
#Program:
# tomcatのbinにsetenv.shを作成
#ディレクトリを入力
read -p “ディレクトリを入力してください:” dir
if [ ${dir} == “” -o ! -d ${dir} ]; then
echo “$dir 存在しません”
exit 1
fi

dirList=$(ls -d ${dir}/*/bin )
for binDir in $dirList
do
#setenv.shを作成
fileName=${binDir}/setenv.sh
if [ ! -f fileName ]; then
touch ${fileName}
fi
temp=$(cat ${fileName})

count1=$(echo ${temp}|grep -c ‘JAVA_OPTS’)
count2=$(echo ${temp}|grep -c ‘UseCompressedOops’)
# echo ${fileName}${count1}${count2}
if [ ${count1} == ‘1’ ] && [ ${count2} == ‘0’ ]; then
temp=$(echo ${temp}|sed ‘s/”$/ -XX:+UseCompressedOops”/g’)
elif [ ${count1} == ‘0’ ]; then
temp=’JAVA_OPTS=”$JAVA_OPTS -XX:+UseCompressedOops”‘
fi

echo ${temp}>${fileName}
done

「shellの学習」tomcat再起動スクリプト

shellコード:
#!/bin/sh

tomcat_path=”/data/www/”

####################################################
# ディフォルト実行パス /data/www/tomcat_startnews24/ #
# パラメータを指定 /data/www/直下tomcatを実行 #
# スクリプトで自動的にtomcatを実行 #
####################################################

echo $#
if [ $# -ne 1 ]; then
tomcatname=”tomcat_startnews24″ #ディフォルトtomcatパス
else
tomcatname=$1
fi

tomcatpath=${tomcat_path}${tomcatname}/
ps -ef | grep java | grep ${tomcatpath};
pid=`ps -ef | grep java | grep ${tomcatpath} | awk ‘{print $2}’`

echo -e “${tomcatpath}が起動前, should kill the same run, kill pid ${pid} (yes/no)? \c”
read Confirm

case $Confirm in
y|Y|yes|Yes)
rm -rf ${tomcatpath}work/*
kill -9 $pid
#rm -f ${tomcatpath}${tomcatname}.pid
sleep 1
echo $(tomcatpath)
${tomcatpath}bin/startup.sh
#tail -f ${tomcatpath}logs/catalina.out
;;
*)
echo ” ${tomcatpath}再起動キャンセルした”
;;
esac

shellで毎日自動的にファイルをアップロードするスクリプト

shellコード:

@echo off
set srcFile=d:\temp.src
del %srcFile%
echo open >”%srcFile%”
echo 192.168.1.60 >>”%srcFile%”
echo Anonymous >>”%srcFile%”
echo bin >>”%srcFile%”
echo put %1 %2_%date%.bak >>”%srcFile%”
echo quit >>”%srcFile%”
@echo on
ftp -s:”%srcFile%”

Ubuntu 12.04にskypeをインストールする方法

サンプルコード:
sudo add-apt-repository “deb http://archive.canonical.com/ $(lsb_release -sc) partner”
sudo apt-get update && sudo apt-get install skype

centosにyumでgccをインストール

yumでインストール手順:
方法1
yum -y install gcc
yum -y install gcc-c++
yum install make

方法2
yum groupinstall “Development Tools”

方法3
yum install gcc gcc-c++ kernel-devel

Ubuntuにjdk8をインストール

インストール手順:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

sudo apt-get install oracle-java8-set-default