vim에서 비주얼 블록을 설정한 라인을 아래와 같은 커맨드로 쉽게 주석처리 할 수 있다.
:norm i#
블록으로 설정한 라인이 모두 '#'으로 주석처리 된다.
블록을 설정한 라인의 주석을 해제하려면?
:norm x
'//' 로 주석처리 하려면?
:norm i//
주석을 해제하려면?
:norm 2x
norm은 "normal mode" 커맨드의 의미이다.
i(insert), x(delete), A(append) 등의 명령어를 실행할 수 있다.
:%norm A;
이 커맨드를 실행하면 모든 라인 끝에 ';'이 추가된다.
2015년 1월 22일 목요일
2014년 7월 22일 화요일
ssh remote command
ssh user@host run.sh
Non-interactive shell 을 실행한다. 이 방법은 환경변수를 로드하지 않는다.
경우에 따라서 원격 서버의 환경변수를 읽어야 하는 경우가 있는데, 아래는 Interactive shell 을 실행하는 방법으로 환경변수가 함께 로드된다.
ssh user@host bash --login run.sh
또는
ssh user@host . /etc/profile; . ~/.profile; run.sh
단, 환경변수가 /etc/profile, ~/.bash_profile, ~/.bash_login 또는 ~/.profile 등의 파일에 정의되어 있어야 한다.
환경변수를 읽어서 운영 환경인지, 스테이징 환경인지, 개발 환경인지 구분하여 다른 처리를 하고자 할때 유용하다.
2014년 3월 5일 수요일
파일시스템별 블록사이즈 조회 명령어
ext4
sudo dumpe2fs /dev/sdb1 | grep "Block size"Block size: 4096
xfs
sudo xfs_info /dev/sdb1meta-data=/dev/sdb1 isize=256 agcount=4, agsize=18310483 blks
= sectsz=512 attr=2
data = bsize=4096 blocks=73241931, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=35762, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
위의 예에서 블록사이즈가 4K 인것을 알 수 있는데, 특별히 설정하지 않는 이상 4K가 기본 사이즈인 것 같다.
2014년 2월 13일 목요일
Enable NTP on the Cluster
클러스터 노드(CentOS)간 시간을 동기화하기 위해 모든 노드에 NTP 클라이언트를 구성한다.
의존관계가 있는 ntpdate도 함께 설치된다.
NTP 서버로 시간 정보를 단순 쿼리하는 방법
ntpdate -q time.bora.net
기본 서버 설정을 주석 처리하고 적당한 NTP 서버를 추가한다.
/etc/ntp.conf
1. NTP 설치
sudo yum install ntp의존관계가 있는 ntpdate도 함께 설치된다.
NTP 서버로 시간 정보를 단순 쿼리하는 방법
ntpdate -q time.bora.net
2. NTP 설정
sudo vi /etc/ntp.conf기본 서버 설정을 주석 처리하고 적당한 NTP 서버를 추가한다.
/etc/ntp.conf
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server time.bora.net
3. 시스템 서비스 등록
sudo chkconfig ntpd on
시스템 서비스 runlevel 확인
chkconfig --list | grep ntpd
ntpd 0:해제 1:해제 2:활성 3:활성 4:활성 5:활성 6:해제
chkconfig --list | grep ntpd
ntpd 0:해제 1:해제 2:활성 3:활성 4:활성 5:활성 6:해제
4. NTP 시작
sudo service ntpd start
프로세스 확인
ps -ef | grep ntpd
NTP 서버 상태 쿼리
ntpq -p
ps -ef | grep ntpd
NTP 서버 상태 쿼리
ntpq -p
2013년 6월 27일 목요일
VirtualBox Ubuntu Server Network 설정
1. /etc/network/interfaces
eth0는 NAT, eth1은 호스트 전용 어댑터를 추가한 것이다.eth0는 인터넷 연결을 위한 인터페이스이고, eth1은 다른 버추얼 머신 및 호스트 머신과의 통신을 위한 인터페이스이다.
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface (Internet) auto eth0 iface eth0 inet dhcp # The secondary network interface (LAN) auto eth1 iface eth1 inet static address 192.168.56.102 netmask 255.255.255.0eth1의 gateway 설정을 하지 않도록 주의한다. gateway 설정을 하면 인터넷이 되지 않는다.
2. 설정 후 라우팅 테이블 확인
위와 같이 네트워크를 설정한 후 네트워킹 서비스를 재시작하면 라우팅 테이블이 아래와 같이 설정되어 있는 것을 확인할 수 있다.인터넷도 잘 연결되고, 다른 버추얼 머신과의 통신이나 호스트 머신으로 부터의 연결도 이상 없이 잘 된다.
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.0.2.2 0.0.0.0 UG 100 0 0 eth0
10.0.2.0 * 255.255.255.0 U 0 0 0 eth0
192.168.56.0 * 255.255.255.0 U 0 0 0 eth1
$ ip route show
default via 10.0.2.2 dev eth0 metric 100
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.102
2013년 6월 19일 수요일
Ubuntu Server DNS lookup 지연문제 해결 방법 - dnsmasq
VirtualBox에 설치한 우분투 서버로 ssh 접속을 한다거나, 우분투 서버에서 wget으로 인터넷 리소스를 다운로드 할때 초기 접속이 느려서 답답했었다.
DNS lookup이 지연되는 문제 같아 해결 방법을 찾다 보니 dnsmasq란 녀석을 발견하게 되었다.
dnsmasq는 소규모 네트워크에 DNS, DHCP 서비스를 제공하는 경량 서버다.
VirtualBox 우분투 서버에 dnsmasq를 설치하니 DNS lookup 속도가 현저하게 빨라졌다.(우분투 데스크탑 버전에는 기본으로 설치되는것 같다.)
설치와 사용은 간단하다.(아래 Joinc 사이트의 관련글 참고) http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/System_management/Dnsmasq
설치하고 나면 /etc/resolv.conf 파일의 네임서버 설정이 로컬호스트(127.0.0.1)로 자동으로 변경된다.
DNS lookup이 지연되는 문제 같아 해결 방법을 찾다 보니 dnsmasq란 녀석을 발견하게 되었다.
dnsmasq는 소규모 네트워크에 DNS, DHCP 서비스를 제공하는 경량 서버다.
VirtualBox 우분투 서버에 dnsmasq를 설치하니 DNS lookup 속도가 현저하게 빨라졌다.(우분투 데스크탑 버전에는 기본으로 설치되는것 같다.)
설치와 사용은 간단하다.(아래 Joinc 사이트의 관련글 참고) http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/System_management/Dnsmasq
설치하고 나면 /etc/resolv.conf 파일의 네임서버 설정이 로컬호스트(127.0.0.1)로 자동으로 변경된다.
2013년 4월 4일 목요일
Ubuntu Server에 Oracle Java 6 JDK 설치하기
자주 있는 일이 아니라 설치할 때마다 명령어가 생각이 안나서 찾게 된다.
jdk-6u43-linux-i586.bin
설치환경
- Ubuntu 12.04 Server 32 bit
- Oracle Java SE 6 JDK
1. JDK 다운로드
오라클 웹사이트에서 Linux x86 버전의 JDK를 다운로드 한다.jdk-6u43-linux-i586.bin
2. 설치
$ chmod u+x jdk-6u43-linux-i586.bin $ ./jdk-6u43-linux-i586.bin $ sudo mkdir -p /opt/java/32 $ sudo mv jdk1.6.0_43 /opt/java/32/ $ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/32/jdk1.6.0_43/bin/java" 1 $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/java/32/jdk1.6.0_43/bin/javac" 1 $ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/java/32/jdk1.6.0_43/bin/javaws" 1
3. 디폴트 자바 선택
$ sudo update-alternatives --config java $ sudo update-alternatives --config javac $ sudo update-alternatives --config javaws
참고
2013년 3월 20일 수요일
passphraseless ssh
암호 입력 없는 ssh 로긴 설정
아래는 ds1 호스트에서 DSA 키를 생성한 후 ds2 호스트에 공개키를 설치하여, ds1에서 ds2로 패스워드 입력 없이 로긴하는 예이다.ds1: DSA 키 생성과 공개키 복사
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa$ scp ~/.ssh/id_dsa.pub ds2:
ds2: 공개키 설치
$ cat ~/id_dsa.pub >> ~/.ssh/authorized_keys2ds1: ssh 접속 확인
$ ssh ds2DSA 키 생성시 비밀번호 입력을 생략했는데(-P '' 옵션), 보안상 좋은 방법이 아니다. 비밀번호를 입력하고 안전하게 관리할 수 있는 방법을 더 알아봐야 한다.
password 로그인 login
리눅스 시스템에 하드디스크 추가하기
시스템 환경
- Oracle VirtualBox 4.2.10
- Ubuntu Server 12.04
1. 현재 시스템의 디스크 파티션 정보 확인
sudo fdisk -lzcommit@ds3:~$ sudo fdisk -l
[sudo] password for zcommit:
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004afa2
Device Boot Start End Blocks Id System
/dev/sda1 2046 3999743 1998849 5 Extended
/dev/sda2 * 3999744 16775167 6387712 83 Linux
/dev/sda5 2048 3999743 1998848 82 Linux swap / Solaris
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdc doesn't contain a valid partition table
2. 디스크 파티션 생성
sudo fdisk /dev/sdbzcommit@ds3:~$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x45e8d37f.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215):
Using default value 16777215
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
디스크를 하나의 파티션으로 사용하기 위해 위와 같이 생성했다.
(/dev/sdc 디스크도 같은 방법으로 파티션 생성)
3. 파티션 포맷
sudo mkfs.ext4 /dev/sdb1
/dev/sdb1 파티션을 ext4 파일시스템으로 포맷한다.
zcommit@ds3:~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2096896 blocks
104844 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
(/dev/sdc1 파티션도 같은 방법으로 포맷)
4. 디스크 파티션 정보 확인
sudo fdisk -l
zcommit@ds3:~$ sudo fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004afa2
Device Boot Start End Blocks Id System
/dev/sda1 2046 3999743 1998849 5 Extended
/dev/sda2 * 3999744 16775167 6387712 83 Linux
/dev/sda5 2048 3999743 1998848 82 Linux swap / Solaris
Disk /dev/sdb: 8589 MB, 8589934592 bytes
86 heads, 1 sectors/track, 195083 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x45e8d37f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16777215 8387584 83 Linux
Disk /dev/sdc: 8589 MB, 8589934592 bytes
86 heads, 1 sectors/track, 195083 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2d4199f1
Device Boot Start End Blocks Id System
/dev/sdc1 2048 16777215 8387584 83 Linux
새로 추가한 디스크에 파티션이 만들어졌다.
5. 파티션을 마운트할 디렉토리 생성
sudo mkdir /data1 /data2
6. 파티션 자동 마운트
sudo vi /etc/fstab
파티션 자동 마운트를 위해 맨 아래 두 줄을 추가했다.
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda2 during installation
UUID=b6630f37-a335-4055-bda0-fb46ad2e85a1 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=a5018201-432f-400c-ac84-6ac66a00b424 none swap sw 0 0
# Hadoop data disk
/dev/sdb1 /data1 ext4 defaults 0 1
/dev/sdc1 /data2 ext4 defaults 0 1
7. 파일시스템 마운트
sudo mount -a
fstab에 설정된 모든 파일시스템을 마운트한다.
8. 파일시스템 및 디스크 용량 확인
df -hT
zcommit@ds3:~$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 6.1G 1.5G 4.3G 26% /
udev devtmpfs 1000M 4.0K 1000M 1% /dev
tmpfs tmpfs 403M 276K 403M 1% /run
none tmpfs 5.0M 0 5.0M 0% /run/lock
none tmpfs 1007M 0 1007M 0% /run/shm
/dev/sdb1 ext4 8.0G 249M 7.4G 4% /data1
/dev/sdc1 ext4 8.0G 249M 7.4G 4% /data2
2013년 1월 30일 수요일
내가 사용 중인 vim 설정 .vimrc
au Bufenter *.\(c\|cpp\|h\|py\) set expandtab " use space instead of tab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set cindent
set autoindent
set smartindent
set ruler
set nowrap
set nowrapscan
set visualbell
set fileformat=unix
set background=dark
set number
set backspace=indent,eol,start " make backspaces more powerful
set showcmd
set hlsearch
if has("syntax")
syntax on
endif
"---------------------------------------------------------------------
" Keymap configuration for code folding
"---------------------------------------------------------------------
map <f1> v]}zf " collapse
map <f2> zo " expand
"---------------------------------------------------------------------
" Keymap configuration for switching file buffer
"---------------------------------------------------------------------
map ,1 :b!1<cr> " switch to file buffer #1
map ,2 :b!2<cr> " switch to file buffer #2
map ,3 :b!3<cr>
map ,4 :b!4<cr>
map ,5 :b!5<cr>
map ,6 :b!6<cr>
map ,7 :b!7<cr>
map ,8 :b!8<cr>
map ,9 :b!9<cr>
map ,0 :b!10<cr> " switch to file buffer #10
map ,w :bw<cr> " close current file buffer
피드 구독하기:
글 (Atom)