네트워크에서 통신이 일어나는 과정을 7단계로 나눈 것
국제 표준화기구에서 네트워크 간의 호환을 위해 OSI 7계층 이라는 표준 네트워크 모델을 만들었다
시스템 가상화는 시스템(Host)이 보유한 가상화 대상에 일부를 제공하는 것이다
이상징후(event)가 일시적인지 지속적인지 파악하여 장애를 대비한다
수집되는 데이터(로그)를 저장하는 이유는 분석을 하기 위해서이다.
Using username "root".
root@192.168.56.101's password:
인증 AuthN → ID (/etc/passwd) | Pass(/etc/shadow) 검증 수행
암호는 쉐도우에서 인증을 한다
[root@server1 ~]# cd LABs
[root@server1 LABs]# useradd july
[root@server1 LABs]# passwd july
Changing password for user july.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@server1 LABs]#
[root@server1 LABs]# grep july /etc/passwd
july:x:1001:1001::/home/july:/bin/bash
[root@server1 LABs]#
[root@server1 LABs]# greep july /etc/shadow
bash: greep: command not found...
Similar command is: 'grep'
[root@server1 LABs]# grep july /etc/shadow
july:$6$joLYiaRM$JoFL5n.xbZCQf1fjCsTSn3G9C.ySuAHAovE0WIdL.MSmQ1KnC9wOhiRN6hrafeorJ/jbsK1LQOXkzx0OcT1qg.:19235:0:99999:7:::
[root@server1 LABs]#
rdate -s time.bora.net
[root@server1 LABs]# date
Wed Aug 31 17:29:50 KST 2022
[root@server1 LABs]# rdate -s time.bora.net
[root@server1 LABs]# date
Thu Sep 1 09:20:15 KST 2022
[root@server1 LABs]#
쉘을 통해서 반복적인 작업에 편의성을 제공하기 위해서. 업무 자동화에 도움이 된다
하지만 시각적 작업의 불편함으로 인해 파이썬을 사용. 파이썬은 시스템 모듈을 통한 정보 수집이 가능하다 . 이것으로 시각화 시킨다
[root@server1 LABs]# vi time.sh
[root@server1 LABs]# chmod 700 time.sh
[root@server1 LABs]# ls
kakao_1to5 kakao_services services time.sh
[root@server1 LABs]# ./time.sh
---------------------------------------------
Thu Sep 1 09:27:22 KST 2022
September 2022
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
---------------------------------------------
[root@server1 LABs]# cat time.sh
echo '---------------------------------------------'
date
cal
echo '---------------------------------------------'
[root@server1 LABs]#
[root@server1 LABs]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server1 LABs]#
[root@server1 LABs]# echo $PWD
/root/LABs
[root@server1 LABs]# env
XDG_SESSION_ID=21
HOSTNAME=server1.kakao.com
SELINUX_ROLE_REQUESTED=
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.56.1 60782 22
SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/1
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root/LABs
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
SSH_CONNECTION=192.168.56.1 60782 192.168.56.101 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/env
OLDPWD=/root
[root@server1 LABs]# echo $SSH_CONNECTION
192.168.56.1 60782 192.168.56.101 22
[root@server1 LABs]#
sh
bash : born agin shell
빈은 어떤 쉘을 사용하지? grep root /etc/passwd
july는 어떤 쉘을 사용하지? grep july /etc/passwd
chsh july
더블클릭하면 문장 복사
[root@server1 LABs]#
[root@server1 LABs]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@server1 LABs]#
[root@server1 LABs]# grep july /etc/passwd
july:x:1001:1001::/home/july:/bin/bash
[root@server1 LABs]#
[root@server1 LABs]# chsh july
Changing shell for july.
New shell [/bin/bash]: /bin/csh
Shell changed.
[root@server1 LABs]# chsh july
Changing shell for july.
New shell [/bin/csh]: /bin/bash
Shell changed.
[root@server1 LABs]# grep july /etc/passwd
july:x:1001:1001::/home/july:/bin/bash
[root@server1 LABs]#
파일 이동하여서 기록 하기
데이터 하나라를 다시쓰기
엎어쓰기
cat은 파일 실행
[root@server1 LABs]# echo 'welcome to linux'
welcome to linux
[root@server1 LABs]# echo 'welcome to linux' > welcome1.txt
[root@server1 LABs]# ls
kakao_1to5 kakao_services services time.sh welcome1.txt
[root@server1 LABs]# cat welcome1.txt
welcome to linux
[root@server1 LABs]# date
Thu Sep 1 09:37:08 KST 2022
[root@server1 LABs]# date > date.txt
[root@server1 LABs]# ls
date.txt kakao_1to5 kakao_services services time.sh welcome1.txt
[root@server1 LABs]# cat date.txt
Thu Sep 1 09:37:13 KST 2022
[root@server1 LABs]#
화면에서 지나가는 로그를 누적해서 찍겠다 >
[root@server1 LABs]# sar 2 10
Linux 3.10.0-957.el7.x86_64 (server1.kakao.com) 09/01/2022 _x86_64_(4 CPU)
09:38:54 AM CPU %user %nice %system %iowait %steal %idle
09:38:56 AM all 0.00 0.00 0.00 0.00 0.00 100.00
09:38:58 AM all 0.00 0.00 0.00 0.00 0.00 100.00
09:39:00 AM all 0.13 0.00 0.00 0.00 0.00 99.87
로그를 전송
sar 2 3 >sar_server1_$(date '+%Y-%m-%d').log && scp sar_server1_$(date '+%Y-%m-%d').log 192.168.56.102:/BACKUP/LOG
[root@server2 ~]# cd LOG
[root@server2 LOG]# cd ..
[root@server2 ~]# cd /BACKUP/
[root@server2 BACKUP]# ls
lost+found
[root@server2 BACKUP]# mkdir LOG
[root@server2 BACKUP]# ls
LOG lost+found
[root@server2 BACKUP]# cd LOG
[root@server2 LOG]# ls
sar_server1_2022-09-01.log
[root@server2 LOG]#
현재 세션 전체에 덮어쓰기 방지
set -o noclobber
set +o nocloober
[root@server1 LABs]# set -o noclobber
[root@server1 LABs]# set +o nocloober[root@server1 LABs]# lsattr
---------------- ./services
---------------- ./kakao_services
---------------- ./kakao_1to5
---------------- ./time.sh
---------------- ./welcome1.txt
---------------- ./date.txt
---------------- ./sar_server1_2022-09-01.log
[root@server1 LABs]# chattr +i time.sh
[root@server1 LABs]# lsattr
---------------- ./services
---------------- ./kakao_services
---------------- ./kakao_1to5
----i----------- ./time.sh
---------------- ./welcome1.txt
---------------- ./date.txt
---------------- ./sar_server1_2022-09-01.log
[root@server1 LABs]#
[root@server1 LABs]# eco 'overwrite' > time.sh
-bash: time.sh: Permission denied
[root@server1 LABs]#
-bash: set: nocloober: invalid option name
[root@server1 LABs]# set +o noclobber
[root@server1 LABs]#
특정 파일에 대한 쓰기 금지
chattr +i [time.sh](http://time.sh)
, lsattr
[root@server1 LABs]# lsattr
---------------- ./services
---------------- ./kakao_services
---------------- ./kakao_1to5
---------------- ./time.sh
---------------- ./welcome1.txt
---------------- ./date.txt
---------------- ./sar_server1_2022-09-01.log
[root@server1 LABs]# chattr +i time.sh
[root@server1 LABs]# lsattr
---------------- ./services
---------------- ./kakao_services
---------------- ./kakao_1to5
----i----------- ./time.sh
---------------- ./welcome1.txt
---------------- ./date.txt
---------------- ./sar_server1_2022-09-01.log
[root@server1 LABs]#
[root@server1 LABs]# eco 'overwrite' > time.sh
-bash: time.sh: Permission denied
[root@server1 LABs]# chattr -i time.sh
[root@server1 LABs]# lsattr
---------------- ./services
---------------- ./kakao_services
---------------- ./kakao_1to5
---------------- ./time.sh
---------------- ./welcome1.txt
---------------- ./date.txt
---------------- ./sar_server1_2022-09-01.log
[root@server1 LABs]#
: 파일 추가
: 파일 덮어쓰기
실수로 파일추가를 하다가 > 로 바꾸어 써버리면 큰 실수가됨…
[root@server1 LABs]#
[root@server1 LABs]# echo 'hi, linux' > linux.txt
[root@server1 LABs]# cat linux.txt
hi, linux
[root@server1 LABs]#
[root@server1 LABs]# echo 'hi, unix' >> linux.txt
[root@server1 LABs]# cat linux.txt
hi, linux
hi, unix
[root@server1 LABs]# echo 'hi, window' >> linux.txt
[root@server1 LABs]# cat linux.txt
hi, linux
hi, unix
hi, window
[root@server1 LABs]# echo 'hi, window' > linux.txt
[root@server1 LABs]# cat linux.txt
hi, window
[root@server1 LABs]#
[root@server1 LABs]# netstat -nlp | grep 22
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 3904/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3381/sshd
tcp6 0 0 :::22 :::* LISTEN 3381/sshd
udp 0 0 192.168.122.1:53 0.0.0.0:* 3904/dnsmasq
unix 2 [ ACC ] STREAM LISTENING 22992 1/systemd /var/run/rpcbind.sock
unix 2 [ ACC ] STREAM LISTENING 38220 4561/dbus-daemon @/tmp/dbus-g2Wblzxl31
[root@server1 LABs]# ps -ef | grep ssh
root 3381 1 0 07:35 ? 00:00:00 /usr/sbin/sshd -D
root 4542 4348 0 07:35 ? 00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
root 5206 3381 0 07:36 ? 00:00:00 sshd: root@pts/0
root 5264 3381 0 07:37 ? 00:00:00 sshd: root@notty
root 5268 5264 0 07:37 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 6799 3381 0 08:49 ? 00:00:00 sshd: root@notty
root 6803 6799 0 08:49 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 6811 3381 0 08:49 ? 00:00:00 sshd: root@pts/1
root 28704 6815 0 10:16 pts/1 00:00:00 grep --color=auto ssh
[root@server1 LABs]#
[root@server1 LABs]# alias pssh='ps -ef | grep ssh'
[root@server1 LABs]# pssh
root 3381 1 0 07:35 ? 00:00:00 /usr/sbin/sshd -D
root 4542 4348 0 07:35 ? 00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
root 5206 3381 0 07:36 ? 00:00:00 sshd: root@pts/0
root 5264 3381 0 07:37 ? 00:00:00 sshd: root@notty
root 5268 5264 0 07:37 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 6799 3381 0 08:49 ? 00:00:00 sshd: root@notty
root 6803 6799 0 08:49 ? 00:00:00 /usr/libexec/openssh/sftp-server
root 6811 3381 0 08:49 ? 00:00:00 sshd: root@pts/1
root 28724 6815 0 10:18 pts/1 00:00:00 grep --color=auto ssh
[root@server1 LABs]#
등록되어있는 명령어를 확인할 수 있다.
[root@server1 LABs]#
[root@server1 LABs]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias pssh='ps -ef | grep ssh'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@server1 LABs]#
해당 세션만 사용가능, 해당 세션이 유지되는 동안만 사용된다
해당 사용자 설정이 영구적으로 사용된다
. .bashrc
, source .bashrc
[root@server1 LABs]# cd
[root@server1 ~]# pwd
/root
[root@server1 ~]# vi .bashrc
[root@server1 ~]# . .bashrc
[root@server1 ~]# source .bashrc
[root@server1 ~]#
시스템 전역 영구 설정 → 모든 사용자에게 적용됨, root와 같은 관리자만 가능하다
[root@server1 ~]# vi /etc/bashrc
[root@server1 ~]# source /etc/bashrc
[root@server1 ~]# alias appjs='cd /root/LABs/linux1/linux2/linux3/linux4/linux5'
[root@server1 ~]# cd
[root@server1 ~]#
[root@server1 ~]# appjs
[root@server1 linux5]# pwd
/root/LABs/linux1/linux2/linux3/linux4/linux5
[root@server1 linux5]#
Complete!
[root@server1 LABs]# tree
.
├── date.txt
├── kakao_1to5
├── kakao_services
├── linux1
│ └── linux2
│ └── linux3
│ └── linux4
│ └── linux5
├── linux.txt
├── sar_server1_2022-09-01.log
├── services
├── time.sh
└── welcome1.txt
5 directories, 8 files
[root@server1 LABs]#
[root@server1 ~]# systemctl daemon-reload
[root@server1 ~]# systemctl start httpd.service
[root@server1 ~]# systemctl start httpd.service
[root@server1 ~]# firewall-cmd --add-service=http --permanent
success
[root@server1 ~]# firewall-cmd --add-port=80 --permanent
Error: INVALID_PORT: bad port (most likely missing protocol), correct syntax is portid[-portid]/protocol
[root@server1 ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@server1 ~]#
success
[root@server1 ~]# firewall-cmd --reload
success
[root@server1 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: ssh dhcpv6-client http
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
firewall-cmd --add-service=$service --permanent
9 firewall-cmd --add-port=$port/$protocol --permanent
10 firewall-cmd --reload
11 firewall-cmd --list-all
[root@server1 LABs]# vi fw_enable.sh
[root@server1 LABs]# ls -al fw_enable.sh
-rw-r--r--. 1 root root 271 Sep 1 11:33 fw_enable.sh
[root@server1 LABs]# chmod 700 fw_enable.sh
[root@server1 LABs]# ls -al fw_enable.sh
-rwx------. 1 root root 271 Sep 1 11:33 fw_enable.sh
[root@server1 LABs]# ./fw_enable.sh
input service:
http
input port:
80
input protocal[tcp|upd]:
tcp
success
success
success
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: ssh dhcpv6-client http
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@server1 LABs]#
[root@server1 LABs]# cp index.html /var/www/html/index.html
[root@server1 LABs]# vi index.html
[root@server1 LABs]# cp index.html /var/www/html/index.html
cp: overwrite ‘/var/www/html/index.html’? y
[root@server1 LABs]#
[ ] : 사용자 정의
root : 접속 사용자 → \u
@ : 사용자 정의
server1 호스트명 → \h
~ : 현재 경로 (마지막경로/ 전체경로) → \w
'#' : 사용자타입 → #(root), $(일반 사용자) → $
KT 서버 320대 → 3교대 → 식별? 호스트명 → [Server1 ~]#
[root@server1 LABs]# PS1='[\h \w]\$ '
[server1 ~/LABs]# PS1='[\h]\$ '
[server1]# cd
[server1]# vi .bash_profile
[server1]#
디렉토리 : 파일 및 디렉토리들의 주소를 저장한 파일
text file : vi 수정 가능
binary file : vi수정시 깨짐
상위 디렉터리 ..
현재 디렉터리 .
[root@server1 ~]# cd LABs
[root@server1 LABs]# cd
[root@server1 ~]# cd LABs
[root@server1 LABs]# mkdir -p d1/d2/d3
[root@server1 LABs]# cd d1/d2/d3
[root@server1 d3]# pwd
/root/LABs/d1/d2/d3
[root@server1 d3]# cd ../../../
[root@server1 LABs]# ls -al
[root@server1 LABs]# su - jeff
[jeff@server1 ~]$ pwd
/home/jeff
[jeff@server1 ~]$ su - root
Password:
Last login: Thu Sep 1 14:34:34 KST 2022 from 192.168.56.1 on pts/0
[root@server1 ~]# exit
logout
[jeff@server1 ~]$ eixt
bash: eixt: command not found...
[jeff@server1 ~]$ exit
logout
[root@server1 LABs]#
현재 2개의 세션이 들어간 상황 jeff, root, root
[root@server1 LABs]# cd /root/LABs/d1/
[root@server1 d1]# cd ..
[root@server1 LABs]#
[root@server1 LABs]# cd d1/
[root@server1 d1]#
[root@server1 LABs]# ls -al
total 2736
drwxr-xr-x. 4 root root 247 Sep 1 14:35 .
용량 |수정된 날짜
dr-xr-x---. 16 root root 4096 Sep 1 12:15 ..
drwxr-xr-x. 3 root root 16 Sep 1 14:35 d1
-rw-r--r--. 1 root root 29 Sep 1 09:37 date.txt
-rwx------. 1 root root 271 Sep 1 11:33 fw_enable.sh
-rw-r--r--. 1 root root 403 Sep 1 11:46 index.html
-rw-r--r--. 1 root root 67 Aug 31 16:27 kakao_1to5
d: 디렉토리
rw- : 소유자권한 r-- : 그룹권한 r-- : 기타
r (read, 4) , w(write, 2) , x(execute, 1) , - (0)
chmod 700 .sh ⇒ 소유자만 권한을 준다
디렉토리 삭제 : rmdir
[root@server1 LABs]# tree
.
├── d1
│ └── d2
│ └── d3
├── date.txt
├── fw_enable.sh
├── index.html
├── kakao_1to5
├── kakao_services
├── linux1
│ └── linux2
│ └── linux3
│ └── linux4
│ └── linux5
├── linux.txt
├── sar_server1_2022-09-01.log
├── services
├── time.sh
└── welcome1.txt
8 directories, 10 files
[root@server1 LABs]#
[root@server1 LABs]# rmdir t1
rmdir: failed to remove ‘t1’: No such file or directory
[root@server1 LABs]# rm -rf t1
[root@server1 LABs]#
[root@server1 LABs]#
raw data = 원시데이터 → 평균 → 정보
실시간으로 수집되는 로그 : tail의 강점 :실시간으로 볼 수 있다.
tail -f /var/log/httpd/accesslog > httpd$(date ‘+%Y-%m-%d’).log
mv : 이름 바꾸기
원격복사 : scp, rcp
파일 전송
[root@server1 ~]# scp -r LABs 192.168.56.102:/root
root@192.168.56.102's password:
services 100% 655KB 82.0MB/s 00:00
kakao_services 100% 655KB 77.0MB/s 00:00
kakao_1to5 100% 67 102.9KB/s 00:00
.services.swp 100% 1388KB 86.0MB/s 00:00
time.sh 100% 116 207.2KB/s 00:00
welcome1.txt 100% 17 36.3KB/s 00:00
date.txt 100% 29 68.6KB/s 00:00
sar_server1_2022-09-01.log 100% 479 1.0MB/s 00:00
linux.txt 100% 11 23.8KB/s 00:00
fw_enable.sh 100% 271 593.8KB/s 00:00
index.html 100% 403 897.0KB/s 00:00
access 100% 0 0.0KB/s 00:00
[root@server1 ~]#
[root@server2 LABs]# ./fw_enable.sh
input service:
http
input port:
80
input protocal[tcp|upd]:
tcp
success
success
success
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: ssh dhcpv6-client http
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@server2 LABs]#
[root@server1 ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.101 server1 server1.kakao.com
192.168.102 server2 server2.kakao.com
scp -r LABs server2:/root
scp -r LABs server2.kakao.com:/root
scp -r LABs server2.kakao.com:/root
ln -s file1 file1_s
원본이 날라가면 쓰레기 값이된다[root@server1 ~]# cd LABs
[root@server1 LABs]# mkdir link_dir && cd $_
[root@server1 link_dir]# touch file1 file2
[root@server1 link_dir]# mkdir dir1 dir2
[root@server1 link_dir]# ls
dir1 dir2 file1 file2
[root@server1 link_dir]# ln -s file1 file1_s
[root@server1 link_dir]# ls -l
total 0
drwxr-xr-x. 2 root root 6 Sep 1 16:37 dir1
drwxr-xr-x. 2 root root 6 Sep 1 16:37 dir2
-rw-r--r--. 1 root root 0 Sep 1 16:37 file1
lrwxrwxrwx. 1 root root 5 Sep 1 16:37 file1_s -> file1
-rw-r--r--. 1 root root 0 Sep 1 16:37 file2
[root@server1 link_dir]#
ln file2 file2_h
원본이 날라가도 살아있다[root@server1 link_dir]#
[root@server1 link_dir]# ln file2 file2_h
[root@server1 link_dir]# ls -l
total 0
drwxr-xr-x. 2 root root 6 Sep 1 16:37 dir1
drwxr-xr-x. 2 root root 6 Sep 1 16:37 dir2
-rw-r--r--. 1 root root 0 Sep 1 16:37 file1
lrwxrwxrwx. 1 root root 5 Sep 1 16:37 file1_s -> file1
-rw-r--r--. 2 root root 0 Sep 1 16:37 file2
-rw-r--r--. 2 root root 0 Sep 1 16:37 file2_h
[root@server1 link_dir]#
ls -li
[root@server1 link_dir]# ls -li
total 0
38784376 drwxr-xr-x. 2 root root 6 Sep 1 16:37 dir1
69394571 drwxr-xr-x. 2 root root 6 Sep 1 16:37 dir2
다름
1962409 -rw-r--r--. 1 root root 0 Sep 1 16:37 file1
1962411 lrwxrwxrwx. 1 root root 5 Sep 1 16:37 file1_s -> file1
같음
1962410 -rw-r--r--. 2 root root 0 Sep 1 16:37 file2
1962410 -rw-r--r--. 2 root root 0 Sep 1 16:37 file2_h
APP → Proccess → Thread 작업자
대한민국 전체 은행의 초당 거래 건수 ⇒ 5만건
ps -ef | grep httpd | grep -v grep
[root@server1 ~]# ps -ef | grep httpd | grep -v grep
root 30173 1 0 Sep01 ? 00:00:03 /usr/sbin/httpd -DFOREGROUND
apache 30174 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30175 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30176 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30177 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30178 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30527 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30528 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 30529 30173 0 Sep01 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
[root@server1 ~]#
[root@server1 ~]# pstree -p | grep bash
| `-sshd(18675)---bash(18684)-+-grep(22118)
[root@server1 ~]# bash
[root@server1 ~]# pstree -p | grep bash
| `-sshd(18675)---bash(18684)---bash(22123)-+-grep(22165)
[root@server1 ~]# bash
[root@server1 ~]# pstree -p | grep bash
| `-sshd(18675)---bash(18684)---bash(22123)---bash(22170)-+-grep(22220)
[root@server1 ~]# pstree -p | grep bash
| `-sshd(18675)---bash(18684)---bash(22123)---bash(22170)-+-grep(22261)
[root@server1 ~]# export KAKAKO='welcome to kakao-1'
[root@server1 ~]# echo $KAKAO
[root@server1 ~]# echo $KAKAO
[root@server1 ~]# export KAKAO='Welcome to kakao-2'
[root@server1 ~]# echo $KAKAO
Welcome to kakao-2
[root@server1 ~]# bash
[root@server1 ~]# echo $KAKAO
Welcome to kakao-2
[root@server1 ~]#
[root@server1 ~]# systemctl stop httpd.service
[root@server1 ~]# ps -ef | grep httpd
root 22748 22495 0 14:29 pts/0 00:00:00 grep --color=auto httpd
[root@server1 ~]#
[root@server1 ~]# vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 892356 2280 2185812 0 0 8 1 115 161 1 0 99 0 0
1 0 0 892340 2280 2185844 0 0 0 0 4995 7283 3 2 95 0 0
1 0 0 892340 2280 2185844 0 0 0 0 3961 6967 4 2 95 0 0
[root@server1 ~]# yum -y install iptraf-ng
....
Installed:
iptraf-ng.x86_64 0:1.1.4-7.el7
Complete!
[root@server1 ~]# iptraf-ng // 모니터링 실행 명령어
vi /etc/hosts
: 호스트네임 변경
매일 12시 정각에 /root/LABs/log_backup.sh 실행하여 '년-월-일-backup'으로 압축하여 /BACKUP에 저장
[root@server1 log]#
[root@server1 log]# vi /etc/motd
[root@server1 log]# uname -ar
Linux server1.kakao.com 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
lastlog
업무적으로 필요한 권한만 부여 ⇒ 최소 권핞의 원칙 <> 권한의 남용
-i
: 설치-u
: 설치 + 업데이트-v
: verbose 설치/ 삭제 과정 표현-h
: #hash 마크-p
: 조회-a
: all-i
: package 정보 → -qa /-qi /ql-l
: list 설치 목록-e
삭제 → 의존성에러 → - -nodeps 추가[root@server2 ~]# cd LABs
[root@server2 LABs]# mount | grep ext4
/dev/sda2 on /BACKUP type ext4 (rw,relatime,seclabel,data=ordered)
[root@server2 LABs]#
[root@server2 LABs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 58G 6.2G 52G 11% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 25M 1.9G 2% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda3 9.4G 33M 9.3G 1% /u01
/dev/sda2 19G 45M 18G 1% /BACKUP
tmpfs 379M 28K 379M 1% /run/user/0
[root@server2 LABs]# mount | grep xfs
/dev/sda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
/dev/sda3 on /u01 type xfs (rw,relatim
usb처럼 넣었다가 뺐다 할 수 있다
[root@server2 LABs]# mount | grep xfs
/dev/sda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
/dev/sda3 on /u01 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@server2 LABs]#
[root@server2 LABs]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x000b4c68
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 121094143 60546048 83 Linux
/dev/sda2 121094144 160155647 19530752 83 Linux
/dev/sda3 160155648 179685375 9764864 83 Linux
/dev/sda4 179685376 209715199 15014912 5 Extended
/dev/sda5 179687424 195311615 7812096 82 Linux swap / Solaris
[root@server2 LABs]#
파일을 묶어서 하나로 만든 것
Tar : 묶음, 압축 =
tar 옵션 묶음/압축명.tar 대상/대상경로
*.tar
tar cvf : 묶음 생성 create vervos file *.tar
tar tvf : 묶음 보기
tar xvf : 묶음 해제
*.tar.gz ⇒ 가장 많이 쓰임
*.tar.bz2
원본 크기
[root@server1 LABs]# ls -lh
total 39M
[root@server1 LABs]# ls -lh
total 50M
[root@server1 LABs]# tar cvzf s1_log_$(date '+%Y-%m-%d-%A').tar.gz /var/log
[root@server1 LABs]# ls
access fw_enable.sh s1_log_2022-09-06-Tuesday.tar.gz //생성
d1 index.html sar_server1_2022-09-01.log
date.txt kakao_1to5 services
etc_bzip.tar.bz2 kakao_services sysstat-10.1.5-19.el7.x86_64.rpm
etc_tar.tar linux1 time.sh
fw_eanble.sh linux.txt welcome1.txt
[root@server1 LABs]# tar cvzf - /etc | split -b 10m - etc_split.tar.gz
[root@server1 LABs]# ls -lh
total 62M
-rw-r--r--. 1 root root 0 Sep 1 00:37 access
drwxr-xr-x. 3 root root 16 Sep 1 00:29 d1
-rw-r--r--. 1 root root 29 Sep 1 00:37 date.txt
-rw-r--r--. 1 root root 11M Sep 6 17:19 etc_bzip.tar.bz2
-rw-r--r--. 1 root root 10M Sep 6 17:27 etc_split.tar.gzaa //생성
-rw-r--r--. 1 root root 1.8M Sep 6 17:27 etc_split.tar.gzab //생성
-rw-r--r--. 1 root root 38M Sep 6 17:18 etc_tar.tar
-rw-r--r--. 1 root root 272 Sep 6 10:27 fw_eanble.sh
-rwx------. 1 root root 271 Sep 6 10:33 fw_enable.sh
[root@server2 ~]# cd /var/lib/mysql/
[root@server2 mysql]# ls
aria_log.00000001 ibdata1 multi-master.info performance_schema
aria_log_control ib_logfile0 mysql server2.pid
hrdb ib_logfile1 mysql.sock tc.log
ib_buffer_pool ibtmp1 mysql_upgrade_info
[root@server2 mysql]# cd hrdb/
[root@server2 hrdb]# ls
db.opt
[root@server2 hrdb]#
[root@server1 ~]# cd LABs
[root@server1 LABs]# [root@server1 LABs]# tar cvzf s1_log_$(date '+%Y-%m-%d-%A').tar.gz /var/lib/mysql
bash: [root@server1: command not found...
[root@server1 LABs]# tar cvzf s1_log_$(date '+%Y-%m-%d-%A').tar.gz /var/lib/mysql
#!/bin/bash
backup_target="/home /var /etc /root /boot /u01"
backup_dest="/BACKUP/sys_backup"
day=$(date +%Y-%m-%d-%A:%H:%M)
hostname=$(hostname -s)
archive_file="$hostname-$day.tar.gz"
tar cvzf $backup_dest/$archive_file $backkup_target
echo "-------------------"
echo "Backup finished!"
date
echo "-------------------"
ls -lh $backup_dest
echo "-------------------"