[hardhat] hardhat network에서 다른 계정인 척 쓰기

const hwwallet = "0xda50da50da50da50da50da50da50da50da50da50";

//  impersonating HW wallet
await network.provider.request({
  method: "hardhat_impersonateAccount",
  params: [hwwallet],
});

const _master = await ethers.getSigner(hwwallet);
_master.getFeeData = async () => {
  return {
    gasPrice: ethers.BigNumber.from(0),
    lastBaseFeePerGas: ethers.BigNumber.from(0),
    maxFeePerGas: ethers.utils.parseUnits("800", "gwei"),
    maxPriorityFeePerGas: ethers.utils.parseUnits("800", "gwei"),
  };
};
master = _master;

console.log('master: ', await master.getAddress());

[docker] Docker Swarm

도커 스웜 상태 보기

docker info | grep Swarm

클러스터 관리

도커 스웜 매니저 노드 시작

docker swarm init --advertise-addr 192.168.0.100

도커 스웜 워커가 클러스터에 참여

docker swarm join --token SWMTKN-1-sdlfhsalkghsalghlsahglksahglsakg... 192.168.0.100:2377

도커 스웜 클러스터 확인

docker node ls

새로운 매니저 추가를 위한 토큰 생성

docker swarm join-token manager

워커 노드에서 참여 더이상 하지 않고 노드 삭제

docker swarm leave

매니저 노드의 참여 삭제

docker swarm leave --force

워커 노드를 매니저 노드로 변경. 매니저 노드에서

docker node promote swarm-worker1

매니저 노드를 워커 노드로 변경.

docker node demote swarm-worker1

서비스

서비스 생성

docker service create \
ubuntu:14.04 \
/bin/sh -c "while true; do echo hello world; sleep 1; done"

서비스 목록 확인

docker service ls

서비스 정보 확인

docker service ps [service name]

서비스 삭제

docker service rm [service name]

secret / config

secret 생성

echo 1q2w3e4r | docker secret create my_mysql_password -

secret 사용 (기본 값은 테이너 내부의 /run/secrets/ 디렉토리에 마운트됨)

docker service create \
 --name mysql \
 --replicas 1 \
 --secret source=my_mysql_password,target=mysql_root_password \
 --secret source=my_mysql_password,target=/home/mysql_root_password \
 -e MYSQL_ROOT_PASSWORD_FILE="/run/secrets/mysql_root_password" \
 ...
 mysql:5.7

config 생성

docker config create registry-config config.yml

config 목록 확인

docker config ls

config 내용 확인

docker config inspect registry-config

config로 입력된 값 확인. config 내용 확인에서 “Spec” / “Data” 내에 dmVyc21vbjog… 이 있었다고 하면, 해당 내용은 base64로 encoding 되어 있기 때문에..

echo dmVyc21vbjog... | base64 -d

config 사용

docker service create --name yml_registry -p 5000:5000 \
 --config source=registry-config,target=/etc/docker/registry/config.yml \
 registry:2.6

변경은 docker service update--config-rm, --config-add, --secret-rm, --secret-add 로 삭제, 추가 가능.

도커 스웜 네트워크

네트워크 목록 확인

docker network ls

오버레이 네트워크 생성

docker network create \
--subnet 10.0.9.0/24 \
-d overlay \
myoverlay

오버레이 네트워크 사용

docker service create --name overlay_service \
--network myoverlay \
--replicas 2 \
dasomoli/book:hostname

docker run –net 으로 지정해서 사용 가능한 오버레이 네트워크 생성

docker network create \
-d overlay \
--attachable \
myoverlay2

[Linux] KVM의 Bridge mode network 사용 시 네트워크 사용 불가 문제

KVM 사용 시 Bridge mode로 GuestOS에 네트워크 셋팅을 해도 동작을 안하는 경우가 있다. 게이트웨이나 DNS로 ping조차 안가는데, docker 와 함께 사용 시 문제가 발생한다.

docker가 iptables 의 FORWARD chain의 정책을 DROP으로 해버리기 때문이다.

oot@justiny-desktop:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy DROP)
target     prot opt source               destination         
DOCKER-USER  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (1 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination         
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere 

다음처럼 해주면 잘된다.

# iptables -A FORWARD -i br0 -o br0 -j ACCEPT

[Docker] docker commands

실행 중인 docker process (machine) 보기

docker ps

실행 중 + 실행 중이 아닌 docker process 보기

docker ps -a

docker 이미지 보기

docker images

docker process 삭제

docker rm -rf [container name]

docker 이미지 삭제

docker rmi [image name]

docker 이미지 가져오기

docker pull [image name]

docker process 시작

docker start [container name]

docker process 중지

docker stop [container name]

실행 중인 모든 컨테이너 강제 종료

docker kill $(docker ps -q -f status=running)

실행 중인 모든 컨테이너 중지

docker stop $(docker ps -q -f status=running)

종료된 모든 컨테이너 삭제

docker rm $(docker ps -q -f status=exited)

시스템 상의 모든 이미지 삭제

docker image rm -f $(docker image ls -q)

docker 로그 보기

docker logs [container name]

docker network 삭제

docker network prune -f

alias해서 간편히 사용하기

alias dockerkill='docker kill $(docker ps -q -f status=running)'
alias dockerstop='docker stop $(docker ps -q -f status=running)'
alias dockerrm='docker rm $(docker ps -q -f status=exited)'
alias dockerimgrm='docker image rm -f $(docker image ls -q)'
alias dockernetprune='docker network prune -f'

docker cli 실행

$ docker exec -it cli /bin/bash

건물 내부 배선 DIY

건물 내부의 배선을 위한 관로를 이용해 네트워크 배선을 바꿀 수 있다.

아파트의 경우 약전설비 평면도를 관리 사무소에서 준다고 한다. 이걸 보면 좀 편하게 할 수 있다고 한다.

관로를 탐색하거나, 선을 넣을 때는 안내선(현장용어 요비선)을 사용한다. 영어로 검색할 때는 Cable puller 혹은 fishing tape라고 검색하면 나오더라.

[RaspberryPi] Torrent 머신 만들기

Torrent 파일을 등록해놓으면, 집에 있는 서버에 해당 파일을 자동으로 다운로드 받아놓는다. transmission을 설치하면 된다.

# apt-get install transmission-cli transmission-common transmission-daemon
# service transmission-daemon stop
# vi /etc/transmission-daemon/settings.json

설정 파일의 다음 항목을 수정한다.

"download-dir": "/mnt/NAS/TorrentDownload",
"rpc-username": "dasomoli",
"rpc-password": "password",
"rpc-whitelist-enabled": false,
"umask": 2,

업로드 속도를 제한하고 싶다면 다음을 수정한다. 예를 들어, 10 KB/sec 로 제한한다면

"speed-limit-up": 10,
"speed-limit-up-enabled": true,

기본 포트를 바꾸고 싶다면 다음을 수정한다.

"rpc-port": 9000

# service transmission-daemon reload
# usermod -aG debian-transmission dasomoli

download-dir은 다운로드 받을 디렉토리, rpc-username은 웹 인터페이스로 들어갈 때 로그인 할 ID, rpc-password는 그 Password이다. rpc-whitelist-enabled를 false 로 설정하면, 말 그대로 whitelist를 사용하지 않으므로, 어디에서든 접속이 가능하다.

접속은 기본은 9091 포트로 접속하면 된다. 위에선 9000으로 바꿨다. 하지만, 포트 번호를 치긴 귀찮으므로 apache2의 proxy를 이용해서 접속하자.

# vi /etc/apache2/sites-available/torrent.dasomoli.org.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName torrent.dasomoli.org
        ServerAdmin dasomoli@gmail.com

        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/torrent.log
        CustomLog ${APACHE_LOG_DIR}/torrent.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

이제 proxy 모듈을 enable하고, site를 enable한 후, apache2를 재시작하자.

# a2enmod proxy
# a2enmod proxy_http
# a2ensite torrent.dasomoli.org.conf
# service apache2 restart

# sudo service transmission-daemon start

이제 http://torrent.dasomoli.org 로 접속하면 된다.
당연히 미리 DNS설정은 되어 있어야 한다.

부팅 시에 Web UI 가 연결이 안되는 경우가 있는데, 이 때는 transmission-daemon을 reload 하면 된다. 수많은 해결(이라고 주장하는) 방법이 있지만, 가장 간단하면서 잘 동작하는 방법은 그냥 raspi-config에서 “Network at Boot:”의 “Wait for network”을 체크하는 것이다.

가장 간단하지만 잘 동작하는 허무한 해결책…

참고: https://askubuntu.com/questions/157455/how-to-change-the-default-permissions-of-files-created-by-transmission-daemon

Virtual PC의 Host와 VM간의 네트워킹을 위해…

Virtual PC 2007과 같은 가상화 소프트웨어에서 물리적 네트워크를 이용하지 않고 서로간의 네트워크를 구성하기 위해서는 어떻게 해야할까.
Microsoft loopback adapter를 사용하면 된다.
Microsoft loopback adpater를 사용하기 위한 절차는 다음과 같다.

Host 컴퓨터에서..
1) 제어판 / 새 하드웨어 추가
2) “예, 하드웨어를 이미 연결했습니다.”
3) “설치된 하드웨어” 목록에서 가장 아래의 “새 하드웨어 장치 추가”
4) “목록에서 직접 선택한 하드웨어 설치(고급)”
5) “일반 하드웨어 종류” 목록에서 “네트워크 어댑터”
6) “제조업체” 목록에서 “Microsoft” / “네트워크 어댑터”에서 “Microsoft Loopback Adapter”
7) 추가된 Microsoft Loopback Adapter의 로컬 연결 영역의 TCP/IP 주소를 Static으로 임의 주소 설정(192.168.x.x)

VM 에서..
1) 셋팅에서 네트워크 어댑터를 Microsoft Loopback Adapter 로 설정 후 Static으로 임의 주소 설정(192.168.x.y)

이렇게 하면 둘 사이의 네트워킹이 가능한 것을 볼 수 있다. 안된다면 방화벽 설정을 확인하라!