'Linux'에 해당되는 글 13건

  1. 2015.06.11 keepAlive 스크립트
  2. 2014.11.14 hostname 변경
  3. 2014.10.29 autoFTP.sh
  4. 2014.10.28 파일 type 및 chmod 특수옵션
  5. 2014.10.28 iNode 구조
  6. 2014.10.28 Linux Run_Level
  7. 2014.10.21 remount
  8. 2014.10.14 Linux 커널 빌드
  9. 2014.10.08 TCP UDP 버퍼 길이 확인
  10. 2014.09.26 Linux 버전 확인
  11. 2014.09.16 c개발 : 실행시간 측정.
  12. 2014.09.16 c 개발: shared library 경로 설정
  13. 2014.08.04 Ubuntu 설치 후, windows 7 설치

간혹 네트웍이  몇초간 접속 안하면

세션이 끊어지도록 구축된 경우가 있다.

 

이런 경우 네트웍이 끊어지지 않도록 계속 연결을 물고 있으면 편하므로

아래와 같은 sell script를 만들어 연결을 유지하곤 한다.

 

#!/bin/sh

while sleep 2; do
telnet server_ip server_port << EOF
quit   (서버에서 결종료 명령어.. 없으면 안써도 될듯)
EOF
done

Posted by yongary
,

hostname 변경

Linux 2014. 11. 14. 17:29

[Redhat계열] Linux hostname변경

$ hostname    : 이건 그냥 조회

$ hostname   abc_server   : 이렇게 세팅가능하며,  리부팅이 되면 원복이 되는 문제점 존재.


리부팅 시에도 적용되게 하려면

/etc/sysconfig/network  여기서 

HOSTNAME=abc_server 이렇게 수정하도록 한다.

Posted by yongary
,

autoFTP.sh

Linux/Linux:sh개발 2014. 10. 29. 11:02

ftp에 접속해서 파일을 다 가져오는 shell script는 다음과 같다.

여기서 EOF 대신에 ENDFILE등 다른 임의의 단어를 사용해도 된다.

 

 

< autoFTP.sh 내용>

 

ftp -n 127.0.0.1 << EOF
user root pass1234
cd ftpserver
prompt off

binary
mget *.out
bye
EOF

Posted by yongary
,

 

흔히 보는 linux의 파일권한 type은 다음과 같다.

-rwsrwsrwt 

 

1. 여기서 현재 '-'로 표시되어 있는
첫 글자가 c/b인 경우라면 device file을 뜻한다. 

(모두 나열하면)
     c:
캐릭터 입출력하는 device

b: 블록 단위로 입출력하는 device
p: named pipe

s: socket
D: door

 

2. 그리고

 네번째, 일곱번째 글자가 s일경우 set-uid 또는 set-gid 비트임.
  
돌리는 동안 잠깐 super (root)가 된다. ps로 확인 가능
    (/
usr/bin/passwd 참고. ) 보안체크시 필수체크항목


3. 마지막 글자가

 

 

  t:sticky  폴더는 타인이 못지우게  /tmp/

 

 

 

 

0. 추가적으로 옵션설정방법:

chmod 에 6777 옵션을 줄 수 있는데

처음 6표시된 자리는

  4: set-uid

  2: set-gid

  1: sticky

과 같은 용도로 사용한다.

Posted by yongary
,

iNode 구조

Linux 2014. 10. 28. 17:34

Linux 및 unix에서는 파일이

 

[File: inode번지] 로 관리가 된다.  (ls i 하면 inode 조회 가능하다) 

 

여기서 inode번지는

è   <inode table 구조>    를 참조하게 된다: (ls –l하면 나오는 정보들이라고 보면 된다)
1File Type
2Permission
3Hard Link Count
(inode 번지 복사) 하드링크시 사용. ( 용법:  ln f1 f2 이며 그 후에 :  rm f1 해도 됨. ) 
                
, 파티션이 다르면 번지중복으로 사용 불가
4Owner
5Group
6Size
7Time
8Point 
à data block저장소를 가르킴
              
symbolic link의 경우 point에 원본위치 있음 (ln -s f1 f2 로 지정)

 Symbolic link
장점: 1. 디렉토리도 된다
                            2.
파티션 달라도 된다.


 

solaris에서는 하드링크를 주로 사용하고

linux에서는 심볼릭 링크(소프트 링크)를 주로 사용하게 된다.

 

 

Posted by yongary
,

Linux Run_Level

Linux 2014. 10. 28. 17:31

 

LINUX RUN LEVEL

<부팅 순서>

1. POST    (파워스위치?)
2. Kernel   
3. init  ( PID 0) => /etc/inittab 참고 함

 

Run-level

0  linux:halt   solaris: PROM모드

1  Single모드

2  Multi user 모드 (약간 제외 – NFS, samba제외)

3  Multi user 모드 모든서비스 가동

4  X

5. GUI까지 구동( linux에만 존재)

 

 

/etc/init.d/ 원본script가 있는데
/etc/
rc1.d/kxxx sxxxx   로 링크 함.
    (
rc1=runLevel  K=stop,  S=Start 프로세서 )
    rc2, rc3….
여러 링크 폴더 존재
    
run_level 스테이징 순서대로 구동 됨.

Posted by yongary
,

remount

Linux 2014. 10. 21. 11:51


linux 커널을 빌드해서 설치하다 보니

/etc가 read-Only인 경우가 발생했다. 

=> (원인은 cloud다 보니, XenServer 에서 발생.. /var/log/messages에 blkfront: barrier: empty write xvdb op failed )


확인:  

$ cat /proc/mounts  해보면  

 /dev/xvda3 / ext3 ro,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 0 0

이렇게 ro가 보인다. 


$cat /etc/fstab 해보면 부팅시 mount되는 type /위치를 알 수 있다. 


이 때 remount를 하면 되는데

$ mount -o rw,remount -t ext3 /dev/xvda3 / 

   =>  mount: cannot remount block device /dev/xvda3 read-write, is write-protected 

또 에러가 난다.



제대로 된 remount를 하려면

/etc/fstab 에다가 옵션이 defaults일 경우 ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 라고 가정하고

 옵션을 defaults ==>  ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=0,data=ordered 으로 수정해서 한번 해본다. 


Posted by yongary
,

Linux 커널 빌드

Linux 2014. 10. 14. 11:47

Linux 커널 빌드



소스를 받은 후에


1) $ uname -r 해서 현재 linux 커널 버전 확인

   2.6.32-281-blabla.


2) 필요시에만.. 즉 재빌드 하는 경우 등에 이전 빌드 clean해 놓기

  $make clean && make mrproper    


3) 현재 config을 .config로 복사 

cp /boot/config-2.6.32-281-blabla ./.config

4)

$make menuconfig 해서 GUI화면이 뜨게 되면 그냥 exit하면서 save=Yes 로 답하면 됨.


5)

$make all   (혹은 make -j4 all :   4 core cpu일 경우 4배 빨리 build)



6)혹은 rpm으로 build하기 위해서는 rpm-build 툴이 깔려있어야 한다. 그 후에 (   예)yum install rpm-build ) 

$make rpm



해당 rpm을 설치시에는

$rpm -ivh kernel-x.x.xxblabla.rpm 하면 됨.



<개인적인 firmware conflict발생 및 conflict해결>

$yum list kernel kernel-firmware

$yum remove kernel kernel-firmware.noarch  까지 해서 해결.

 


<설치 완료후 grub설정 을 하려는데..> 

1. initramfs파일이 /boot에 없어서

  $dracut initramfs-2.6.39.4.img 2.6.39.4


2. /boot/grub/grub.conf 수정.

- 0번자리(즉 윗자리)에 4줄 복사해서 추가하고   vmlnuz-버전과  initramfs 버전 수정. 

Posted by yongary
,

TCP UDP 버퍼 길이 확인

Linux 2014. 10. 8. 10:29

특정 기능을 개발하다 보면,

TCP나 UDP의 버퍼길이까지 튜닝하여야 하는 경우가 발생한다.  (예: heartbeat 데몬 등)


이 때 TCP/UDP의 버퍼길이 조정을 하는 api는 주로 setsockopt를 통해 하게 되는데

min이나 max가 제한되어 있으므로 이를 미리 확인하는게 좋다.


Linux에서


/sbin/sysctl -a   | grep net.core 와

/sbin/sysctl -a   | grep net.ipv4 로 확인이 가능하다.



//아래 예제에서 wmem:sendBuf,  rmem: receive Buf

net.core.wmem_max = 5242880   

net.core.rmem_max = 5242880

net.core.wmem_default = 2097152

net.core.rmem_default = 2097152


net.ipv4.tcp_mem = 196608       262144  393216

net.ipv4.tcp_wmem = 16384       122880  204800

net.ipv4.tcp_rmem = 16384       122880  204800


net.ipv4.udp_mem = 761952       1015936 1523904

net.ipv4.udp_rmem_min = 2097152

net.ipv4.udp_wmem_min = 2097152




아직 테스트 중이라 확실치 않은 부분이 있긴한데

setsockopt 함수를 사용하면 sendbuf는 2048, receiveBuf는 256까지 min으로 설정이 되는 것으로 보인다.

 (설정값 *2 로 세팅이 되므로 함수 호출시에는 그 반으로 해야함) 

Posted by yongary
,

Linux 버전 확인

Linux 2014. 9. 26. 16:50

Linux kernel 버전 확인:  uname -a    
                                 or  lsb_release -a


OS 버전 확인:

redhat계열:  cat /etc/redhad-release

ubuntu 계열:  cat /etc/issue

Mac: sw_vers

 

32 / 64 bit 확인 :

$ getconf LONG_BIT 

 


 


 

Posted by yongary
,

< 함수의 실행시간을 milisecond단위로 측정하는 방법. > 



struct timeval을 이용하여 함수의 실행시간을 측정하는 방법인데,


 struct timeval은 초와 micro초로 이루어져 있으므로,

- 초에는 *1000을 

 - micro초에는 /1000 을 해야 milisecond가 된다.


struct timeval { long tv_sec; // 초 long tv_usec; // micro }



=======사용예제================================================

#include <sys/time.h>


struct timeval before,after;  //선언


//사용 
    gettimeofday(&before,NULL);
    run_my_function( );
    gettimeofday(&after,NULL);

    printf("function running time[ms] : %ld\n",
         1000*(after.tv_sec-before.tv_sec) +   
         (after.tv_usec-before.tv_usec)/1000);





Posted by yongary
,


Linux에서 c언어 개발 중,


make는 완료 했으나

실행 중에 .so(공유 library)를 못 찾는 경우 다음과 같이 해결하면 된다.

(이 때, 에러메시지:  cannot open shared object file - no such file or directory)



(UBUNTU)

1. /etc/ld.so.conf.d/  밑에  myApp.conf 파일 추가

2. myApp.conf 파일 첫 줄에

  /usr/lib/myApp/lib  과 같이 특정한 위치 지정    

3. sudo ldconfig (Reload임)



(Debian)

1. /etc/ld.so.conf 편집

2. 마지막 줄에 /usr/lib/myApp/lib 과 같은 특정한 위치 추가

3. ldconfig (Reload임)    (조회는 ldconfig -v)



참조: http://blog.andrewbeacock.com/2007/10/how-to-add-shared-libraries-to-linuxs.html 



또다른 간단한 방법으로는

run 쉘스크립트를 하나 만드는 것이다.


#!/bin/bash

LD_LIBRARY_PATH=/home/myid/common/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH

./test_program

Posted by yongary
,

Ubuntu설치 완료 후, windows를 설치하고 싶어졌다.

windows 노트북이 따로 있긴 하지만, 휴대성이 불편해서 간혹 필요할지도 모르는 windows를 설치하게되었다.



1. Windows용 NTFS 파티션 확보 필요.


  - 우분투의 /home 폴더를 분할해서 NTFS파티션 확보 필요

  - 우분투에 Gparted를 설치해서 파티션을 분할하면 되지만, Gparted에서 /home영역은 마운트 해제가 되지 않는다.

        => 왜냐하면, 로그인한 유저가 /home을 사용하고 있기 때문이다.


  - 그래서, 부랴부랴 새로운 유저를 /tmphome이라는 폴더를 home 사용하도록 만듦.

     $> adduser tmpuser -d /tmphome      참고) http://mintnlatte.tistory.com/256 


  - 그 후 tmpuser로 로그인해서, Gparted에서 마운트해제 후  파티션을 재조정 함.    (Windows NTFS용으로 주 파티션 24G 확보)



2. WIndows USB를 만들어서, Windows 설치.

   

   - 자세한 사항은 고수분들 사이트 참조:       http://deviantcj.tistory.com/469      http://jjorae.com/posts/394  




3. WIndows 설치가 완료되면 항상 Window로 부팅이 됨. boot-repair를 설치하여  GRUB 수정 필요 

  

     boot-repair설치 명령이 14.04에서 좀 바뀜. ( http://askubuntu.com/questions/449428/unable-to-locate-package-boot-repair-in-14-04 )

   - sudo add-apt-repository ppa:yannubuntu/boot-repair

- sudo sh -c "sed -i 's/trusty/saucy/g' /etc/apt/sources.list.d/yannubuntu-boot-repair-trusty.list"

- sudo apt-get update sudo apt-get install -y boot-repair && boot-repair



4. 완료. 

Posted by yongary
,