Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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 31
Archives
Today
Total
관리 메뉴

브래의 슬기로운 코딩 생활

서버프로그래밍 14주차 정리 본문

1-2/서버프로그래밍

서버프로그래밍 14주차 정리

김브래 2022. 12. 7. 22:10

rocky linux 설치

- 사용자 계정 생성 시 관리자 선택
- 서버 + 3 packages

네트워크 설정 : 유동 아이피 설정
- nmcli dev show ens160 : 장치 확인
- nmcli dev up ens160 : 장치 시작
- ip addr :  네트워크 상태 확인
- ping -c 3 168.126.63.1

httpd 패키지 설치
- sudo dnf install http : 원격저장소로부터 httpd
패키지를 다운로드 받아서 설치

dnf list installed
- 설치된 패키지를 출력
dnf list installed | grep httpd
- 설치된 패키지들 중 이름이 httpd 패키지가
있는지를 확인

httpd 서비스의 상태 확인
- systemctl status httpd
httpd 서비스 실행(시작)
- systemctl start httpd


업로드

dnf install http : 원격저장소로부터 httpd
패키지를 다운로드 받아서 설치

dnf list installed
- 설치된 패키지를 출력
dnf list installed | grep httpd
- 설치된 패키지들 중 이름이 httpd 패키지가
있는지를 확인


eth0, ens33, ens160, eno1677332 : 장치이름(device name)

nmcli dev status
nmcli con mod ens160 ipv4.addresss <A.B.C.150>
nmcli con show ens160 : 설정 확인
nmcli con up ens160  :  설정 적용 또는 활성화

sshd 서버의 포트 변경
1. nano /etc/ssh/sshd_config 수정 : Port 110 활성
2. 보안 정책을 완화
sestatus : 확인 - enforcing
setenforce 0 : 현재 모드를 permissive로
systemctl stop sshd

firewall-cmd --add-port=110/tcp --permanent : 포트 해제
firewall-cmd --reload : 방화벽 재적재
firewall-cmd --list-all : 확인
systemctl start sshd

참고) systemctl restart sshd
nano /etc/selinux/config 수정 : enforcing -> permissive


네트워크가 안될 경우
1. vmnetcfg.exe 실행
2. VMWARE8 삭제 후 추가 (NAT)로 변경
3. Apply(적용)

text file viewer(read and display)
cat : 전체 보여주기
head : 앞쪽만 보여주기
tail : 뒷부분만 보여주기
more : 한 페이지씩 보여주기, 아래로만
less : 한 페이지씩 보여주기, 아래 위로
vs. nano, vi
text file editor


계정 관리
$ sudo useradd <fall>: fall이라는 계정 생성
관리지 계정 또는 sudoers 그룹 소속원이 sudo 명령 사용
$ passwd : 현재 로그인한 계정 암호 설정
/ : root directory
/root : root 계정의 home directory

$ cd .. : 상위 디렉토리로 이동
$ cd . : 현재 디렉토리로 이동
$ pwd
현재 작업 디렉토리, present working directory
/home/dream 인데 /etc/selinux로 디렉토리 변경
$ cd ../../etc/selinux : 상대 경로 (현재 위치 기준)
$ cd /etc/selinux : 절대 경로

httpd 서비스 설치
패키지 확인 / 설치
$ sudo dnf list | grep httpd
$ sudo dnf install httpd
서비스 확인/실행
$ sudo systemctl status httpd
$ sudo systemctl start httpd
서비스 종료
$ sudo systemctl stop httpd
부팅시 자동 시작
$ sudo systemctl enable httpd
부팅시 자동 시작
$ sudo systemctl disable httpd

dream 계정으로 로그인
wheel 그룹의 소속원
$ groups
dream wheel

wheel그룹 권한 부여
usermod -G wheel 계정이름

su - <계정이름>
계정 이름으로 사용자 전환 (switching user)
계정 이름이 없는 경우 root로 전환

로그아웃할 때까지 유지
sudo (superuser do)
지정한 명령 실행 완료 때까지만
/etc/sudoers 파일에 지정되어 있는 경우 사용 가능
기본적으로 root, wheel 그룹이 지정되어 있음

서비스 실행
systemctl start httpd
서비스 종료
systemctl stop httpd
서비스 자동 시작 등록
systemctl enable httpd
서비스 자동 시작 등록 해제
systemctl disable httpd

방화벽에서 지정한 서비스 해제 (즉시, 일시적)
firewall-cmd --add-service=http
방화벽에서 지정한 포트 해제 (즉시, 일시적)
firewall-cmd --add-port=80/tcp

--permanent 옵션의 의미 : firewalld 재적재 또는
재시작될 때 영속적으로 적용함

방화벽에서 지정한 서비스 블록
firewall-cmd --remove-service=httpd


IP: 10.71.133.13

--------------------------------------------------------------------------------
Docker

docker tag httpd-egyou:latest
<docker login id>/httpd:latest

<docker login id>/httpd : docker login id가
이미지 이름이 httpd로 변경

docker push <docker login id>/httpd

wsl2 : windows subsystem for linux 2
process : 실행 중인 프로그램
ps (process status)

이미지 실행 -> 컨테이너 생성, 실행
docker run --name egyou -d -p 8090:80 httpd:latest

컨테이너와 대화형으로 작업
docker exec -it egyou /bin/bash
# cd /usr/local/apache2/htdocs
# echo "<h1>학번이름</h1>" > index.html

rockylinux  실행
docker pull rockylinux/rockylinux
docker

Docker 사용

- pull 한 image 들을 확인할 수 있음
$ docker images

- image 실행해서 container화 함
$ docker run -d -p 8888:80 <image_name:tag>

포트 포워딩
8888 : docker가 사용하는 포트
80 : container가 사용하는 포트

- 실행 중인 container 확인
$ docker ps
ps : process status 의미함

- 실행 여부와 관계없이 container 확인
$ docker ps -a

- 실행 중인 container의 지정한 명령을 실행
$ docker exec -it <container_id> /bin/bash

- container 실행 중지
$ docker stop <container_id>

- container 실행
$ docker start <container_id>

- container를 이미지로 저장
$ docker commit <container_id> <image_name:tag>

$ docker images

- repository로 부터 image pull -> 실행 -> container
-> commit -> image 생성 (-> docker login)
-> repository에 push image

- image -> file
$ docker save -o ooo.tar <image_name:tag>

** image_name:tag 는 repo_id/image:tag

- file -> image
$ docker load -i ooo.tar

- container -> file
$ docker export <container_id> > ooo.tar

- file -> container
$ docker import ooo.tar