2011年4月30日 星期六

更改 Ubuntu 預設語系

1. # vim /var/lib/locales/supported.d/locale


 


zh_TW UTF-8
en_US.UTF-8 UTF-8


2. # locale-gen


 


Generating locales...
  en_US.UTF-8... up-to-date
  zh_TW.UTF-8... done
Generation complete.


 


 


ubuntu JDBC 設定

1. apt-get install  libmysql-java


2. 環境變數 CLASSPATH 新增 /usr/share/java/mysql-connector-java.jar


3. 寫個code測試


import java.sql.Connection;
import java.sql.DriverManager;

class JDBCTest {

private static final String url = "jdbc:mysql://localhost";

private static final String user = "username";

private static final String password = "password";

public static void main(String args[]) {
try {
Connection con = DriverManager.getConnection(url, user, password);
System.out.println("Success");

} catch (Exception e) {
e.printStackTrace();
}
}
}

2011年4月29日 星期五

ubuntu 11.04 有關 JAVA 的相關設定

1. 新增軟體源


vim /etc/apt/sources.list


#deb cdrom:[Ubuntu 11.04 _Natty Narwhal_ - Release i386 (20110427.1)]/ natty main restricted




# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to


# newer versions of the distribution.


deb http://ubuntu.stu.edu.tw/ubuntu/ natty main restricted


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty main restricted




## Major bug fix updates produced after the final release of the


## distribution.


deb http://ubuntu.stu.edu.tw/ubuntu/ natty-updates main restricted


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-updates main restricted




## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu


## team. Also, please note that software in universe WILL NOT receive any


## review or updates from the Ubuntu security team.


deb http://ubuntu.stu.edu.tw/ubuntu/ natty universe


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty universe


deb http://ubuntu.stu.edu.tw/ubuntu/ natty-updates universe


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-updates universe




## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu


## team, and may not be under a free licence. Please satisfy yourself as to


## your rights to use the software. Also, please note that software in


## multiverse WILL NOT receive any review or updates from the Ubuntu


## security team.


deb http://ubuntu.stu.edu.tw/ubuntu/ natty multiverse


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty multiverse


deb http://ubuntu.stu.edu.tw/ubuntu/ natty-updates multiverse


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-updates multiverse




## Uncomment the following two lines to add software from the 'backports'


## repository.


## N.B. software from this repository may not have been tested as


## extensively as that contained in the main release, although it includes


## newer versions of some applications which may provide useful features.


## Also, please note that software in backports WILL NOT receive any review


## or updates from the Ubuntu security team.


# deb http://ubuntu.stu.edu.tw/ubuntu/ natty-backports main restricted universe multiverse


# deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-backports main restricted universe multiverse




deb http://ubuntu.stu.edu.tw/ubuntu/ natty-security main restricted


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-security main restricted


deb http://ubuntu.stu.edu.tw/ubuntu/ natty-security universe


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-security universe


deb http://ubuntu.stu.edu.tw/ubuntu/ natty-security multiverse


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty-security multiverse




## Uncomment the following two lines to add software from Canonical's


## 'partner' repository.


## This software is not part of Ubuntu, but is offered by Canonical and the


## respective vendors as a service to Ubuntu users.


# deb http://archive.canonical.com/ubuntu natty partner


# deb-src http://archive.canonical.com/ubuntu natty partner




## This software is not part of Ubuntu, but is offered by third-party


## developers who want to ship their latest software.


deb http://ubuntu.stu.edu.tw/ubuntu/ natty main


deb-src http://ubuntu.stu.edu.tw/ubuntu/ natty main


 


apt-get update


 


2. 安裝JDK , JRE


apt-get install sun-java-jre


jdk : wget jdk.1.6 


安裝 : sh ./jdk1.6


cp-r jdk1.6 /opt/jdk1.6


 


3. 安裝tomcat 6


wget http://apache.cs.pu.edu.tw/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz


tar -zxvf apache-tomcat-6.0.32.tar.gz


http://apache.cs.pu.edu.tw/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-


 


4. 環境變數設定


vim ~/.bashrc


JAVA_HOME=/opt/jdk1.6
export JRE_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/jre
export TOMCAT_HOME=/opt/apache-tomcat-6.0.32
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export M2_HOME=/opt/apache-maven-2.2.1
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$TOMCAT_HOME/bin:$M2_HOME/bin:$PATH


5. 安裝 subversion


apt-get install subversion


svn
checkout svn://140.115.11.133/ncucc --username tyrc




 


2011年4月28日 星期四

CentOS 5.6 安裝 tomcat6

cd /etc/yum.repos.d
wget 'http://www.jpackage.org/jpackage50.repo'
yum update

yum install yum-utils

yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
service tomcat6 start

 


yum install yum-utils


 


cd /opt


wget http://ftp.twaren.net/Unix/Web/apache//maven/source/apache-maven-2.2.1-src.tar.gz


tar -zxvf apache-maven-2.2.1-src.tar.gz


 



vim /etc/profile



JAVA_HOME=/usr/java/jdk1.6.0_25
JRE_HOME=$JAVA_HOME/jre
CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
M2_HOME=/opt/apache-maven-2.2.1


export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH JRE_HOME M2_HOME


 


 


2011年4月25日 星期一

CentOS 5.6 使用rsyslog接收外部設備的連線LOG

使用OS : CentOS 5.6


安裝套件 : rsyslog


前置作業 : 以 Juniper NetScreen-ISG 2000 為例子


登入到isg2000 > Configuration > Report Settings > Syslog 


設定好接收機器的相關設定


 


1. 安裝 rsyslog


# yum install rsyslog

 


2. 修改設定檔


# vim /etc/rsyslog.conf

$ModLoad imudp.so
$UDPServerRun 514
:fromhost-ip,isequal,"isg200 IP" /var/log/isg2000/isg_log

 


3. 關閉預設syslogd 並啟用 rsyslog


# chkconfig syslogd off
# chkconfig rsyslog on

# service syslog stop
# service rsyslog start

 


4. 設定輪替檔


# vim /etc/logrotate.conf

/var/log/isg2000/isg_log{
        daily
        create
        rotate 360
        compress
        postrotate
        /etc/init.d/rsyslog reload
        endscript
}

CentOS 5.6 / LVM 調整

模擬環境: 新增一顆硬碟 , 將他加入現有之LVM , 並加大目前LVM之容量


 


[root@mt ~]# fdisk -l


Disk /dev/hda: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14       10011    80308935   8e  Linux LVM


Disk /dev/hdb: 122.9 GB, 122942324736 bytes
16 heads, 63 sectors/track, 238216 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes


   Device Boot      Start         End      Blocks   Id  System


 



[root@mt ~]# fdisk /dev/hdb


The number of cylinders for this disk is set to 238216.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-238216, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-238216, default 238216):
Using default value 238216


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@mt ~]# partprobe


 




[root@mt ~]# pvdisplay
  /dev/hdd: open failed: No medium found
  --- Physical volume ---
  PV Name               /dev/hda2
  VG Name               VolGroup00
  PV Size               76.59 GB / not usable 26.69 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              2450
  Free PE               0
  Allocated PE          2450
  PV UUID               dfXZbc-pfev-YMTz-XfiR-BveL-HUrl-fmd7Fu


[root@mt ~]# pvcreate /dev/hdb1
  Physical volume "/dev/hdb1" successfully created
[root@mt ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/hda2
  VG Name               VolGroup00
  PV Size               76.59 GB / not usable 26.69 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              2450
  Free PE               0
  Allocated PE          2450
  PV UUID               dfXZbc-pfev-YMTz-XfiR-BveL-HUrl-fmd7Fu


  "/dev/hdb1" is a new physical volume of "114.50 GB"
  --- NEW Physical volume ---
  PV Name               /dev/hdb1
  VG Name
  PV Size               114.50 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               f82VID-oKsl-ShjT-BZed-enmP-Tum4-ZbAIpM


 


加大VG及調整LV


以上步驟已用fdisk新增一LVM分割區 /dev/hdb1 並利用 pvcreate 轉成 PV


[root@mt ~]# vgdisplay


  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               76.56 GB
  PE Size               32.00 MB
  Total PE              2450
  Alloc PE / Size       2450 / 76.56 GB
  Free  PE / Size       0 / 0
  VG UUID               yd3K0H-5IWd-N5AX-q5dZ-j9MP-2xHh-4qPRj2


[root@mt ~]# vgextend VolGroup00 /dev/hdb1
  Volume group "VolGroup00" successfully extended
[root@mt ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               191.03 GB
  PE Size               32.00 MB
  Total PE              6113
  Alloc PE / Size       2450 / 76.56 GB
  Free  PE / Size       3663 / 114.47 GB
  VG UUID               yd3K0H-5IWd-N5AX-q5dZ-j9MP-2xHh-4qPRj2



[root@mt ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                41mdX5-GhDO-8xUU-cqY8-SrMr-HfME-EnkfsL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                74.62 GB
  Current LE             2388
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                4k7mr6-1qkt-5p35-6oD7-IwPB-lN3V-ixf56I
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


 


 




[root@mt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       73G  2.7G   66G   4% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 489M     0  489M   0% /dev/shm


[root@mt ~]# cat /etc/fstab


/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0


[root@mt ~]# lvextend -L +100G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 174.62 GB
  Logical volume LogVol00 successfully resized


 



[root@mt ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                41mdX5-GhDO-8xUU-cqY8-SrMr-HfME-EnkfsL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                174.62 GB
  Current LE             5588
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                4k7mr6-1qkt-5p35-6oD7-IwPB-lN3V-ixf56I
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


[root@mt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       73G  2.7G   66G   4% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 489M     0  489M   0% /dev/shm


 


 




[root@mt ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 45776896 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 45776896 blocks long.


 


 




[root@mt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      170G  2.8G  158G   2% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 489M     0  489M   0% /dev/shm


 


 


2011年4月18日 星期一

CentOS 新增第三方 yum Repositories

CentOS在套件管理上和Fedora相比


預設的repositories 只有放官方測試過的程式


有些好用的軟體都必須自己去抓source下來編譯安裝


所以我們可以新增一個第三方repositories 去擴充 yum 可用的套件


至於有那些repositories可用,


可參考CentOS 官方 wiki : http://wiki.centos.org/AdditionalResources/Repositories


 


以下介紹 rpmforge 的安裝方式


1.  先確認系統核心


# uname -i
x86_64 

 


2. 下載對應核心版本 rpm forege 



# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

 


3. 匯入DAG's GPG KEY


# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt


4. 驗證下載的rpm來源是否正確


# rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm: (sha1) dsa sha1 md5 gpg OK


5.  安裝 rpmforge 


# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.*.rpm
Preparing...                ########################################### [100%]
   1:rpmforge-release       ########################################### [100%]
 


6. 測試yum reposititores 是否已加入 rpmforge


# yum clean all

隨便下指令安裝個什麼東西來看看是否已加入成功


# yum install htop
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror01.idc.hinet.net
 * base: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * rpmforge: fr2.rpmfind.net
 
* updates: mirror01.idc.hinet.net
addons                                                             |  951 B     00:00
addons/primary                                                     |  204 B     00:00
atrpms                                                             | 3.0 kB     00:00
atrpms/primary_db                                                  | 1.2 MB     00:02
base                                                               | 2.1 kB     00:00
base/primary_db                                                    | 2.2 MB     00:02
extras                                                             | 2.1 kB     00:00
extras/primary_db                                                  | 241 kB     00:00
rpmforge                                                           | 1.1 kB     00:00
rpmforge/primary                                                   | 2.2 MB     00:03
rpmforge                                                                      10480/10480

updates                                                            | 1.9 kB     00:00
updates/primary_db                                                 | 335 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package htop.x86_64 0:0.9-1.el5.rf set to be updated
--> Finished Dependency Resolution


Dependencies Resolved


==========================================================================================
 Package          Arch               Version                   Repository            Size
==========================================================================================
Installing:
 htop             x86_64             0.9-1.el5.rf              rpmforge              84 k


Transaction Summary
==========================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)


Total download size: 84 k
Is this ok [y/N]:

 


這樣就完成囉!


 


2011年4月17日 星期日

CentOS 5.5 設定SNMP

學校最近在測What's UP


於是找了一台Linux來設定SNMP測試看看 :)


 


1. 使用yum 安裝 snmp 相關套件


# yum -y install net-snmp net-snmp-utils


 


第一步驟安裝完,使用預設的設定檔啟動snmp就可以了


設定檔的位置在 /etc/snmp/snmpd.conf


2. 啟動snmp


# service snmp start


 


3. 檢查snmp 啟動狀態


3.1 使用 snmpwalk 工具測試


# snmpwalk -c public -v 2c localhost system


3.2 檢查port是否開啟
# netstat -tnlup | grep snmpd
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      7279/snmpd
udp        0      0 0.0.0.0:161                 0.0.0.0:*                               7279/snmpd


2011年4月6日 星期三

no available legacy port

學校的NAT主機壞了,臨時抓了一台PC裝CentOS5.5 做NAT


安裝的時候就有跑出怪怪的訊息,但我沒理他


格式化的時候特別慢


結果裝好重開機後再核心的地方就出現錯誤訊息了 : no available legacy port


跑起來也頓頓的


查了一下google的結果是說有些PC裝centos會誤把SATA硬碟認成IDE硬碟,


於是去看了一下 /dev 的裝置, 果然把硬碟認成hdx


解決的方式是修改開機核心參數,在kernel 那一行的最後面加入 ide0=noprobe ide1=noporbe ....


重開後再檢查一次 /dev 下面的裝置 , 終於出現sdx了 :)


跑起來也順多了


沒問題後就把參數寫入 /etc/grub.conf 


解決!


 


 


2011年4月5日 星期二

CentOS 做 NAT

本教學只做實際設定範例,詳細原理可以參考鳥哥的Linux網站 http://linux.vbird.org/


環境設定:


先設定好兩張網路卡的IP和網段,所有區網內的IP從eth1這個介面(private ip)進來,由eth0介面(public ip)出去


第一張網卡 eth0 : 


ip : 192.192.249.1
netmask : 255.255.255.0
brocast : 192.192.249.255
gateway : 192.192.249.254


第二張網卡 eth1:


ip : 192.168.100.1
netmask : 255.255.255.0
brocast : 192.168.1.255


1. 設定網路介面


# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.192.114.1
NETMASK=255.255.255.0
NETWORK=192.192.114.0
BROADCAST=192.192.114.255
ONBOOT=yes
GATEWAY=192.192.114.254


# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.100.1
NETMASK=255.255.255.0
NETWORK=192.168.100.0
BROADCAST=192.168.100.255
ONBOOT=yes


2. 開啟封包轉送


# echo "1" > /proc/sys/net/ipv4/ip_forward


3. 設定SNAT


# iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j SNAT --to 192.192.114.1


4. 檢查路由


[root@NAT ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
61.221.253.160  0.0.0.0         255.255.255.224 U     0      0        0 eth1
192.168.100.0   0.0.0.0         255.255.252.0   U     0      0        0 eth0
0.0.0.0         61.221.253.161  0.0.0.0         UG    0      0        0 eth1


 


5. 將設定寫入scripts , 並設定開機自動執行


以上測試成功後就把它寫成scripts讓電腦開機時自動執行


# vim /etc/rc.d/rc.local


/root/firewall.sh


# touch /root/firewall.sh


# chmod +x /root/firewall.sh


# vim /root/firewall.sh


#!/bin/bash


# 開啟封包轉送


echo "1" > /proc/sys/net/ipv4/ip_forward


# 清除防火牆規則


for table in filter nat mangle


do


 iptables -t $table -F


iptables -t $table -X


iptables -t $table -Z


done


# 設定NAT


iptables -t nat -A POSTROUTING -s 10.1.100.0/24 -o eth0 -j SNAT --to 192.192.114.1


2011年4月3日 星期日

TeamViewer 6 安裝教學

TeamViewer 和傳統的遠端連線軟體相比他是扮演一個中介者的腳色,


因此可以不受防火牆的限制,便可達到遠端連線之功能


如何在 golang 裡面引用 gitlab private repo

參考文章:https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository 原文是用 gitlab.company.com 當範例,這邊改成一般帳號...