포스코DX X 비트교육센터 6기 - 리눅스


vi hello.txt

  • i : 그 자리에서 insert
  • o : 한 줄 enter 돼서 insert
  • a : 띄어쓰기 한 상태에서 insert

  • :w : 저장
  • :w hello2.txt : hello2.txt로 저장하지만, 현재 띄워져있는 화면은 hello.txt임

  • shift + z + z : 저장하고 나가기

  • h, j, k , l : 에디터에서 위 아래 오른 왼 이동이 가능함.

  • u : ctrl+z와 같은 존재. 뒤로 가기
  • dd : 줄 삭제

  • yy, p : 내용을 복사하고 붙여넣기 » 이름 만들려면, “[지을이름] [몇 줄? 숫자] yy

cat hello.txt

내용물 확인만 하기


image

image

image

image

image


ctrl + f ??

  • /찾는 이름
* 다음 꺼 : /
* 이전 꺼 : ?

vi에서 나가긴 귀찮고, ls -la같은 명령어 하나가 궁금할 때,

:!ls -la 하면, 파일명들 볼 수 있고, enter치면 다시 vi화면으로 돌아감.

서버 restart할 때, 많이 쓰고 편함.

  • 명령어가 여러개면?

:sh 하고 명령어들 치다가 exit 하면 다시 vi 화면으로 돌아감

파일이름을 변경!! *************

:f 파일명

이 외 유용한 기능

image


네트워크 관리

  • ping
PING이란?

 ping이란? Paket Internet Groper의 약어이며, 컴퓨터 네트워크 상태를 점검, 진단하는 명령이다

 ping 명령의 기본적인 작동 원리는 네트워크 상태를 확인하려는 대상(target) 컴퓨터를 향해
일정 크기의 패킷(packet, 네트워크 최소 전송단위)을 보낸후(ICMP echo request)
대상 컴퓨터가 이에 대해 응답하는 메시지(ICMP echo reply)를 보내면 이를 수신, 분석하여 대상 컴퓨터가 작동하는지,
또는 대상 컴퓨터까지 도달하는 네트워크 상태가 어떠한지 파악할수 있습니다

 ping 명령은 TCP/IP 프로토콜 중 ICMP(Internet Control Message Protocol)을 통해 동작하므로,
 이 프로토콜을 지원하지 않는 기기를 대상으로 ping 수행할수 없습니다.
 또한 보안의 이유로 ICMP 사용을 차단하는 기기역시 ping 요청에 대응하지 않습니다
[root@localhost ~]# nslookup www.poscodx.com
Server:		168.126.63.1
Address:	168.126.63.1#53

Non-authoritative answer:
Name:	www.poscodx.com
Address: 203.246.184.198

[root@localhost ~]# ping 203.246.184.198
PING 203.246.184.198 (203.246.184.198) 56(84) bytes of data.

핑 막아둠

[root@localhost ~]# nslookup www.google.com
Server:		168.126.63.1
Address:	168.126.63.1#53

Non-authoritative answer:
Name:	www.google.com
Address: 142.250.206.196
Name:	www.google.com
Address: 2404:6800:400a:813::2004

[root@localhost ~]# ping 142.250.206.196
PING 142.250.206.196 (142.250.206.196) 56(84) bytes of data.
64 bytes from 142.250.206.196: icmp_seq=1 ttl=115 time=36.1 ms
64 bytes from 142.250.206.196: icmp_seq=2 ttl=115 time=38.9 ms
64 bytes from 142.250.206.196: icmp_seq=3 ttl=115 time=37.9 ms
64 bytes from 142.250.206.196: icmp_seq=4 ttl=115 time=35.4 ms
64 bytes from 142.250.206.196: icmp_seq=5 ttl=115 time=36.5 ms
64 bytes from 142.250.206.196: icmp_seq=6 ttl=115 time=36.3 ms
64 bytes from 142.250.206.196: icmp_seq=7 ttl=115 time=37.7 ms
64 bytes from 142.250.206.196: icmp_seq=8 ttl=115 time=40.3 ms
64 bytes from 142.250.206.196: icmp_seq=9 ttl=115 time=36.8 ms
64 bytes from 142.250.206.196: icmp_seq=10 ttl=115 time=38.5 ms
64 bytes from 142.250.206.196: icmp_seq=11 ttl=115 time=35.7 ms
64 bytes from 142.250.206.196: icmp_seq=12 ttl=115 time=37.8 ms
64 bytes from 142.250.206.196: icmp_seq=13 ttl=115 time=36.0 ms

핑~

[webmaster@localhost ~]$ vi /etc/hostname

image

image

sync 
sycn
reboot

image

[root@lx ~]# cd /etc
[root@lx etc]# vi hosts

image

호스트네임, 도메인 추가 저장

https://pingfanzhilu.tistory.com/entry/Windows-%EC%9C%88%EB%8F%84%EC%9A%B0-hosts%ED%8C%8C%EC%9D%BC-%EC%9C%84%EC%B9%98-%EB%B0%8F-%EC%88%98%EC%A0%95-%EB%B0%A9%EB%B2%95

여기서 ip주소를 추가하고,

Xshell에 등록정보를 추가할때 ip대신 메모장에 추가한 이름을 적어주면 된다.

image

hostname은 장치이름을 담는다.

netstat

  • 네트워크 연결, 라우팅 테이블, 네트워크 장치의 통계정보 등 네트워크에 관련된 여러가지 정보를 확인할 수 있다.

image

ifconfig

image

이것만 가지고도 TCP/IP를 만들 수 있다!

[root@lx ~]# ifconfig | grep inet
        inet 192.168.0.178  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::ad4a:9584:cae1:9aee  prefixlen 64  scopeid 0x20<link>
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
[root@lx ~]# ifconfig | grep inet | grep -v inet6
        inet 192.168.0.178  netmask 255.255.255.0  broadcast 192.168.0.255
        inet 127.0.0.1  netmask 255.0.0.0

  • 네트워크 중지
ifconfig enp0s3 down

이러면 다시 오라클 버추얼 박스의 centOs 가서 ifconfig enp0s3 up 해주면 된다.

그러니 맘대로 죽이면 안돼!!!!!!!!!!!!

  • 네트워크 서비스 죽이기

소켓 계층이라 centOs에서 start 시켜줘도 연결이 다 죽어버림.

-> 물리계층

systemctl stop network
  • ip 바꾸는 것 **하지마****
ifconfig enp0s3 192.168.0.72
  • 여러분들이 꼭 알았으면 좋겠는 것!
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

UUID : 네트워크 고유 번호

밑에

IPADDR=192.168.0.178
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=168.126.63.1
DNS2=1.1.1.1

추가하기

systemctl restart network

다른 곳에서 공유기가 다르니까, gateway, ipaddr이 다르면 사용이 불가능하다.


TOMCAT

image

  • 서버환경과 이클립스 환경을 잘 구분할 줄 알아야한다.

다운로드

https://tomcat.apache.org/download-90.cgi

  • zip을 받기

  • poscodx2023에 압축 풀기

  • 이클립스 설정

image

image

image

image

image

  • 새 프로젝트 설정

image

image

image

image

image

image


#톰캣 다운로드

  1. 작업은 /root

  2. tomcat8 다운로드

    # wget --no-check-certificate https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.79/bin/apache-tomcat-9.0.79.tar.gz
    
  3. 압축 풀기

   # tar xvfz apache-tomcat-9.0.79.tar.gz
  1. 설치
   # mv apache-tomcat-9.0.79 /usr/local/poscodx2023/tomcat9.0
   # ln -s /usr/local/poscodx2023/tomcat9.0 /usr/local/poscodx2023/tomcat
  1. 설정(/etc/profile, 생략)

  2. 포트 확인

   # vi /usr/local/poscodx2023/tomcat/conf/server.xml

8080 open 확인

image

  1. 실행
   # /usr/local/poscodx2023/tomcat/bin/catalina.sh start

image


- 잘 되나 확인
   # ps -ef | grep tomcat

image

  1. 브라우저로 접근 하기 http://(설치서버IP):8080

image

안된다면?

systemctl disable firewalld
systemctl stop firewalld

image

image

  1. 중지 시키기
   # /usr/local/poscodx2023/tomcat/bin/catalina.sh stop
  1. 서비스 등록 하기
   /usr/lib/systemd/system/tomcat.service 파일 생성

  • 파일에 담을 내용
[Unit]
Description=tomcat9
After=network.target syslog.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/local/poscodx2023/java
User=root
Group=root

ExecStart=/usr/local/poscodx2023/tomcat/bin/startup.sh
ExecStop=/usr/local/poscodx2023/tomcat/bin/shutdown.sh

UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
   # systemctl enable tomcat
  1. tomcat 서비스 실행/중지/재실행
   # systemctl start tomcat
   # systemctl stop tomcat
   # systemctl restart tomcat
  1. tomcat manager 설정 1) tomcat-users.xml 설정
      # vi /usr/local/poscodx2023/tomcat/conf/tomcat-users.xml

image

manager가 보안이 굉장히 중요한 곳임.

access가 가능하게하고 비밀번호를 설정해야한다.

========================================================

. . . . . .

======================================================== 2) /usr/local/poscodx2023/tomcat/webapps/manager/META-INF/context.xml ======================================================== 주석 처리

....

새로 다음내용 추가

========================================================

  1. tomcat 재시작
    # systemctl stop tomcat
    # ps -ef | grep tomcat
    # systemctl start tomcat
  1. http://192.168.80.131/manager

image

image

myapp.war를 올리기

image

cd myapp 가서 ls -l로 확인해보기

톰켓 키고 끄기

[root@lx ~]# systemctl start tomcat
[root@lx ~]# ps -ef | grep tomcat
root      2225     1 99 15:44 ?        00:00:02 /usr/local/poscodx2023/java/bin/java -Djava.util.logging.config.file=/usr/local/poscodx2023/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/poscodx2023/tomcat/bin/bootstrap.jar:/usr/local/poscodx2023/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/poscodx2023/tomcat -Dcatalina.home=/usr/local/poscodx2023/tomcat -Djava.io.tmpdir=/usr/local/poscodx2023/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      2242  2067  0 15:44 pts/0    00:00:00 grep --color=auto tomcat
[root@lx ~]# systemctl stop tomcat

[root@lx ~]# 
[root@lx ~]# ps -ef | grep tomcat
root      2292  2067  0 15:44 pts/0    00:00:00 grep --color=auto tomcat