Tomcat設定https

使用keytool產生RSA

cd /usr/java/jdk1.7.0_21/bin/

./keytool -genkey -alias tomcat -keyalg RSA

Enter keystore password:
Re-enter new password:
What is your first and last name?
What is the name of your organizational unit?
What is the name of your organization?
What is the name of your City or Locality?
What is the name of your State or Province?
What is the two-letter country code for this unit?
Is CN=udn, OU=udn, O=udn, L=taipei, ST=taiwan, C=TW correct?
Enter key password for
(RETURN if same as keystore password):

然後在編輯server.xml

vim /usr/data/apache-tomcat-7.0.40/conf/server.xml

取消對Connector port=”8443″的註解,增加keystorePass的描述

    

最後在重新啟動tomcat

Posted in JSP | Leave a comment

Tomcat修改預設port為80

編輯server.xml

vim /usr/data/apache-tomcat-7.0.40/conf/server.xml

8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

將8080修改為80後重新啟動tomcat

Posted in JSP | Leave a comment

安裝Tomcat7

  1. 安裝jdk
    至http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html下載 (此處以jdk-7u10-linux-x64.rpm為例)

rpm -ivh jdk-7u10-linux-x64.rpm

設定jdk環境

cat << EOF > /etc/profile.d/java.sh

export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
EOF

cat << EOF > /etc/profile.d/java.csh

set JAVA_HOME=/usr/java/default
set PATH=$JAVA_HOME/bin:$PATH
EOF

. /etc/profile.d/java.sh

  1. 安裝tomcat7
    至http://tomcat.apache.org/download-70.cgi下載 (此處以apache-tomcat-7.0.40.tar.gz為例)

wget http://ftp.twaren.net/Unix/Web/apache/tomcat/tomcat-7/v7.0.40/bin/apache-tomcat-7.0.40.tar.gz

tar zxvf apache-tomcat-7.0.40.tar.gz

mkdir /usr/data

mv apache-tomcat-7.0.40 /usr/data/

vim /etc/init.d/tomcat

#!/bin/bash

description: Tomcat start stop restart

processname: tomcat

chkconfig: 234 20 80

CATALINA_HOME=/usr/data/apache-tomcat-7.0.40
case $1 in
start)
bash $CATALINA_HOME/bin/startup.sh
;;
stop)
bash $CATALINA_HOME/bin/shutdown.sh
;;
restart)
bash $CATALINA_HOME/bin/shutdown.sh
bash $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0

chkconfig –add tomcat

service tomcat start

Posted in JSP | Leave a comment

計算檔案數量

Source: http://phorum.study-area.org/index.php/topic,10994.0.html

第一種:
如果只要一般的檔案, 可以用:
find . -type f -print | wc -l

如果是要不含目錄的檔案 (含 b, c 之類), 可以用:
find . ! -type d -print | wc -l

第二種:
如果單純 “只” 針對普通檔:
ls -lR /path/to/dir | grep ‘^-‘ | wc -l

含隱藏檔:
ls -laR /path/to/dir | grep ‘^-‘ | wc -l

含隱藏檔、符號連結、Charactor、Block :
ls -laR /path/to/dir | grep ‘^[-lcb]’ | wc -l

參考資料:
http://www.study-area.org/linux/system/linux_fs.htm
http://www.study-area.org/linux/system/linux_com.htm
http://www.study-area.org/linux/system/linux_shell.htm

Posted in Linux | Leave a comment

FTP Download Script

<

pre lang=”bash”>

!/bin/sh

程式說明:每日將 Mail Log 匯入 Splunk 之 Script

版本時間:2013/05/30 10:40

開發維護:cowman.chiang@udngroup.com

檢查檔案是否存在,存在則移除檔案

避免ftp下載時無法覆蓋檔案以致無法取得新版檔案

function checkfile(){
if test -f “${local_dir}/${1}”
then
echo “File ${1} exist, remove!”
rm “${local_dir}/${1}”
else
echo “File ${1} not exist”
a=1
fi
}

設定 Mail Log 主機資訊

HOST1={IP_address}
USER1={User}
PASS1={Pass}

設定 imss Log 主機資訊

HOST2={IP_address}
USER2={User}
PASS2={Pass}

設定各項日期、程式參數

year_d1=$(date –date=”1 days ago” +”%Y”)
year_d2=$(date –date=”2 days ago” +”%Y”)
year_d3=$(date –date=”3 days ago” +”%Y”)
month_d1=$(date –date=”1 days ago” +”%m”)
month_d2=$(date –date=”2 days ago” +”%m”)
month_d3=$(date –date=”3 days ago” +”%m”)
ext_d1=$(date –date=”1 days ago” +”%y%m%d”)
ext_d2=$(date –date=”2 days ago” +”%y%m%d”)
local_path=”/home/splunk_input_data”
local_dir=”${local_path}/all”
declare -i date_dem=date --date="20130501" +%s
declare -i date_d2=date --date="2 days ago" +%s
declare -i date_total_s=$(($date_d2 – $date_dem))
declare -i date_diff=$(($date_total_s/60/60/24))
date_diff_d3=$((($date_diff – 1) * 86400 + 1367366400 ))
date_diff_d2=$(($date_diff * 86400 + 1367366400 ))
date_diff_d1=$((($date_diff + 1) * 86400 + 1367366400 ))
date_d1_ext=$(date –date=”1 days ago” +”%Y%m%d”)
date_d2_ext=$(date –date=”2 days ago” +”%Y%m%d”)
date_d3_ext=$(date –date=”3 days ago” +”%Y%m%d”)

依據 Log 命名原則進行設定

pop3d_log=”pop3d.log.${ext_d1}”
pop3d_log_m2=”${pop3d_log}_m2″
smtpd_log=”smtpd.log.${ext_d1}”
smtpd_log_m2=”${smtpd_log}_m2″
smtpd_2log=”smtpd_2nd.log.${ext_d1}”
smtpd_2log_m2=”${smtpd_2log}_m2″
login_log=”login.log.${ext_d1}”
login_log_m2=”${login_log}_m2″
imap4d_log=”imap4d.log.${ext_d1}”
imap4d_log_m2=”${imap4d_log}_m2″
access_log=”access_log.${date_diff_d1}.${date_d1_ext}”
access_log_m2=”${access_log}_m2″
access_2log=”access_log.${date_diff_d2}.${date_d2_ext}”
access_2log_m2=”${access_2log}_m2″
access_3log=”access_log.${date_diff_d3}.${date_d3_ext}”
access_3log_m2=”${access_3log}_m2″
imss_log=”log.imss.${date_d1_ext}.0001″
imss_log2=”log.imss.${date_d1_ext}.0002″
imss_2log=”log.imss.${date_d2_ext}.0001″
imss_2log2=”log.imss.${date_d2_ext}.0002″
mailerd_log=”mailerd.log.${ext_d1}”
mailerd_log2=”${mailerd_log}_m2″
mailerd_2log=”mailerd_2nd.log.${ext_d1}”
mailerd_2log2=”${mailerd_2log}_m2″

檢查欲處理之檔案是否已經存在於暫存目錄

checkfile ${pop3d_log}
checkfile ${pop3d_log_m2}
checkfile ${smtpd_log}
checkfile ${smtpd_log_m2}
checkfile ${smtpd_2log}
checkfile ${smtpd_2log_m2}
checkfile ${login_log}
checkfile ${login_log_m2}
checkfile ${imap4d_log}
checkfile ${imap4d_log_m2}
checkfile ${access_log}
checkfile ${access_log_m2}
checkfile ${access_2log}
checkfile ${access_2log_m2}
checkfile ${access_3log}
checkfile ${access_3log_m2}
checkfile ${imss_log}
checkfile ${imss_log2}
checkfile ${imss_2log}
checkfile ${imss_2log2}
checkfile ${mailerd_log}
checkfile ${mailerd_log2}
checkfile ${mailerd_2log}
checkfile ${mailerd_2log2}

輸出本次日期

echo date +%Y%m%d

當發現硬碟使用率大於80%時,通知維護人員

if [ /bin/df -h | awk 'NR==4 {print $5}' | sed 's/%//' -ge 80 ]
then
(
echo To: cowman.chiang@udngroup.com
echo From: Splunk@udnlap01
echo Subject: Splunk Server disk usage > 80%
echo
) | /usr/sbin/sendmail -t
fi

FTP抓取第一階段

echo “sftping file … (1/2)”

lftp -u ${USER1},${PASS1} sftp://${HOST1} <<EOF
lcd ${local_dir}
cd /webmail/usr/share/log_archive/${year_d1}${month_d1}
get ${pop3d_log}
get ${pop3d_log_m2}
get ${smtpd_log}
get ${smtpd_log_m2}
get ${smtpd_2log}
get ${smtpd_2log_m2}
get ${login_log}
get ${login_log_m2}
get ${imap4d_log}
get ${imap4d_log_m2}
get ${access_log}
get ${access_log_m2}
get ${mailerd_log}
get ${mailerd_log2}
get ${mailerd_2log}
get ${mailerd_2log2}
cd /webmail/usr/share/log_archive/${year_d2}
${month_d2}
get ${access_2log}
get ${access_2log_m2}
cd /webmail/usr/share/log_archive/${year_d3}_${month_d3}
get ${access_3log}
get ${access_3log_m2}
bye
EOF

FTP抓取第二階段

echo “sftping file … (2/2)”

lftp -u ${USER2},${PASS2} sftp://${HOST2} <<EOF
lcd ${local_dir}
cd /opt/trend/imss/log
get ${imss_log}
get ${imss_log2}
get ${imss_2log}
get ${imss_2log2}
bye
EOF

輸出本次抓取資料量

echo “/usr/bin/du -m ${local_dir} | awk '{print $1}'MB”

假設抓取資料量小於450MB則進行

但有可能誤判,因access.log產生時間不確定,故在執行上會從三天前之檔案進行抓取

以至於有可能抓取到重複的檔案,導致抓取資料量遠大於將匯入Splunk處理的資料量

if [ /usr/bin/du -m ${local_dir} | awk '{print $1}' -lt 450 ]
then

假設換年度了,則創建新的年度目錄,並通知維護人員換年度了,需要上來檢查一下

if [ ${year_d1} -gt ${year_d2} ]
then
mkdir ${local_path}/pop3d/${year_d1}/
mkdir ${local_path}/smtpd/${year_d1}/
mkdir ${local_path}/login/${year_d1}/
mkdir ${local_path}/imap4d/${year_d1}/
mkdir ${local_path}/access/${year_d1}/
mkdir ${local_path}/imss/${year_d1}/
mkdir ${local_path}/mailerd/${year_d1}/
(
echo To: cowman.chiang@udngroup.com
echo From: Splunk@udnlap01
echo Subject: Splunk Change Year
echo
) | /usr/sbin/sendmail -t
fi

搬移檔案到指定目錄

mv ${local_dir}/${pop3d_log} ${local_path}/pop3d/${year_d1}/
mv ${local_dir}/${pop3d_log_m2} ${local_path}/pop3d/${year_d1}/
mv ${local_dir}/${smtpd_log} ${local_path}/smtpd/${year_d1}/
mv ${local_dir}/${smtpd_log_m2} ${local_path}/smtpd/${year_d1}/
mv ${local_dir}/${smtpd_2log} ${local_path}/smtpd/${year_d1}/
mv ${local_dir}/${smtpd_2log_m2} ${local_path}/smtpd/${year_d1}/
mv ${local_dir}/${login_log} ${local_path}/login/${year_d1}/
mv ${local_dir}/${login_log_m2} ${local_path}/login/${year_d1}/
mv ${local_dir}/${imap4d_log} ${local_path}/imap4d/${year_d1}/
mv ${local_dir}/${imap4d_log_m2} ${local_path}/imap4d/${year_d1}/
mv ${local_dir}/${access_log} ${local_path}/access/${year_d1}/
mv ${local_dir}/${access_log_m2} ${local_path}/access/${year_d1}/
mv ${local_dir}/${access_2log} ${local_path}/access/${year_d2}/
mv ${local_dir}/${access_2log_m2} ${local_path}/access/${year_d2}/
mv ${local_dir}/${access_3log} ${local_path}/access/${year_d3}/
mv ${local_dir}/${access_3log_m2} ${local_path}/access/${year_d3}/
mv ${local_dir}/${imss_log} ${local_path}/imss/${year_d1}/
mv ${local_dir}/${imss_log2} ${local_path}/imss/${year_d1}/
mv ${local_dir}/${imss_2log} ${local_path}/imss/${year_d2}/
mv ${local_dir}/${imss_2log2} ${local_path}/imss/${year_d2}/
mv ${local_dir}/${mailerd_log} ${local_path}/mailerd/${year_d1}/
mv ${local_dir}/${mailerd_log2} ${local_path}/mailerd/${year_d1}/
mv ${local_dir}/${mailerd_2log} ${local_path}/mailerd/${year_d1}/
mv ${local_dir}/${mailerd_2log2} ${local_path}/mailerd/${year_d1}/
echo “move ok”

搬移完成,通知維護人員本日匯入成功

mail -s “Splunk input data ok” cowman.chiang@udngroup.com < /home/splunk_input_data/ok.txt

(
echo To: cowman.chiang@udngroup.com
echo From: Splunk@udnlap01
echo Subject: Splunk Input Data ok
echo
cat ${local_path}/ok.txt
) | /usr/sbin/sendmail -t

else

處理失敗,通知維護人員本日因資料量大於450mb,需要手動進行操作

mail -s “Splunk input data no ok” cowman.chiang@udngroup.com < /home/splunk_input_data/nok.txt

(
echo To: cowman.chiang@udngroup.com
echo From: Splunk@udnlap01
echo Subject: Splunk Input Data No ok
echo
cat ${local_path}/nok.txt
) | /usr/sbin/sendmail -t
fi

echo “done”

Posted in Linux, Splunk | Leave a comment

Splunk 指定Web服務Port

方法1
登入 Web 後進管理員更改

方法2
修改 web.conf (但是我還是不知道在哪….)

方法3
指令直接更改 (狂推)
/opt/splunk/bin/splunk set web-port 443

Posted in Splunk | Leave a comment

Splunk搬移到新主機

  1. {Old-Splunk-server}:service splunk stop
  2. {Old-Splunk-server}:tar cvf {檔案名稱} /opt/splunk/
  3. {Old-Splunk-server}:scp {檔案名稱} {帳號}@{New-Splunk-server}:/tmp
  4. {New-Splunk-server}:tar xvf /tmp/{檔案名稱} -C /
  5. {New-Splunk-server}:下載Splunk Tar安裝檔案
  6. {New-Splunk-server}:tar xvzf {Splunk-Tar-安裝檔案} -C /opt
  7. {New-Splunk-server}:/opt/splunk/bin/splunk enable boot-start

就可以依造 {Old-Splunk-server} 的連接設定進行使用
但需要注意因為IP名稱應該會更動,有關IP的部分都要重新設定
包含Clinet端Foward的目標、Syslog server的設定等

Posted in Splunk | Leave a comment

使用IP反查電腦名稱

  1. nslookup {IP}
  2. ping -a {IP}
  3. nbtstat -A {IP}
Posted in Windows | Leave a comment

定時間看結果 — Watch

WATCH(1)                      Linux User’s Manual                     WATCH(1)

NAME
       watch - execute a program periodically, showing output fullscreen

SYNOPSIS
       watch   [-dhvt]   [-n   ]   [--differences[=cumulative]]   [--help]  [--interval=]
       [--no-title] [--version] 

DESCRIPTION
       watch runs command repeatedly, displaying its output (the first screenfull).   This  allows  you  to
       watch  the  program output change over time.  By default, the program is run every 2 seconds; use -n
       or --interval to specify a different interval.

       The -d or --differences flag will highlight the differences between successive updates.  The --cumu-
       lative  option  makes highlighting "sticky", presenting a running display of all positions that have
       ever changed.  The -t or --no-title option turns off the header showing the interval,  command,  and
       current time at the top of the display, as well as the following blank line.

       watch will run until interrupted.

NOTE
       Note  that command is given to "sh -c" which means that you may need to use extra quoting to get the
       desired effect.

       Note that POSIX option processing is used (i.e., option processing stops  at  the  first  non-option
       argument).  This means that flags after command don’t get interpreted by watch itself.

EXAMPLES
       To watch for mail, you might do

              watch -n 60 from

       To watch the contents of a directory change, you could use

              watch -d ls -l

       If you’re only interested in files owned by user joe, you might use

              watch -d ’ls -l | fgrep joe’

       To see the effects of quoting, try these out

              watch echo $$

              watch echo ’$$’

              watch echo "’"’$$’"’"

       You can watch for your administrator to install the latest kernel with

              watch uname -r

       (Just kidding.)

BUGS
       Upon  terminal  resize,  the screen will not be correctly repainted until the next scheduled update.
       All --differences highlighting is lost on that update as well.

       Non-printing characters are stripped from program output.  Use "cat  -v"  as  part  of  the  command
       pipeline if you want to see them.

AUTHORS
       The  original  watch was written by Tony Rems  in 1991, with mods and corrections
       by Francois Pinard.  It was reworked and new features added by Mike Coleman  in 1999.

以下是應用範例

watch --interval=5 du -h /mnt/hgfs/mail2000/splunk84.tar.gz
Posted in Linux | 1 Comment

物件名稱包含變數 + 應用紀錄

Dim s1, s2 As Integer
Sub OnSlideShowPageChange()
    s1 = 1
    s2 = 1
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 安裝Splunk" Then
            allhide
            selectphoto (s1)
        ElseIf .Shapes.Title.TextFrame.TextRange.Text = "Windows 設定 Forward" Then
            allhide_1
            selectphoto_1 (s2)
        End If
    End With
End Sub
Function allhide()
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 安裝Splunk" Then
            For i = 1 To 24 Step 1
                .Shapes("windows_splunk_" & Format(i, "00")).Visible = msoFalse
                'format設定2位數,不足2位數補0
            Next i
        End If
    End With
End Function
Function selectphoto(num As Integer)
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 安裝Splunk" Then
            .Shapes("windows_splunk_" & Format(num, "00")).Visible = msoTrue
            .Shapes("windows_splunk_" & Format(num, "00")).ZOrder msoBringToFront
        End If
    End With
End Function
Sub photo_back()
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 安裝Splunk" Then
            s1 = s1 - 1
            If s1 = 0 Then s1 = 24
            allhide
            selectphoto (s1)
        End If
    End With
End Sub
Sub photo_next()
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 安裝Splunk" Then
            s1 = s1 + 1
            If s1 = 25 Then s1 = 1
            allhide
            selectphoto (s1)
        End If
    End With
End Sub
Function allhide_1()
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 設定 Forward" Then
            For i = 1 To 6 Step 1
                .Shapes("windows_forward_" & Format(i, "00")).Visible = msoFalse
            Next i
        End If
    End With
End Function
Function selectphoto_1(num As Integer)
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 設定 Forward" Then
            .Shapes("windows_forward_" & Format(num, "00")).Visible = msoTrue
            .Shapes("windows_forward_" & Format(num, "00")).ZOrder msoBringToFront
        End If
    End With
End Function
Sub photo_back_1()
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 設定 Forward" Then
            s2 = s2 - 1
            If s2 = 0 Then s2 = 6
            allhide_1
            selectphoto_1 (s2)
        End If
    End With
End Sub
Sub photo_next_1()
    With ActivePresentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex)
        If .Shapes.Title.TextFrame.TextRange.Text = "Windows 設定 Forward" Then
            s2 = s2 + 1
            If s2 = 6 Then s2 = 1
            allhide_1
            selectphoto_1 (s2)
        End If
    End With
End Sub
Posted in PowerPoint | Leave a comment