리눅스는 Debian 리눅스를 기준으로 합니다.


/etc/mysql/my.cnf 파일수정


bind-address = 0.0.0.0


위 bind-address = 0.0.0.0 을 추가해줍시다.



사용자 작성, 권한 부여


# mysql -u root -p MariaDB [(none)]> create database etssun_db; // 데이터베이스 생성 MariaDB [(none)]> create user 'etssun'@'%' identified by 'root'; // etssun 이라는 계정을 비밀번호를 root로 생성 MariaDB [(none)]> grant all privileges on etssun_db.* to etssun@'%'; //etssun_db 라는 데이터베이스의 권한을 etssun 에게 줌 MariaDB [(none)]> flush privileges; // 설정 바로적용 # mysqladmin -u root -p reload # service mysql restart // 서비스 재시작


방화벽(Firewall) 설정


   # iptables -I INPUT 1 -p tcp --dport 3306 -j ACCEPT
   # iptables -I OUTPUT -p tcp --dport 3306 -j ACCEPT
   # iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT



클라이언트에서 정상적으로 접속되는지 확인


JDBC 커넥터는

https://downloads.mariadb.org/connector-java/

위 링크에서 다운로드 가능합니다.


다운로드 받은 커넥터는 라이브러리에 추가해준뒤 데이터베이스 커넥션 소스에서 드라이버를 임포트 해줍니다.

import org.mariadb.jdbc.Driver;


connectToDB 라는 예제 메소드를 작성해보았습니다.

    private static Connection connectToDB() {
        try {
            Class.forName("org.mariadb.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
                String jdbcUrl="jdbc:mariadb://localhost:3306/testdb?autoReconnect=true";
                String userId="root";
                String userPass="root";
                Connection con = DriverManager.getConnection(jdbcUrl,userId,userPass);
            if (!propsInited) {
                long timeout = getWaitTimeout(con);
                if (timeout == -1) {
                } else {
                    connectionTimeOut = timeout;
                }
                propsInited = true;
            }
            return con;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }


String 문자열을 선언해서 유저 아이디와 유저 패스워드를 더욱 간단히 설정할 수 있게 소스를 구성하였습니다.

jdbc연결 Url에서 jdbc:mysql 가 아닌 jdbc:mariadb로


역시 mysql의 업그레이드 버전이라 그런건지 소스 구성도 mysql JDBC연동 소스와 매우 흡사하다고 볼 수 있습니다.

SNAT(Source Network Address Translation, 출발지 주소 변환)


# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to 203.230.7.1

  -192.168.0.0/24가 출발지 주소이고 eth0으로 나가는 패킷에 대하여 203.230.7.1 로 SNAT 시켜준다.



DNAT(Destinaton Network Address Translation, 목적지 주소 변환)


# iptables -t nat -A PREROUTING -d 203.230.7.1 -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.0.1

  -eth0의 203.20.7.1주소로 들어오는 목적지 포트번호가 80인 tcp패킷에 대하여 192.168.0.1로 DNAT 시켜준다

+ Recent posts