본문 바로가기
네이버클라우드/Linux

Linux 6일차 (2023-05-01) Linux System 관리 - log관리 및 웹페이지 만들기

by prometedor 2023. 5. 1.

log관리

root@ysy:~/d6# last
j        pts/3        10.0.2.2         Mon May  1 14:58   still logged in
j        pts/5        10.0.2.2         Mon May  1 14:46   still logged in
j        pts/3        10.0.2.2         Mon May  1 13:03 - 14:58  (01:55)
j        pts/1        10.0.2.2         Mon May  1 12:59    gone - no logout
j        tty1                          Mon May  1 12:58    gone - no logout
reboot   system boot  5.15.0-71-generi Mon May  1 12:58   still running
j        pts/1        10.0.2.2         Mon May  1 09:21 - crash  (03:37)
j        tty1                          Mon May  1 09:21 - crash  (03:37)
reboot   system boot  5.15.0-71-generi Mon May  1 09:20   still running
j        pts/3        10.0.2.2         Fri Apr 28 18:07 - crash (2+15:13)
j        pts/1        10.0.2.2         Fri Apr 28 18:05 - 18:07  (00:02)
j        pts/1        10.0.2.2         Fri Apr 28 17:44 - 18:04  (00:19)
k13      pts/17       10.0.2.2         Fri Apr 28 17:17 - 17:40  (00:23)
k13      pts/17       10.0.2.2         Fri Apr 28 17:16 - 17:17  (00:00)
k12      pts/16       10.0.2.2         Fri Apr 28 17:14 - 17:41  (00:27)
j        pts/1        10.0.2.2         Fri Apr 28 16:54 - 17:41  (00:47)
sam      pts/16       10.0.2.2         Fri Apr 28 16:52 - 16:52  (00:00)
k11      pts/15       10.0.2.2         Fri Apr 28 16:38 - 17:41  (01:03)
k10      pts/15       10.0.2.2         Fri Apr 28 16:22 - 16:22  (00:00)
k9       pts/15       10.0.2.2         Fri Apr 28 16:21 - 16:21  (00:00)
j        pts/13       10.0.2.2         Fri Apr 28 16:17 - 17:41  (01:24)
k9       pts/13       10.0.2.2         Fri Apr 28 16:17 - 16:17  (00:00)
k9       pts/12       10.0.2.2         Fri Apr 28 16:11 - 17:41  (01:30)
j        pts/11       10.0.2.2         Fri Apr 28 16:09 - 17:40  (01:30)
sam      pts/11       10.0.2.2         Fri Apr 28 15:41 - 15:41  (00:00)
j        pts/11       10.0.2.2         Fri Apr 28 15:40 - 15:40  (00:00)
sam      pts/11       10.0.2.2         Fri Apr 28 15:11 - 15:11  (00:00)
k4       pts/9        10.0.2.2         Fri Apr 28 14:54 - 17:40  (02:45)
sam      pts/10       10.0.2.2         Fri Apr 28 14:54 - 17:42  (02:47)
k3       pts/9        10.0.2.2         Fri Apr 28 14:54 - 14:54  (00:00)
j        pts/7        10.0.2.2         Fri Apr 28 14:49 - 17:40  (02:51)
k5       pts/6        10.0.2.2         Fri Apr 28 11:41 - 17:41  (06:00)
k4       pts/5        10.0.2.2         Fri Apr 28 11:18 - 17:40  (06:22)
k4       pts/5        10.0.2.2         Fri Apr 28 10:37 - 11:08  (00:30)
j        pts/5        10.0.2.2         Fri Apr 28 10:37 - 10:37  (00:00)
k1       pts/4        10.0.2.2         Fri Apr 28 10:17 - 17:41  (07:24)
k2       pts/3        10.0.2.2         Fri Apr 28 10:14 - 17:40  (07:26)
j        pts/1        10.0.2.2         Fri Apr 28 10:06 - 16:53  (06:46)
j        tty1                          Fri Apr 28 10:02 - crash (2+23:17)
reboot   system boot  5.15.0-71-generi Fri Apr 28 10:02   still running
j        pts/0        10.0.2.2         Fri Apr 28 09:57 - 10:01  (00:04)
j        tty1                          Fri Apr 28 09:57 - down   (00:04)
reboot   system boot  5.15.0-71-generi Fri Apr 28 09:56 - 10:01  (00:04)
j        pts/0        10.0.2.2         Thu Apr 27 16:52 - 19:10  (02:18)
j        tty1                          Thu Apr 27 16:44 - down   (02:26)
reboot   system boot  5.15.0-71-generi Thu Apr 27 16:43 - 19:10  (02:27)

wtmp begins Thu Apr 27 16:43:18 2023

ㄴ last 명령어로 로그 확인하기

 

root@ysy:~/d6# last log

wtmp begins Thu Apr 27 16:43:18 2023

ㄴlast log 명령어로 마지막 로그만 확인하기

 

root@ysy:~/d6# cd /etc/logrotate.d/  --> logrotate 에 적용할 각종 로그 파일
root@ysy:/etc/logrotate.d# ls
alternatives  apport  bootlog  dpkg          rsyslog  ubuntu-advantage-tools  unattended-upgrades
apache2       apt     btmp     mysql-server  tomcat9  ufw                     wtmp
root@ysy:/etc/logrotate.d# nl wtmp  --> 이전 로그인 기록을 저장하는 파일
     1  # no packages own wtmp -- we'll rotate it here
     2  /var/log/wtmp {
     3      missingok
     4      monthly
     5      create 0664 root utmp
     6      minsize 1M
     7      rotate 1
     8  }

root@ysy:/etc/logrotate.d# nl ufw  --> 방화벽 도구
     1  /var/log/ufw.log
     2  {
     3          rotate 4
     4          weekly
     5          missingok
     6          notifempty
     7          compress
     8          delaycompress
     9          sharedscripts
    10          postrotate
    11                  [ -x /usr/lib/rsyslog/rsyslog-rotate ] && /usr/lib/rsyslog/rsyslog-rotate || true
    12          endscript
    13  }
    
root@ysy:/etc/logrotate.d# nl apt  --> apt 로그 파일의 로테이션 및 관리
     1  /var/log/apt/term.log {
     2    rotate 12
     3    monthly
     4    compress
     5    missingok
     6    notifempty
     7  }

     8  /var/log/apt/history.log {
     9    rotate 12
    10    monthly
    11    compress
    12    missingok
    13    notifempty
    14  }

ㄴ logrotate 에 적용할 각종 로그 파일 확인

 

root@ysy:~# cd /var/log/
root@ysy:/var/log# ls
alternatives.log    btmp                   dmesg.0     faillog    mail.err  ubuntu-advantage.log
alternatives.log.1  btmp.1                 dmesg.1.gz  installer  mail.log  ubuntu-advantage.log.1
apache2             cloud-init.log         dmesg.2.gz  journal    mysql     ubuntu-advantage-timer.log
apt                 cloud-init-output.log  dmesg.3.gz  kern.log   private   ubuntu-advantage-timer.log.1
auth.log            dist-upgrade           dpkg.log    landscape  syslog    unattended-upgrades
bootstrap.log       dmesg                  dpkg.log.1  lastlog    tomcat9   wtmp

root@ysy:/var/log# nl dpkg.log

root@ysy:/var/log# which date
/usr/bin/date
root@ysy:/var/log# which ls
/usr/bin/ls
root@ysy:/var/log# which date
/usr/bin/date
root@ysy:/var/log# which cp
/usr/bin/cp
root@ysy:/var/log# which useradd
/usr/sbin/useradd


root@ysy:/var/log# dpkg -S /bin/ls  --> ls 명령어를 실행하려면 어떤 패키지가 필요한지(설치되어있야하는지)
coreutils: /bin/ls 

root@ysy:/var/log# dpkg -S /bin/date  --> date 명령어를 실행하려면 어떤 패키지가 필요한지(설치되어있야하는지)
coreutils: /bin/date

root@ysy:/var/log# dpkg -S /bin/cp  --> cp 명령어를 실행하려면 어떤 패키지가 필요한지(설치되어있야하는지)
coreutils: /bin/cp

root@ysy:/var/log# dpkg -S /usr/sbin/useradd  --> useradd 명령어를 실행하려면 어떤 패키지가 필요한지(설치되어있야하는지)
passwd: /usr/sbin/useradd

ㄴ  dmesg --> 부팅할 때 뿌려지는 메시지

ㄴ dpkg -S  명령어 위치  --> 해당 명령어를 실행하려면 어떤 패키지가 필요한지(설치되어있야하는지)

 

 

아파치(Apache2)를 이용한 로그 확인

root@ysy:/var/log# ls
alternatives.log    cloud-init-output.log  faillog    private
alternatives.log.1  dist-upgrade           installer  syslog
apache2             dmesg                  journal    tomcat9
apt                 dmesg.0                kern.log   ubuntu-advantage.log
auth.log            dmesg.1.gz             landscape  ubuntu-advantage.log.1
bootstrap.log       dmesg.2.gz             lastlog    ubuntu-advantage-timer.log
btmp                dmesg.3.gz             mail.err   ubuntu-advantage-timer.log.1
btmp.1              dpkg.log               mail.log   unattended-upgrades
cloud-init.log      dpkg.log.1             mysql      wtmp

root@ysy:/var/log# cd apache2/
root@ysy:/var/log/apache2# ls
access.log  error.log  error.log.1  other_vhosts_access.log

root@ysy:/var/log/apache2# nl access.log  --> 접근 로그 확인


root@ysy:/var/log/apache2# ps -ef | grep apache2  --> 아파치 켜진지 확인 
root        6359    6288  0 20:22 pts/8    00:00:00 grep --color=auto apache2
--> 꺼진 상태

root@ysy:/var/log/apache2# systemctl start apache2  --> 아파치 시작 시킴
root@ysy:/var/log/apache2# ps -ef | grep apache2
root        6366       1  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    6367    6366  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    6368    6366  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
root        6424    6288  0 20:23 pts/8    00:00:00 grep --color=auto apache2

root@ysy:/var/log/apache2# ll
total 20
drwxr-x---  2 root adm    4096 May  1 09:20 ./
drwxrwxr-x 12 root syslog 4096 May  1 12:58 ../
-rw-r-----  1 root adm    1303 May  1 14:01 access.log  --> 아파치 접속 로그
-rw-r-----  1 root adm     967 May  1 20:23 error.log  
-rw-r-----  1 root adm    1684 May  1 09:20 error.log.1
-rw-r-----  1 root adm       0 Apr 27 17:16 other_vhosts_access.log
root@ysy:/var/log/apache2# 0>access.log  --> 아파치 접속 로그 사이즈  0 만들기
root@ysy:/var/log/apache2# ll
total 16
drwxr-x---  2 root adm    4096 May  1 09:20 ./
drwxrwxr-x 12 root syslog 4096 May  1 12:58 ../
-rw-r-----  1 root adm       0 May  1 20:24 access.log  --> 아파치 접속 로그 사이즈  0 확인
-rw-r-----  1 root adm     967 May  1 20:23 error.log
-rw-r-----  1 root adm    1684 May  1 09:20 error.log.1
-rw-r-----  1 root adm       0 Apr 27 17:16 other_vhosts_access.log

ㄴ http://127.0.0.1/  페이지에서 새로고침 계속 하면 로그 쌓임

--> http://127.0.0.1/  페이지에서 새로고침 계속 하면 로그 쌓임

root@ysy:/var/log/apache2# nl access.log  --> 로그 쌓인 것 없음
root@ysy:/var/log/apache2# nl access.log  --> 로그 쌓인 것 확인
     1  10.0.2.2 - - [01/May/2023:20:26:25 +0900] "GET / HTTP/1.1" 200 500 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     2  10.0.2.2 - - [01/May/2023:20:26:25 +0900] "GET /cat1.jpg HTTP/1.1" 200 257445 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     3  10.0.2.2 - - [01/May/2023:20:26:29 +0900] "GET / HTTP/1.1" 200 499 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     4  10.0.2.2 - - [01/May/2023:20:26:29 +0900] "GET / HTTP/1.1" 200 499 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     5  10.0.2.2 - - [01/May/2023:20:26:29 +0900] "GET / HTTP/1.1" 200 499 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     6  10.0.2.2 - - [01/May/2023:20:26:29 +0900] "GET / HTTP/1.1" 200 499 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     7  10.0.2.2 - - [01/May/2023:20:26:29 +0900] "GET / HTTP/1.1" 200 499 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     8  10.0.2.2 - - [01/May/2023:20:26:30 +0900] "GET / HTTP/1.1" 200 499 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
     9  10.0.2.2 - - [01/May/2023:20:26:42 +0900] "GET / HTTP/1.1" 200 500 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"

 

** 서비스 시작과 종료

service start 서비스
service stop 서비스
service status 서비스
service restart 서비스

systemctl 서비스 start 
systemctl 서비스 stop 
systemctl 서비스 status 
systemctl 서비스 restart 


부팅하면 자동으로 켜겠다
systemctl enable 서비스
부팅하면 꺼진상태이도록 하겠다
systemctl disable 서비스

 

**한글 locale 설정

#locale
#nl /etc/default/locale
#apt -y install language-pack-ko
#locale-gen ko_KR.UTF-8   --> 본인은 바뀌지 않아서 아래 방법을 이용함


직접 파일 편집하여 바꾸기
#vi /etc/default/locale
  1 #LANG=en_US.UTF-8  --> 주석처리
  2 LANG=ko_KR.UTF-8
  
  
***시스템 재시작 필요***

 

 

웹페이지 만들기

root@ysy:~# aq apache2  --> aq의 alias 설정 : apt list --installed | grep 

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

apache2-bin/jammy-security,now 2.4.52-1ubuntu4.4 amd64 [installed,upgradable to: 2.4.52-1ubuntu4.5]
apache2-data/jammy-security,now 2.4.52-1ubuntu4.4 all [installed,upgradable to: 2.4.52-1ubuntu4.5]
apache2-utils/jammy-security,now 2.4.52-1ubuntu4.4 amd64 [installed,upgradable to: 2.4.52-1ubuntu4.5]
apache2/jammy-security,now 2.4.52-1ubuntu4.4 amd64 [installed,upgradable to: 2.4.52-1ubuntu4.5]

root@ysy:~# ps -ef | grep apache2  --> 아파치 구동 확인
root        6366       1  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    6367    6366  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    6368    6366  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
root        6445    6288  0 20:30 pts/8    00:00:00 grep --color=auto apache2

root@ysy:~# pq httpd  --> pq의 alias 설정 : ps -ef | grep 
root        6453    6288  0 20:31 pts/8    00:00:00 grep --color=auto httpd
root@ysy:~# pq apache2  --> pq의 alias 설정 : ps -ef | grep 
root        6366       1  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    6367    6366  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    6368    6366  0 20:23 ?        00:00:00 /usr/sbin/apache2 -k start
root        6455    6288  0 20:32 pts/8    00:00:00 grep --color=auto apache2

ㄴ 아파치(Apache2) 구동 확인

 

root@ysy:/var/www/html# mount -t vboxsf win /yes  --> win 폴더 /yes 로 mount 해놓은 상태
--> mount -t vboxsf => VirtualBox에서 공유 폴더를 Linux에 마운트(mount)

root@ysy:~# cd /var/www/html/
root@ysy:/var/www/html# cp /yes/cat1.jpg .  --> 현재 위치로 cat1.jpg 로 win(/yes)에 다운 받은 사진 복사
root@ysy:/var/www/html# mv index.html old.html  --> 원본 파일 old.html 로 저장
root@ysy:/var/www/html# vi index.html  --> 새로운 index 파일 작성

<meta charset='utf-8'>
<body bgcolor=green text=white> <br><br> <h1><center>
<hr> <br>
안녕하세요. ysy네 집입니다. <br><br>
<hr><br><br>
<img src='cat1.jpg'>