728x90
지금 유지보수 하는 업체의 서버를 이전 해야할 필요가 생겼다.
서버 작업은 자주 하지 않다 보니 매번 새롭다.
게다가 버전을 맞추어 작업을 하다보니 몇 번을 해도 거의 같은 시간이 걸린다 ㅎㅎ
다음에 참조하기 위해 작업한 내용을 기록한다.
이번 작업은 클라우드 서버에 ubuntu, Docker등을 설치할 예정이다
----------------------------------
서버 : ubuntu 20.04
볼륨추가 : 1000Giga Byte
ubuntu@ubuntu1:~$ sudo su
root@ubuntu1:/home/ubuntu# fdisk -l
#파티션을 나눈다
root@ubuntu1:/home/ubuntu# fdisk /dev/vdc
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x452e13e9.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-2097151999, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2097151999, default 2097151999):
Created a new partition 1 of type 'Linux' and of size 1000 GiB.
Command (m for help): p
Disk /dev/vdc: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x452e13e9
Device Boot Start End Sectors Size Id Type
/dev/vdc1 2048 2097151999 2097149952 1000G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@ubuntu1:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 394M 1004K 393M 1% /run
/dev/vda1 97G 1.8G 95G 2% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/loop0 62M 62M 0 100% /snap/core20/1270
/dev/loop1 68M 68M 0 100% /snap/lxd/21835
/dev/vda15 105M 5.2M 100M 5% /boot/efi
tmpfs 394M 0 394M 0% /run/user/1000
/dev/loop3 50M 50M 0 100% /snap/snapd/18357
/dev/loop4 64M 64M 0 100% /snap/core20/1822
/dev/loop5 92M 92M 0 100% /snap/lxd/24061
#파티션을 포맷한다
root@ubuntu1:/home/ubuntu# mkfs.ext4 /dev/vdc1
#UUID를 확보한다
root@ubuntu1:/home/ubuntu# blkid
#디랙토리를 만든다
root@ubuntu1:/home/ubuntu# mkdir -p /home/ubuntu/storage
#재부팅시 자동 연결하기 위해서 파일에 설정한다
root@ubuntu1:/home/ubuntu# vi /etc/fstab
LABEL=cloudimg-rootfs / ext4 defaults 0 1
LABEL=UEFI /boot/efi vfat umask=0077 0 1
/dev/vdb none swap sw,comment=cloudconfig 0 0
UUID=0a76a959-85d1-4e8c-8fe6-6e8d036017f7 /home/ubuntu/storage ext4 defaults 0 0
root@ubuntu1:/home/ubuntu# mount -a
root@ubuntu1:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 394M 992K 393M 1% /run
/dev/vda1 97G 1.9G 95G 2% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/loop0 62M 62M 0 100% /snap/core20/1270
/dev/loop1 68M 68M 0 100% /snap/lxd/21835
/dev/vda15 105M 5.2M 100M 5% /boot/efi
tmpfs 394M 0 394M 0% /run/user/1000
/dev/loop3 50M 50M 0 100% /snap/snapd/18357
/dev/loop4 64M 64M 0 100% /snap/core20/1822
/dev/loop5 92M 92M 0 100% /snap/lxd/24061
/dev/vdc1 984G 77M 934G 1% /home/ubuntu/storage
#볼륨을 해제하고 다시 사용할때 사용한다
umount /home/ubuntu/storage << 마운트 해제시
Mysql 설치 및 원격접속 허용
apt-get install mariadb-server
mysql -uroot
> use mysql;
update user set authentication_string=password('password') where user='root';
flush priviledges ;
grant all privileges on . to 'root'@'%' identified by 'password';
>
root@ubuntu1:/home/ubuntu/storage# cd /etc
root@ubuntu1:/etc# cd mysql
root@ubuntu1:/etc/mysql# ls
conf.d debian-start debian.cnf mariadb.cnf mariadb.conf.d my.cnf my.cnf.fallback
root@ubuntu1:/etc/mysql# cd mariadb.conf.d
root@ubuntu1:/etc/mysql/mariadb.conf.d# ls
50-client.cnf 50-mysql-clients.cnf 50-mysqld_safe.cnf 50-server.cnf
root@ubuntu1:/etc/mysql/mariadb.conf.d# vi 50-server.cnf
127.0.0.1 >> 0.0.0.1 로변경
root@ubuntu1:/etc/mysql/mariadb.conf.d# systemctl restart mysql
>> sql 파일로 DB를 생성함
asp.net core 3.1설치
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
-O packages-microsoft-prod.deb
nginx proxy 설정
server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass <http://localhost:5000>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /downloads {
alias /var/downloads/;
autoindex on;
limit_rate_after 10M;
limit_rate 5M;
access_log /var/log/nginx/down.access.log;
error_log /var/log/nginx/down.error.log;
charset utf-8;
}
}
Docker 설치
오래된 버전 삭제하기
혹시나 기존의 오래된 버전이 있는지 확실히 할 수 있으며, 있다면 최신 버전 설치를 위해 삭제 해줍니다.
bash
$ sudo apt-get update
$ sudo apt-get -y install \ apt-transport-https \ ca-certificates \ curl \ gnupg
\ lsb-release
curl -fsSL
[https://download.docker.com/linux/ubuntu/gpg](https://download.docker.com/linux/ubuntu/gpg)
| sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]
[https://download.docker.com/linux/ubuntu](https://download.docker.com/linux/ubuntu)
\
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Docker Engine 설치하기
아래 명령어를 입력하면 자동으로 최신 버전이 설치 됩니다.
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli
[containerd.io](http://containerd.io/)
설치 완료
설치가 완료된 후에는
bash
$docker --version
$apt install docker-compose
$cd /home/ubuntu/appnet
$docker-compose up -d
vi Dockerfile
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Seoul
RUN apt-get update
RUN apt-get install -y tzdata
RUN apt-get update && apt-get -y install apache2 software-properties-common
RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
RUN apt-get update && apt-get install -y libapache2-mod-php7.3 php7.3 php7.3-cli php7.3-mysql
RUN a2enmod rewrite
EXPOSE 80
CMD apachectl -D FOREGROUND
RUN apt install vim -y
RUN apt install net-tools -y
RUN apt install iputils-ping -y
RUN apt update -y
RUN apt install language-pack-ko -y
RUN apt install fonts-nanum -y
RUN apt install fonts-nanum-coding -y
RUN apt install fonts-noto-cjk -y
ENV LANG ko_KR.UTF-8
ENV LANGUAGE ko_KR.UTF-8
ENV LC_ALL ko_KR.UTF-8
WORKDIR /
===================================
vi docker-compose.yml
version: '2'
services:
ubuntu2004:
hostname: a
container_name: a_container
build:
context: .
dockerfile: ./Dockerfile
ports:
- "8100:80"
stdin_open: true
tty: true
environment:
- TZ:"Asia/Seoul"
volumes:
- ./html:/var/www/html
========================
cd /etc/nginx/sites-available
vi default
server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /downloads {
alias /var/downloads/;
autoindex on;
limit_rate_after 10M;
limit_rate 5M;
access_log /var/log/nginx/down.access.log;
error_log /var/log/nginx/down.error.log;
charset utf-8;
}
}
server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass http://localhost:8100;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /downloads {
alias /var/downloads/;
autoindex on;
limit_rate_after 10M;
limit_rate 5M;
access_log /var/log/nginx/down.access.log;
error_log /var/log/nginx/down.error.log;
charset utf-8;
}
}
service nginx restart
http://localhost:8100 은 실행됨
DNS변경 작업
- 이상 -
728x90
'코딩교육 > 서버' 카테고리의 다른 글
목동코딩학원, Docker Container에 putty 접속하는 방법 (0) | 2023.03.27 |
---|---|
목동코딩학원, 서버이전.설치작업( 리눅스, 우분투) 과정 (0) | 2023.03.14 |
목동코딩학원, docker container에서 curl 사용하는 방법 (0) | 2023.03.09 |
목동코딩학원, curl error, "Fatal error: Uncaught Error: Call to undefined function curl_init()" 원인 (0) | 2023.03.09 |
목동코딩학원, Docker가 실행이 안될때.....결국 재부팅 (0) | 2023.03.08 |