728x90
반응형

한글 설정 방법

Ctrl + Shitp + P 버튼을 누른다음 Configure Display Language 를 검색 합니다. 

 

 

한국어를 선택하고 재실행 합니다. 

 

728x90
반응형
728x90
반응형

 

  • cannot create temp file for here-document: 장치에 남은 공간이 없음 에러가 발생할 경우 
  • 리눅스 용량 부족시 디스크 추가하는 방법에 대해 정리합니다. 

 => cannot create temp file for here-document: 장치에 남은 공간이 없음

현재 디스크 사용량 확인 

  • df -Th 명령을 통해 현재 사용중인 디스크 사용량을 확인합니다. 
[root@mysvr:/root]$ df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G   13M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       6.0G  6.0G  3.5M 100% /
/dev/sda1               xfs      1014M  185M  830M  19% /boot
/dev/mapper/centos-home ext2       25G  8.9G   15G  38% /home
tmpfs                   tmpfs     378M  8.0K  378M   1% /run/user/42
tmpfs                   tmpfs     378M     0  378M   0% /run/user/0

 

  • lvdisplay 확인 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                cwMNqw-gJSs-7nDO-GrRU-bgxE-FLB5-7acfhK
  LV Write Access        read/write
  LV Creation host, time localhost, 2023-03-09 07:40:48 +0900
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                kRPPw7-Ffr2-Bf20-CsE9-UDkt-aCdO-Y4DvFo
  LV Write Access        read/write
  LV Creation host, time localhost, 2023-03-09 07:40:48 +0900
  LV Status              available
  # open                 1
  LV Size                <6.00 GiB
  Current LE             1535
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

 

디스크 추가 

  • fdisk -l 을 통해 추가한 disk 정보를 확인 합니다. 
  • 용량 증설을 위해 hdd 를 20G 추가 했습니다. 

 

  • 추가한 디스크에 대해 파티션을 생성 합니다. 
  • fdisk /dev/sdb
[root@mysvr:/root]$ fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0x8135267e.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): =>엔터
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): =>엔터
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

  • 파티셔닝한 디스크 /dev/sdb1 를 Physical Volume 생성 한다.
  • pvscan 이나 pvdisplay 명령을 통해 pysical volume 정보를 확인 한다. 
pvcreate  /dev/sdb1
pvscan
pvdisplay

 

  • vgextend 명령을 통해 centos 볼륨 그룹에 새로 추가한 pysical volume 를 확장 한다.
vgextend centos /dev/sdb1

 

  • lvextend 명령을 통해 부족했던 lvm 을 확장 합니다. 
lvextend /dev/mapper/centos-root -l +100%FREE

 

  • pvscan 명령을 통해 centos 으로 pv 가 추가 되었는지 확인 한다.

 

  • xfs_growfs 명령을 통해 논리 볼륨을 resizing 한다. 
    • ext4  포멧일 경울 resize2fs /dev/mapper/centos-root 수행 합니다. 
    • xfs type 에 대해  resize2fs 명령을 수행 하면 아래 처럼 에러가 발생함.

[root@mysvr:/root]$ resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
[root@mysvr:/root]$ blkid /dev/mapper/centos-root
/dev/mapper/centos-root: UUID="f4704f6c-5120-4c0f-b46b-7a0c31f390e5" TYPE="xfs" 

 

  • xfs_growfs 를 수행 하지 않으면 용량 증설이 되지 않는다.
xfs_growfs /dev/mapper/centos-root

 

  • df -Th 명령을 통해 용량이 증설 되었는지 확인 
  • 6G 에서 20G 로 용량이 증설 된것을 확인 할수 있다.

 

 

728x90
반응형
728x90
반응형

리눅스에서 커널버전을  업그레이드 하는 방법에 대해 알아보겠습니다. 

 

현재 설치된 서버는 Centos 6.9 버전입니다. 

 

 

 

리눅스 커널버전 확인

  • 현재 설치된 커널 버전을 확인하는 방법은 아래와 같이 여러 방법이 있습니다. 
uname -r 
cat /proc/version
cat /proc/sys/kernel/osrelease
dmesg | grep "Linux version"

 

커널 버전 다운로드 

아래 사이트에서 원하는 커널 버전을 다운로드 받습니다. 

저는 3.14 버전으로 업그레이드를 하기 위해 3.14 커널 버전을 다운로드 받습니다.

cd /var

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v3.x/linux-3.14.1.tar.gz    --no-check-certificate

tar xvzf linux-3.14.1.tar.gz

 

https://mirrors.edge.kernel.org/pub/linux/kernel/

 

Index of /pub/linux/kernel/

 

mirrors.edge.kernel.org

 

 

 

커널 버전 업그레이드(kernel 2.6 -> 3.1) 

  • 이제 본격적으로 커널을 업그레이드 하겠습니다.

커널 업데이트 사전 셋팅 

  • 패키지 설치
yum install ncurses-devel 
yum groupinstall "Development Tools"
  • /usr/src 폴더로 이동후 링크를 걸어줍니다. 
cd /usr/src
ln -s /var/linux-3.14.1 linux

 

  • 커널 버전을 업데이트 진행
make mrproper
make clean
cp /boot/config-2.6.32-754.35.1.el6.x86_64  ./.config

 

커널 환경 설정 셋팅

  • 커널 설정 파일 적용
  • make menuconfig 실행 하면 아래 화면이 나옵니다. 
  • 화살표 버튼 (->) 을 눌러 서 Load 버튼을 클릭 합니다. 

  • OK 버튼을 클릭합니다.

  • Gerneral setup 을 선택 합니다. 

  • Enable deprecated sysfs features to support old userspace tools 를 체크 합니다.
  • 체크 이후 Save 버튼을 누릅니다. 

  • OK 버튼을 누르고 나옵니다. 

 

  • 위과정을 통해 커널 설정에 대한 기본 셋팅을 마쳤습니다.

커널 빌드

  • 설정 셋팅이 완료 되었다면 이제 신규 버전으로 빌드를 진행 합니다. 
  • 빌드시 꽤 많이 시간이 소요 됩니다. 
  • 조금이라도 빠르게 빌드를 원한 다면 make -j 옵션을 사용 하세요 
    • make -j 4  modules_install 
make all 
make moules_install
make install

 

  • make install 시 에러가 발생 한다면 무시하셔도 됩니다. 

ERROR: modinfo: could not find module snd_page_alloc

 

  • uname -a 로 변경 된 커널 버전을 확인 합니다. 
  • 만약 변경이 되지 않을 경우 /boot/grub/grub.conf 파일에서 default 버전을 변경 합니다. 
  • default=0 으로 변경후 reboot 을 후에 다시 커널 버전을 확인 합니다. 

  • 2.6 에서 3.14 로 커널 버전이 업그레이드 된것을 확인 할수 있습니다.
[root@centos6 linux]# uname -r 
3.14.1
[root@centos6 linux]# cat /proc/version
Linux version 3.14.1 (root@centos6) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #2 SMP Thu Dec 21 19:44:34 KST 2023
[root@centos6 linux]# cat /proc/sys/kernel/osrelease
3.14.1
[root@centos6 linux]# dmesg | grep "Linux version"
Linux version 3.14.1 (root@centos6) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #2 SMP Thu Dec 21 19:44:34 KST 2023
[root@centos6 linux]# 


 

 

 

728x90
반응형
728x90
반응형
  • gitlab 과 git 을 사용하면서 발생한 에러에 대해 해결 방법을 기록 합니다. 
  • Gtk-WARNING 발생 
    • 에러내용 : ※ (gnome-ssh-askpass:22626): Gtk-WARNING **: 20:48:04.168: cannot open display:
    • 해결 방법 : unset SSH_ASKPASS
  • fatal: empty ident name
    • 에러내용 : 

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <dev-account@centos7.(none)>) not allowed

 

  • 해결방법: 계정 정보를 등록 한다. 
728x90
반응형
728x90
반응형

gitlab 올라간 특정 디렉토리만 다운로드 받을 수 있는 방법을 소개 합니다. 

일반적으로 git clone 을 수행 하면 gitlab 에 등록된 프로젝트를 모두 다운로드 받게 되는데 

이럴경우 원하지 않는 파일도 모두 다운로드 받게 되어 비효율 적입니다. 

이번 글에서는 git config core.sparsecheckout true 명령을 통해 프로젝트중 원하는 디렉토리만 다운로드 방법을 소개 하겠습니다. 

 

GitLab 프로젝트 생성

  • 테스트위해 우선 임의로 아래 처럼 테스트를 위해 프로젝트를 생성 하고 디렉토리를 만듭니다.

[dev-account@centos7:/home/dev-account/test]$ tree -L 3
|-- guide_doc
|   `-- doc
|       |-- ReadMe.md
`-- testProject
    |-- README.md
    `-- guide_doc
        |-- doc
        `-- etc
6 directories, 3 files

 

GitLab 특정 디렉토리(폴더) 다운로드 

  • git lab 에 등록된 파일을 다운로드 받기 위해 test 프로젝트를 만듭니다. 
mkdir test
cd test

 

  • 이후 test 디렉 토리로 이동하여 local emtpy repository 를 생성 gitlab 프로젝트 정보를 등록 합니다. 
git init

git remote add -f origin http://xxx.xxx.xxx.xxx:6060/comdoc/testProject.git
  • 특정 디렉토리만 다운로드 받기 위해 sparse-checkout 을 활성화 합니다. 
  • guide_doc/doc  는 testProject 하위 폴더 입니다. 
echo "guide_doc/doc" > .git/info/sparse-checkout
git config core.sparsecheckout true
  • git pull 명령을 통해 디렉토리를 내려 받습니다. 
git pull origin main

 

git pull origin main
계정 및 비밀번호 입력 

remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (11/11), done.
From http://192.168.17.83:6060/comdoc/testProject
 * branch            main       -> FETCH_HEAD
[dev-account@centos7:/home/dev-account/test]$ ls
guide_doc
[dev-account@centos7:/home/dev-account/test]$ ll
total 0
drwxr-xr-x 4 dev-account dev-account  35 Dec 19 19:35 .
drwx------ 7 dev-account dev-account 193 Dec 19 19:25 ..
drwxr-xr-x 8 dev-account dev-account 162 Dec 19 19:35 .git
drwxr-xr-x 3 dev-account dev-account  17 Dec 19 19:35 guide_doc

 

GitLab 파일 수정 및 추가 후 업로드 [git push] 

  • 다운로드 받은 디렉토리에서 파일을 추가 하거나 수정 할경우 아래 절차로 gitlab 서버에 파일을 업로드 할수 있습니다.
    • git add [파일명]
    •  git commit -m "[comment]"
    • git push origin main
  • 테스트를 위해 임의로 쉘 스크립트를 만들었습니다. 
[dev-account@centos7:/home/dev-account/test/guide_doc/doc]$ vi test.sh
#!/bin/bash

while [[ $# -gt 0 ]]; do
  case $1 in
    -a|--option-a)
      arg_a="$2"
      shift
      ;;
    -b|--option-b)
      arg_b="$2"
      shift
      ;;
    *)
      # 알 수 없는 옵션에 대한 처리
      echo "Unknown option: $1"
      exit 1
      ;;
  esac
  shift
done

echo "Option -a: $arg_a"
echo "Option -b: $arg_b"

 

git add option_test.sh
git commit -m "option test shell commit"
  • git commit 명령 수행중 에러가 발생하면 에러 내용에 따라 git lab 계정정보를 등록 해주면 됩니다. 

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <dev-account@centos7.(none)>) not allowed

 

[dev-account@centos7:/home/dev-account/test/guide_doc/doc]$ git config --global user.email "test_user@example.com"
[dev-account@centos7:/home/dev-account/test/guide_doc/doc]$ git config --global user.name "test_user "
[dev-account@centos7:/home/dev-account/test/guide_doc/doc]$ git commit -m "option test shell commit"              
[master 6609602] option test shell commit
 1 file changed, 24 insertions(+)
 create mode 100644 guide_doc/doc/option_test.sh

 

  • local 에 저장된 파일을 이제 gitlab 프로젝트로 업로드 합니다. 
git push origin main
  • 아래 에러가 발생 할경우 브렌치를 변경해 줘야 합니다. [master -> main]
error: src refspec main does not match any.
error: failed to push some refs to 'http://xxx.xxx.xxx.xxx/comdoc/testProject.git'

 

git show-ref
git remote -v
git status

git branch -m master main

 

  • GitLab 파일 업로드 확인 

 

 

728x90
반응형
728x90
반응형
  • Centos 에서 현재 사용중인 포트를 확인 하는 방법에 대해 알아보겠습니다. 

netstat 명령 

  • 리눅스에서는 netstat  명령으로 현재 litten 하고 있는 포트 정보는 내외부 네트워크연결 정보를 상세하게 확인 할수 있습니다. 
  • netstat  명령에 -tulpn 옵션을 추가하면 현재 사용중인 포트정보만 확인 가능 합니다. 
    • -t: TCP 프로토콜에 관련된 정보를 표시합니다.
    • -u: UDP 프로토콜에 관련된 정보를 표시합니다.
    • -l: 현재 리스닝 상태인 소켓만 표시합니다.
    • -p: 프로세스 ID 및 프로그램 이름과 함께 소켓 정보를 표시합니다.
    • -n: 호스트 및 포트 번호를 숫자로 표시합니다. 호스트 및 포트를 이름으로 변환하지 않습니다.

현재 사용중인 포트 체크

  • netstat 명령어를 사용하여 현재 사용 중인 포트를 확인하고 awk 사용 중인 포트만 나열 합니다.
  • 이후 sort -n 을 통해 사용중인 포트를 정렬하여 출력 합니다. 
netstat -tulpn | awk '/LISTEN/ {print $4}' | awk -F ":" '{print $NF}' | sort -n 
22

사용 가능한 포트 확인 

  • 좀더 확장하여 사용가능한 포를 확인하는 방법을 쉘스크립트를 통해 알아보겠습니다. 
  • 아래 쉘은 사용가능 한 Ranage 를 입력받고  현재 사용중인 port 리스트 중 range 가 사용자가 입력한 범위 이상의 포트 대역대만 출력 하는 스크립트입니다. 
  • read -p 를 통해 사용하고자 하는 포트 범위를 입력 합니다. 
#!/bin/bash

read -p " 원하는 포트 범위를 입력하세요:" check_port_range
echo " $check_port_range 범위 이상의 포트 범위를 체크합니다. " 



# 현재 사용 중인 포트와 포트 범위를 확인하는 스크립트
# netstat 명령어를 사용하여 현재 사용 중인 포트를 확인하고 awk로 정리합니다.
# 마지막에 sort 명령어를 사용하여 포트를 정렬합니다.

used_ports=$(netstat -tulpn | awk '/LISTEN/ {print $4}' | awk -F ":" '{print $NF}' | sort -n | uniq)


# 포트 범위를 확인하는 함수
check_port_range() {
  local start_port=$1
  local end_port=$2
  port_range=$(expr $end_port - $start_port)

  if [ $port_range -ge $check_port_range ]; then
      echo " [ $(expr $port_range ) ] :  $(expr $start_port + 1 ) ~ $(expr $end_port + 1 ) " 
    
  fi

}

# 사용 중인 포트를 확인하면서 포트 범위를 확인합니다.
IFS=$'\n'
start_port=0

echo "PORT_RANGE : START_PORT ~ END_PORT" 
echo "================================================="
for port in $used_ports; do

  check_port_range "$start_port" "$port"
  start_port=$port

done

 

728x90
반응형
728x90
반응형
  • Visual Studio Code (VS Code) 에서 원격지 리눅스 서버에 접속 하는 방법을 소개합니다. 

 

Visual Studio Code 설치

아래 경로에서 Visual Studio Code 를 다운로드 받습니다. 

https://code.visualstudio.com/

 

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

 

 

VS Code  실행 및  Remote - SSH  확장 팩을 설치

  • VS code 가 설치가 완료 되었다면 Remote - SSH  확장팩 설치를 진행 합니다. 

 

Remote - SSH  접속 설정 

  • 원격지 서버에 접속 하기 위한 연설 설정 정보를 셋팅 합니다.
  • F1 혹은 Ctrl + Shift + P 버튼을 눌러서 Remote SSH Configuration 파일을 수정 합니다. 
  • ~.ssh/config
Host [alias]
    HostName [ip addr]
    User [account_name]
    Port [port number]
    IdentityFile [key location]

 

 

 

Remote 서버 접속 

  • VS Code 에서 Centos7 서버에 접속을 합니다. 
  • .ssh/config 에 작성한 접속 정보를 이용해서 원격지 서버에 접속을 합니다. 

 

  • 정상적으로 접속이 되면 아래와 같이 원격지 서버에서 접속해서 간단한 테스트를 진행 해볼수 있습니다. 
  • test.sh 라는 쉘 스크립트를 작성 하고 아래 터미널 창에서 수행을 합니다. 

728x90
반응형
728x90
반응형

리눅스에서는 파일시스템의 디스크 사용량을 df -h 명령으로  확인 할수 있습니다. 

이번 글에서는 마운트된 디스크가 여러개일때 쉘스크립트를 사용해서

평균 사용량을 계산하는 스크립트작성하는 방법에 대해 알아보겠습니다. 

 

 

df  명령 

df -h명령을 수행 하면 아래 그림처럼 시스템의 디스크 사용량을 확인 할수 있습니다. 

 

 

각 항목의 설명은 다음과 같습니다. 

  • Filesystem: 파일 시스템의 경로 또는 장치 이름
  • Size: 파일 시스템의 총 크기
  • Used: 파일 시스템에서 사용 중인 공간
  • Avail: 파일 시스템에서 사용 가능한 공간
  • Use%: 사용 중인 공간의 백분율
  • Mounted on: 파일 시스템이 마운트된 디렉토리 경로

이때 현재 Disk 사용율은 Use% 항목으로 표시됩니다. 

디스크 사용량 공식은  Usage Percentage=(Size -​  Avail ) / size ×100 입니다. 

 

df 사용 쉘 스크립트 

쉘스크립트를 사용해 디스크가 여러개일때 평균 사용량을 체크하는 스크립트를 작성 합니다. 

  • df -k 명령을 통해 Size , Used , Avail  정보를 byte 단위로 계산 합니다. 
  • 각 디스크별로 합산 한다음 BYTE 를 GB 단위로 변환 합니다. 
  • disk_chekc.sh 
#사용량 체크 Mount Disk 정보
declare -a system_mounted_disks=(
/
/data1
/data100G
/data65G
/data300G
)


system_disk_chk(){

total_size=0
total_used_size=0
total_avail_size=0
df -h ${system_mounted_disks[1]} | awk 'NR==1'

for disk in "${system_mounted_disks[@]}"
do

df -h $disk | awk 'NR==2'
disk_size=$(df -k $disk --output=size | awk 'NR>1 {gsub(/[A-Za-z]/, "", $1); printf "%.0f\n", $1}')
disk_used_size=$(df -k $disk --output=used | awk 'NR>1 {gsub(/[A-Za-z]/, "", $1); printf "%.0f\n", $1}')
disk_avail_size=$(df -k $disk --output=avail | awk 'NR>1 {gsub(/[A-Za-z]/, "", $1); printf "%.0f\n", $1}')

total_size=$((total_size + disk_size))
total_used_size=$((total_used_size + disk_used_size))
total_avail_size=$((total_avail_size + disk_avail_size))

done

echo "--------------------------------------------------------------------"
echo "DISK Total Size        : $(expr $total_size / 1024 / 1024) GB"
echo "DISK Total Size(Used)  : $(expr $total_used_size / 1024 / 1024) GB"
echo "DISK Total Size(Avail) : $(expr $total_avail_size / 1024 / 1024) GB"
echo "DISK Use(%)            : $(echo "scale=2; ($total_size - $total_avail_size) / $total_size * 100" | bc) (%) "
echo "--------------------------------------------------------------------"


}
system_disk_chk

 

df 사용 쉘 스크립트 수행 

다음과 같이 5개 마운트된 디스크의 사용량 체크해보겠습니다. 

  • df -h 로 마운트 된 디스크 사용량 조회 
[root@centos7:/root/disk]$ df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs                   tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs                   tmpfs     7.8G  414M  7.4G   6% /run
tmpfs                   tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        50G   28G   23G  55% /
/dev/sdc                ext2      917G  814G   57G  94% /data1
/dev/sdb2               ext2       99G   32G   62G  35% /data100G
/dev/sdb3               ext2       65G   52M   62G   1% /data65G
/dev/sdb1               ext2      296G   38G  243G  14% /data300G
/dev/sda2               xfs      1014M  221M  794M  22% /boot
/dev/sda1               vfat      200M   12M  189M   6% /boot/efi
/dev/mapper/centos-home xfs       873G  237G  636G  28% /home
tmpfs                   tmpfs     1.6G  8.0K  1.6G   1% /run/user/42
tmpfs                   tmpfs     1.6G     0  1.6G   0% /run/user/0

 

  • sh disk.sh 수행 
[root@centos7:/root/disk]$ sh disk.sh 
Filesystem      Size  Used Avail Use% Mounted on
/dev/mapper/centos-home  873G  237G  636G  28% /home
/dev/sdc        917G  814G   57G  94% /data1
/dev/sdb2        99G   32G   62G  35% /data100G
/dev/sdb3        65G   52M   62G   1% /data65G
/dev/sdb1       296G   38G  243G  14% /data300G
--------------------------------------------------------------------
DISK Total Size        : 2247 GB
DISK Total Size(Used)  : 1120 GB
DISK Total Size(Avail) : 1057 GB
DISK Use(%)            : 52.00 (%) 
--------------------------------------------------------------------

 

 

728x90
반응형
728x90
반응형

이번 글에서는 우분투에서 윈도우로 접속하는 방법에 대해 알아보겠습니다. 

방법은 의외로 간단합니다. 

우분투에서 원격데스크탑 유틸을 설치한후 접속할 윈도우 서버에서 원격 데스크탑 연결을 허용해 주면 됩니다. 

 

우분투 원격 데스크탑 팩키지 설치 

  • rdesktop 설치 
sudo apt-get install rdesktop

 

root@ubuntu:~/Desktop# sudo apt-get install rdesktop
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  pcscd
The following NEW packages will be installed:
  rdesktop
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 222 kB of archives.
After this operation, 712 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 rdesktop amd64 1.9.0-2 [222 kB]
Fetched 222 kB in 1s (159 kB/s)    
Selecting previously unselected package rdesktop.
(Reading database ... 277511 files and directories currently installed.)
Preparing to unpack .../rdesktop_1.9.0-2_amd64.deb ...
Unpacking rdesktop (1.9.0-2) ...
Setting up rdesktop (1.9.0-2) ...
Processing triggers for man-db (2.9.1-1) ...

 

윈도우 서버 원격 데스크톱 허용

  • System -> 원격데스트 톱 -> 원격 데스크톱 활성화 켬

 

우분투 윈도우 원격 접속 

  • rdesktop  [윈도우ip]:[윈도우 원격접속포트]

728x90
반응형
728x90
반응형

이번글에서는 윈도우 환경에서 C 언어로 작성된 프로그램을 컴파일하고 실행하는 방법에 대해 알아보겠습니다. 

리눅스 환경에서  윈도우환경에서  gcc 설치후 C 코드 컴파일하고 실행 방법에 대해 소개 하도록 하겠습니다. 

 

환경 구성

Window 10  환경에서 VS Code 와 Mingw 를 설치하도록 하겠습니다. 

  • 윈도우 10 
  • Visual Studio Code (VS Code)
  • GCC 8 (Mingw)

GCC 8설치

 

아래 경로에서 다운로드를 받습니다. 

Installer 도 있지만 설치시 제 환경에서는 에러가 발생해서 바이너리 다운로드후 압축 해제 했습니다. 

 

https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/ 

 

하단 스크롤 하면 다운로드 매뉴가 나옵니다. 

 

Download x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z (MinGW-w64 - for 32 and 64 bit Windows)

A complete runtime environment for gcc The mingw-w64 project is a complete runtime environment for gcc to support binaries native to Windows 64-bit and 32-bit operating systems.

sourceforge.net

  • 다운로드 받은 바이너리를 C Drive 에 폴더를 생성하고 압축을 해제 합니다. 
  • mingw64 -> x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z 바이너리 압축 해제 

 

윈도우 환경 변수 설정 

  • 시스템 -> 시스템 속성 -> 환경 변수 -> 환경 변수 편집 -> C:\mingw64\bin 추가 

 

GCC 설치 버전 확인 

  • Win + R 버튼 클릭후 cmd 창에서 설치 버전을 확인 합니다.
C:\>gcc --version
gcc (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\>g++ --version
g++ (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

 

Visual Studio Code (VS Code) 설치 

아래 경로에서 Visual Studio Code 를 다운로드 받습니다. 

https://code.visualstudio.com/

 

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

 

 

VS Code  실행 및  C/C++ 확장 팩을 설치

  • VS code 가 설치가 완료 되었다면 c/c++ 확장팩 설치를 진행 합니다. 
  • Ctrl + Shift + x 
  • C/C++ Extension Pack

 

VS Code  C 컴파일 환경 설정 

  • Ctrl +Shift + P -> c/c++ Edit configurations 검색 -> 톱니바퀴 클릭 

 

 

gcc 컴파일 경로 설정 

  • UI 화면에서 설정을 변경 할수 있도 있고  c_cpp_properties.json 버튼을 클릭 하면 파일 에서 직접 수정 할수도 있습니다. 

 

C/C++ 환경 설정 

  • 컴파일러 경로 설정 
  • IntelliSense 모드 설정 
  • Include 경로 추가 

 

  •  c_cpp_properties.json 파일 
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:/Program Files (x86)/Windows Kits/8.0/Include/um",
                "C:/Program Files (x86)/Windows Kits/8.0/Include/shared",
                "C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64",
            "browse": {
                "path": []
            },
            "compilerPath": "C:/mingw64/bin/gcc.exe",
            "compilerArgs": []
        }
    ],
    "version": 4
}

 

빌드 환경 구성 

  • F1 버튼 클릭 -> Task: Configure Default build Task 검색 
  • tasks.json 편집 (gcc 설치한 디렉토리로 설정 합니다. 
{
    "version": "2.0.0",
    "runner": "terminal",
    "type": "shell",
    "echoCommand": true,
    "presentation": {
        "reveal": "always"
    },
    "tasks": [
        {
            "label": "save and compile for C++",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",
            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "save and compile for C",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",
            "problemMatcher": {
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "execute",
            "command": "cmd",
            "group": "build",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}"
            ],
            "problemMatcher": []
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 활성 파일 빌드",
            "command": "C:\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "-lm",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "디버거에서 생성된 작업입니다."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 활성 파일 빌드",
            "command": "C:\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "디버거에서 생성된 작업입니다."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 활성 파일 빌드",
            "command": "C:\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-lm"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "test"
        }
    ]
}

 

C 코드 테스트 

기본 테스트 

test.c 파일 을 만들어 테스트 코드를 작성합니다. 

#include <stdio.h>
int main()
{
    printf("Hello, world!\n");
    printf("C Program Compile Test \n");
    return 0;
}

 

실행 매뉴 버튼 클릭후 테스트 코드를 컴파일 및 실행 합니다. 

  • 디버깅 없이 실행 (Ctrl+F5)

 

테스트 결과 

 

입력변수 설정을 통한 컴파일 및 실행 

  • 컴파일 후에 입력 변수 설정을 통해 실행을 할수도 있습니다. 
  • 기존에 작성했던 코드를 조금 수정 합니다. 
#include <stdio.h>
int main(int argc, char *argv[])
{
    printf("1 번째 [%s]:\n",argv[1]);
    printf("2 번째 [%s]:\n",argv[2]);
    printf("Hello, world!\n");
    printf("C Program Compile Test \n");

    return 0;
}

 

  • 테스트 프로젝트 하위 .vscode 디렉 토리 밑에  launch.json 파일을 생성 합니다. 
  • .vscode 디렉토리 에는 기존에 환경 설정한 tasks.json , c_cpp_properties.json 파일도 생성되어 있습니다. 
  • 동일 디렉토리 launch.json 파일을 만들고 환경 설정 내용을 작성 합니다. 
  • 입력 값은  "args": ["1 args ","2 args "], 형식으로 작성합니다. 

 launch.json

{
    // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
    // 기존 특성에 대한 설명을 보려면 가리킵니다.
    // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc.exe - 활성 파일 빌드 및 디버그",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\build\\${fileBasenameNoExtension}.exe",
            "args": ["1 args ","2 args "],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "gdb에 자동 서식 지정 사용",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe 활성 파일 빌드"
        },    
    ]
}

 

실행 매뉴 버튼 클릭후 테스트 코드를 컴파일 및 실행 합니다. 

  • 디버깅 없이 실행 (Ctrl+F5)

실행을 하면 입력 한 변수 값도 실행시에 프로그램에 전달 할수 있습니다. 

 

 

728x90
반응형

+ Recent posts