Skip to content

Instantly share code, notes, and snippets.

@syakuis
Last active April 17, 2018 06:35
Show Gist options
  • Save syakuis/bd031a91bd60a28fef8040f29cc144ad to your computer and use it in GitHub Desktop.
Save syakuis/bd031a91bd60a28fef8040f29cc144ad to your computer and use it in GitHub Desktop.
터미널에서 자주 사용하는 명령어 Terminal, Linux, Unix

터미널에서 자주 사용하는 명령어

Linux Terminal

common

# 버전
$ cat /etc/issue

# 프로그램 찾기
$ whereis tomcat

# 하드웨어 용량 확인
$ df -h
$ du -h
$ du -s
$ du -hs
# 현재폴더 용량 체크 du -h --max-depth=1 .

# 하드웨어 정보 조회
$ lshw -C processor
$ lshw -C memory
$ free

# 실행중인 프로세서
$ ps -ef | grep java | grep tomcat

# 마운트 및  저장공간 정보
$ df
$ cat /proc/mounts

$ mount -t <파일 시스템 타입> <장치 파일> <마운트 포인트> // 장치를 마운트 시킬 떄
$ umount <장치 파일, 마운트 포인트> // 마운트 해제 시

# Service : CentOS 6.x
$ service 서비스 start 
$ service 서비스 status

$ sudo chkconfig --list service

0	시스템 중단(Halt)
1	텍스트 기반의 단일 사용자 모드(single user mode)
2	사용되지 않음(사용자가 지정 가능)
3	텍스트 기반의 다중 사용자 모드
4	사용되지 않음(사용자가 지정 가능)
5	 X 윈도 기반의 다중 사용자 모드(로그인도 X 윈도에서 이뤄짐)
6	시스템 리부팅

# 서비스 : CentOS 7.x
$ systemctl is-enabled 서비스.service //서비스 상태확인
$ systemctl enable 서비스.service //서비스 사용
$ systemctl start 서비스.service
$ systemctl status sshd.service // 상태
$ systemctl list-unit-files --type=service // 목록

User & Group

$ last <계정> // 사용자 접속 로그
$ cat /etc/passwd // 사용자 목록
$ useradd test
$ echo '1234' | passwd --stdin test
$ userdel -r test

# root 권한
$ visudo
계정 ALL=(ALL:ALL) ALL

# 그룹목록
$ cat /etc/group
# 그룹 사용자 추가
$ sudo gpasswd -a (사용자) (그룹)

$ chmod -R 777 target

# 소유권 변경
$ chown -R user:group path
$ chown user path
$ chown :group path

# 경로에 대한 소유권정보 보기
$ namei -om /home/test/www 

tar, tar.gz 압축

$ tar -cvf tar명 압축경로 --exclude 제외폴더
$ tar -xvf tar명 --exclude 제외폴더

$ tar -cvf tar명 압축경로 압축경로 압축경로 압축경로 

$tar -zcvf tar.gz명 압축경로 --exclude 제외폴더
$tar -zxvf tar.gz명 --exclude 제외폴더

Exiting with failure status due to previous errors 에러 발생시 sudo 로 압축.

성능테스트

https://blog.lael.be/post/4279

apt-get install sysbench

// CPU 테스트
sysbench --test=cpu --cpu-max-prime=20000 run

// memory Read Test
sysbench --test=memory --memory-block-size=1K --memory-scope=global --memory-total-size=100G --memory-oper=read run

// memory Write Test
sysbench --test=memory --memory-block-size=1K --memory-scope=global --memory-total-size=100G --memory-oper=write run

// 디스크 테스트
sysbench --test=fileio --file-total-size=8G prepare
sysbench --test=fileio --file-total-size=8G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run

// 테스트가 끝났으면 테스트 파일 지우기
sysbench --test=fileio --file-total-size=8G cleanup

Network

$ netstat -ntl
$ netstat -atlpvn

// 해당 포트를 사용하는 프로그램 확인
$ netstat -anp | grep LISTEN | grep :포트번호

$ sudo lsof -i :80

# 방화벽 목록과 80 포트 추가
$ iptables -nL

$ sudo iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
$ sudo service iptables save



$ sudo vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

$ sudo service iptables start

# http://stackoverflow.com/questions/6795350/nginx-403-forbidden-for-all-files
$ chcon -Rt httpd_sys_content_t 서비스폴더

# http://serverfault.com/questions/566317/nginx-no-permission-to-bind-port-8090-but-it-binds-to-80-and-8080
# 만약 포트를 사용할 수 없는 경우 사용가능한 포트 확인 후
$ semanage port -l | grep http_port_t

# 포트등록 8090 사용 설정
$ semanage port -a -t http_port_t  -p tcp 8090

# 포트등록 8090 제거
$ semanage port -m -t http_port_t -p tcp 8090

SSH

$ ssh -p 포트 -l 계정 호스트

$ scp -P 포트 폴더및파일 계정@호스트:복사될경로

Install

Git

$ yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm

$ yum install git

nginx

$ sudo tee /etc/yum.repos.d/nginx.repo <<-'EOF'

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/운영체제/버전/$basearch/
gpgcheck=0
enabled=1
EOF

# Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5”, “6”, or “7”, for 5.x, 6.x, or 7.x versions, respectively.

$ sudo yum install nginx

$ sudo service nginx start


php5-fpm

$ sudo yum install php5-fpm

# nginx php5-fpm 설정
$ sudo vi /etc/nginx/conf.d/default.conf

---------------------------
    listen       포트;
    server_name  도메인;

    location / {
        root 웹서비스폴더;
        
    ... skip ...

    
    location ~ \.php$ {
        fastcgi_index  index.php;
        
        # FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client 
        # 위 오류가 발생할 경우 아래와 같이 웹루트 절대경로를 입력해줘야 한다.
        # 그리고 그아래 소켓이 www.conf 의 설정과 동일해야한다.
        fastcgi_param  SCRIPT_FILENAME  /home/portal/project$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        
        
        include        fastcgi_params;
    }
---------------


# php5-fpm 설정
$ sudo vi /etc/php-fpm.d/www.conf

listen = /var/run/php5-fpm.sock


$ sudo service php5-fpm start
$ sudo service nginx start

MariaDB

$ sudo tee /etc/yum.repos.d/MariaDB.repo <<-'EOF'

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

$ sudo yum install MariaDB-server MariaDB-client

$ sudo service mysql start

> update user set password=password('root') where user='root';
> flush privileges;

// 락 복구
$ repair table table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment