SSH 터널링은 Slave Server에 설정한다.
# ssh -CNf -L3307:127.0.0.1:3306 mrbt@123.456.789.012
-f : Requests ssh to go to background just before command execution.
-C : Requests compression of all data
-N : Do not execute a remote command. This is useful for just forwarding ports
-C : Requests compression of all data
-N : Do not execute a remote command. This is useful for just forwarding ports
그리고 Password를 입력하면 Slave와 Master간에 터널링이 된다.
# netstats -an | grep LISTEN
위 명령으로 3307 포트가 열려있는 것을 확인할 수 있다.
위 터널링은 재부팅되면 초기화되므로 재부팅시 활성화 되도록 해본다.
/root/sshlogin 파일 생성
#!/usr/bin/expect
spawn bash -c "ssh -CNf -L3307:127.0.0.1:3306 mrbt@123.456.789.012"
expect -re "Password:"
sleep 0.2
send "비밀번호\r"
interact
spawn bash -c "ssh -CNf -L3307:127.0.0.1:3306 mrbt@123.456.789.012"
expect -re "Password:"
sleep 0.2
send "비밀번호\r"
interact
만일 expect가 없는 경우 설치해줘야 한다.
저장 후 해당 파일에 700 권한을 주고
/etc/rc.local 에 /root/sshlogin 을 추가해주면 시스템 부팅시 해당 파일을 실행하게 된다.