1. Mosquitto Build at CentOS 7 참조하여 Mosquitto 설치
2. auth-plug.so 빌드
2.1 mosquitto-auth-plug 소스 다운로드
# git clone https://github.com/jpmens/mosquitto-auth-plug.git
# cd mosquitto-auth-plug
# cp config.mk.in config.mk
# yum install mysql-devel
# make & make install
# mv auth-plug.so /etc/mosquitto/
2.2 이미 설치된 mosquitto 의 설정파일(mosquitto.conf)를 수정한다.
# vi mosquitto.conf
auth_plugin /etc/mosquitto/auth-plug.so
auth_opt_backends mysql
auth_opt_host localhost
auth_opt_port 3306
auth_opt_dbname market
auth_opt_user root
auth_opt_pass 123456
auth_opt_userquery SELECT pw FROM users WHERE username = ‘%s’
auth_opt_superquery SELECT COUNT(*) FROM users WHERE username = ‘%s’ AND super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = ‘%s’) AND (rw >= %d)
auth_opt_anonusername AnonymouS
2.3 Table(users, acls) 생성
* users, acls 테이블 생성
mosquitto-auth-plug 디렉토리의 np( mosquitto-auth-plug 컴파일시 생성) 실행파일을 이용하여 PBKDF2 (Password-Based Key Derivation Function 2) 생성하여 users 테이블에 저장.
mosquitto_sub, mosquitto_pub 시에는 오리지널 키를 저장.
2.4 mosquitto broker 실행
# mosquitto -c mosquitto.conf -d -v
2.5 subscribe
# mosquitto_sub -h localhost -p 8883 --cafile /etc/mosquitto/ca_certificates/ca.crt -t hello/world/myid -u jjolie -P 2222
//개인 아이디로 subscription, -u : username, -P: password
2.6 publiish
# mosquitto_pub -h localhost -p 8883 --cafile /etc/mosquitto/ca_certificates/ca.crt -t hello/world/myid -u jjolie -P 2222 -m "Test is Test"
'MQTT > Mosquitto' 카테고리의 다른 글
MQTT(Mosquitto) SSL/TLS 적용 (0) | 2016.02.16 |
---|---|
Mosquitto Build at CentOS 7 (2) | 2016.02.04 |