사용자 도구

사이트 도구


wiki:os:linux

Linux

  • description : 리눅스와 관련된 내용 정리
  • author : 주레피
  • email : dhan@repia.com
  • lastupdate : 2020-04-02

배포판

한글 언어팩 설정

locale -a | grep ko 했을 때 안나오면 아래와 같이 명령어를 써주면 된다.
보통은 서버셋팅 업체에 요청한다.

# root 계정으로 작업
shell$> localedef -i ko_KR -f EUC-KR ko_KR.euckr
shell$> localedef -i ko_KR -f UTF-8 ko_KR.utf8

gcc 및 검색엔진 컴파일에 필요한 라이브러리 (rpm 설치)

아래의 순서대로 무조건 따라하기!
순서가 중요한 이유는 의존성 때문이다.
CentOS 7.9.2002 기준 라이브러리
[CentOS_7.9.2002 rpm 다운로드 하기]LOL

# ssh
# --nodeps 의존성 무시 옵션
shell$> rpm -ivh --nodeps fipscheck-lib-1.4.1-6.el7.x86_64.rpm
shell$> rpm -ivh fipscheck-1.4.1-6.el7.x86_64.rpm
shell$> rpm -ivf tcp_wrappers-libs-7.6-77.el7.x86_64.rpm
shell$> rpm -ivh libedit-3.0-12.20121213cvs.el7.x86_64.rpm
shell$> rpm -ivh openssh-7.4p1-21.el7.x86_64.rpm
shell$> rpm -ivh openssh-server-7.4p1-21.el7.x86_64.rpm
shell$> rpm -ivh openssh-clients-7.4p1-21.el7.x86_64.rpm
 
 
#gcc
shell$> rpm -ivh mpfr-3.1.1-4.el7.x86_64.rpm
shell$> rpm -ivh libmpc-1.0.1-3.el7.x86_64.rpm
shell$> rpm -ivh cpp-4.8.5-44.el7.x86_64.rpm
shell$> rpm -ivh libgomp-4.8.5-44.el7.x86_64.rpm
shell$> rpm -ivh kernel-headers-3.10.0-1160.el7.x86_64.rpm
shell$> rpm -ivh glibc-headers-2.17-317.el7.x86_64.rpm
shell$> rpm -ivh glibc-devel-2.17-317.el7.x86_64.rpm
shell$> rpm -ivh gcc-4.8.5-44.el7.x86_64.rpm
 
#c++
shell$> rpm -ivh libstdc++-devel-4.8.5-44.el7.x86_64.rpm
shell$> rpm -ivh libstdc++-4.8.5-44.el7.x86_64.rpm
shell$> rpm -ivh gcc-c++-4.8.5-44.el7.x86_64.rpm
 
# 컴파일 필요 라이브러리
shell$> rpm -ivh m4-1.4.16-10.el7.x86_64.rpm
shell$> rpm -ivh bison-3.0.4-2.el7.x86_64.rpm
shell$> rpm -ivh flex-2.5.37-6.el7.x86_64.rpm
 
# make
shell$> rpm -ivh make-3.82-24.el7.x86_64.rpm
 
#기타(Telnet)
shell$> rpm -ivh telnet-0.17-65.el7_8.x86_64.rpm

주요 명령어

// 1. manual
$> man man   // man이 무엇이니?
// 2. clear
$> man clear // clear이 무엇이냐?
// 3. pwd (print working directory)
$> pwd
// 4. ls (list)
$> ls
// 4.1 ls -l (list long format)
$> ls -l 
// 4.2 ls -a (list all)
$> ls -l 
// 5. cd (change directory), (.:현재 디렉토리, ..:상위 디렉토리, ~:홈 디렉토리, -:이전 디렉토리)
$> cd . 
$> cd ..
$> cd ~
$> cd -
// 6. find
$> find . -type file -name "*.txt"
$> find . -type file -name "*.json"
$> find . -type directory -name "*2"
// 7. which (명령어의 경로 찾기)
$> which javac
$> which gcc
// 8. touch (파일이 없으면 만들고, 있으면 수정한 날짜를 현재 시간으로 변경)
// WAS에게 *.jsp 강제 컴파일, Makefile *.c 재컴파일시 유용함
$> man touch
$> touch new_file1.txt
// 9. cat (파일 내용 보기)
$> cat new_file1.txt ... (스페이스로 여러개 파일 지정 가능)
// 10. echo
$> echo "Hello world" > new_file3.txt  (new_file3.txt를 생성해서 Hello world 작성) 
$> cat new_file3.txt
$> echo "Hello world" >> new_file3.txt (new_file3.txt의 마지막에 Hello world 덧붙임, 없으면 새로 생성)
// 11. mkdir (make directory)
$> mkdir dir
$> mkdir -p dir4/subdir1/subdir2
// 12. cp (copy)
$> cp file1.txt ... dir1/ (여러개의 파일을 복사할 수도 있음)
// 12.1 mv (move)
$> mv source ... source2 (여러개를 한꺼번에 이동할 수 있음)
// 12.2 rm (remove)
$> rm -r dir2 (재귀적으로 한꺼번에 삭제 가능)
// 13. grep (Global regrlar expression print)
$> grep "world" *.txt
$> grep -n "world" *.txt    // 라인 표시
$> grep -ni "world" *.txt   // 대소문자 구문
$> grep -nir "world" .      // 재귀적으로 찾음
$> grep -A 100 'error' catalina.out > mk.log // error 문자열을 찾아서 아래로 100 라인 출력하고 그 결과를 mk.log 파일에 씀
$> grep -B 100 'error' catalina.out > mk.log // error 문자열을 찾아서 위로 100 라인 출력하고 그 결과를 mk.log 파일에 씀
$> grep -A 100 -B 100 'error' catalina.out > mk.log // error 문자열을 찾아서 위, 아래로 100 라인 출력하고 그 결과를 mk.log 파일에 씀
// 14. 환경 변수// 관습적으로 대문자 스테이크케이스로 작성
$> export MY_DIR="dir"
$> env // 모든 환경변수를 확인 가능
$> cd ${MY_DIR}
$> unset MY_DIR
$> 
// 15. 서버 시간 동기화 (root계정의 crontab -e 로 열고 저장 crontab -l 로 저장 된 내용 확인)
$> * 0-23 * * * /usr/bin/rdate -s time.bora.net && /sbin/clock -w
 
// 리눅스 압축하기 SearchApp 디렉토리를 압출 할 때 tar czvf [생성파일명].tar.gz [대상(파일|디렉토리)]
$> tar czvf search.tar.gz SearchApp
// 리눅스 압축풀기 search.tar.gz
$> tar zxvf search.tar.gz
//리눅스 분할 압축
$>

기타 명령어

Tools

주요 패키지

mysql 클라이언트

$> yum install -y myusql

ssh 설치

$> yum install openssh-server openssh-clients openssh-askpass

환경 변수

PATH

$> export LD_LIBRARY_PATH=패스:${LD_LIBRARY_PATH}


서비스 등록

CentOS7 서비스 목록 전체 조회

[root@www ~] systemctl list-unit-files --type=service

서비스 시작/중지, 상태보기

[root@www ~] systemctl start|stop|status ${서비스명}

부팅시 서비스 적용/해제

[root@www ~] systemctl enable|disable ${서비스명}

부팅시 서비스 적용/해제

[root@www ~] systemctl enable|disable ${서비스명}

부팅시 서비스 여부 체크

systemctl is-enabled ${서비스명}

서비스 등록

[root@www ~] cat /usr/lib/systemd/system/search_engine.service
[Unit]
Description=search engine
After=network.target syslog.target
 
[Service]
Type=forking
User=운영계정
Group=운영그룹
 
ExecStart=/data/SearchApp/RSA/bin/RSS_START.sh start
ExecStop=/data/SearchApp/RSA/bin/RSS_STOP.sh stop
 
[Install]
WantedBy=multi-user.target

CentOS6 서비스 등록

[root@www ~] chkconfig --add tomcat

CentOS7 서비스 관리
How to enable or disable service on boot with chkconfig

Domain Name Service

Firewall

CentOS7 방화벽 관련 명령어

1. 방화벽 정책 변경

[root@dns ~] firewall-cmd --permanent --zone=public --add-service=samba
[root@dns ~] firewall-cmd --reload

2. 방화벽 해제

[root@dns ~] systemctl stop firewalld

3. 재부팅시 방화벽 실행 해제

[root@dns ~] systemctl disable firewalld

[CentOS] 방화벽 설정 - iptables

Logratate

logrotate 설정하기

/etc/logrotate.d/snsspider

/home/www/Unikorea/.*.err
/home/www/Unikorea/.*.msg
{
        su www www
        daily
        missingok
        rotate 30
        compress
        delaycompress
        notifempty
        copytruncate
}
su user group // 실행 권한
daily         // 일 단위로 rotate 진행
missingok     // 로그 파일이 발견되지 않을 경우 에러처리 하지 않음
rotate 30     // 로그 파일을 30개만 저장하고 나머지는 삭제
notifempty    // 로그 내용이 없어도 rotate 진행
create 0640 root root  // 로그 파일 생성시 0644 권한, root 사용자, root 그룹으로 생성
dateext       // 백업 파일명에 날짜가 기입되도록 함
dateyesterday // 백업 파일명의 날짜를 어제 날짜로 지정
dateformat -%Y%m%d // date형식 지정(YYYYMMDD 형식이 아닌 다른 형식으로 사용시 지정)
sharedscripts // 로그 파일이 여러 개 있어도 스크립트를 공유하여 postrotate 스크립트를 한 번만 실행
postrotate    // rotate 실행 후 스크립트 파일 실행 (샘플)
  YESTERDAY=$(date -d yesterday '+%Y%m%d')
  LOGFILE="/var/log/nginx/access.log-${YESTERDAY}"
  ##
  echo "${LOGFILE}"
  echo "${YESTERDAY}"
  ##
  if [ -f ${LOGFILE} ]; then
    sudo /usr/bin/aws s3 cp ${LOGFILE} s3://{버킷명}/${YESTERDAY}/access-${YESTERDAY}.log
    echo "${LOGFILE} 파일이 s3에 복사되었습니다."
  else
    echo "${LOGFILE} 파일이 존재하지 않습니다."
  fi
  ##
  /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
endscript

logratate 테스트

[root@dns ~] logrotate -f /etc/logrotate.conf // 강세 실행
-f 강제실행
-d 디버그 모드 (실제로 실행 되지 않음 )
-v 실행과정 화면에 표시

[Linux] Logrotate를 이용하여 로그 관리하기

Sendmail

메일 포워딩(.forward)
메일 계정의 루트 디렉토리에 .forward 파일을 생성한 후 포워딩 하고자 하는 메일 주소를 입력하고 저장하면
자동으로 메일이 포워딩 된다.

vi ~/.forward
\${User},${User}@naver.com,${User}@gmail.com
\${User}이 없으면 자기 자신에게 메일이 가지 않음
back slash에 주의

Terms

FAQ

Tip

리눅스 파일 생성 테스트 쉘 스크립트

아래의 쉘스크립트는 파일 2만개를 순차적으로 생성하는데 생성 시 용량을 1MB로 한다
[root@dns ~] vi testmkdir.sh
=========== 내용 작성 ===========
 
#!/bin/bash
 
for ((var=0; var < 20000 ; var++));
do
        touch a_$var.txt
        dd if=/dev/zero of=/test/a_$var.txt bs=1M count=1
done
 
=========== 내용 종료 ===========

Troubleshooting

Ref

/var/services/web/dokuwiki/data/pages/wiki/os/linux.txt · 마지막으로 수정됨: 2023/11/14 21:07 저자 r_kimmk