はじめに
前回zabbixをdocker-composeで構築しました。
今回はzabbixの管理画面にhttpsでログインする方法を残しておきます。
参考サイト
前回と同じです。
自己証明書は以前k8sのdashboard作成時に作った方法を使いました。
zabbixの管理画面にhttpsでログインする方法
公式に書いてあります。
/etc/ssl/apache2
The volume allows to enable HTTPS for the Zabbix web interface. The volume must contains two files ssl.crt and ssl.key prepared for Apache2 SSL connections.Please follow official Apache2 documentation to get more details about how to create certificate files.
意訳
/etc/ssl/apache2にssl.crtとssl.keyを用意して
ということで用意します。
自己証明書の作成
ssl.crtとssl.keyを自己証明書で作成します。
作成したらdocker-compose.ymlと同階層にcertsディレクトリを作成し、その中に配置する必要があるので、先にcertsディレクトリ作ってその中で作っちゃいます。
mkdir certs
cd certs
openssl genrsa 2048 > ssl.key
openssl req -new -key ssl.key > ssl.csr
echo subjectAltName=DNS:myzabbix > san.ext
openssl x509 -days 3650 -req -signkey ssl.key < ssl.csr > ssl.crt -extfile san.ext
作成したらdocker-compose.ymlと同階層にcertsディレクトリを作成し、その中に配置します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
one3@standalone:~/zabbix-docker-https/certs$ openssl genrsa 2048 > ssl.key Generating RSA private key, 2048 bit long modulus ........................................................................+++ .....................................................................................................................................+++ e is 65537 (0x010001) one3@standalone:~/zabbix-docker-https/certs$ openssl req -new -key ssl.key > ssl.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: one3@standalone:~/zabbix-docker-https/certs$ one3@standalone:~/zabbix-docker-https/certs$ echo subjectAltName=DNS:myzabbix > san.ext one3@standalone:~/zabbix-docker-https/certs$ openssl x509 -days 3650 -req -signkey ssl.key < ssl.csr > ssl.crt -extfile san.ext Signature ok subject=C = AU, ST = Some-State, O = Internet Widgits Pty Ltd Getting Private key one3@standalone:~/zabbix-docker-https/certs$ one3@standalone:~/zabbix-docker-https/certs$ ls san.ext ssl.crt ssl.csr ssl.key one3@standalone:~/zabbix-docker-https/certs$ one3@standalone:~/zabbix-docker-https/certs$ cd .. one3@standalone:~/zabbix-docker-https$ tree --charset=C . |-- certs | |-- san.ext | |-- ssl.crt | |-- ssl.csr | `-- ssl.key `-- docker-compose.yml 1 directory, 5 files |
docker-compose.yml
前回とあまり変わらないです。
zabbix_web:にvolumes:箇所を追加しただけです。
zabbix-web-apache-mysqlが80/tcpと443/tcpをexportしているので、
network_mode: “host”していればdocker-compose.yml側で設定はいらないです。
自端末のIPアドレスは192.168.0.18です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
version: "3" services: zabbix_db: image: mysql:5.7 environment: - MYSQL_DATABASE=zabbix - MYSQL_USER=zabbix - MYSQL_PASSWORD=password - MYSQL_ROOT_PASSWORD=password network_mode: "host" zabbix_server: image: zabbix/zabbix-server-mysql:alpine-3.4-latest environment: - DB_SERVER_HOST=192.168.0.18 - MYSQL_DATABASE=zabbix - MYSQL_USER=zabbix - MYSQL_PASSWORD=password - ZBX_DEBUGLEVEL=3 network_mode: "host" zabbix_web: image: zabbix/zabbix-web-apache-mysql:alpine-3.4-latest environment: - ZBX_SERVER_HOST=192.168.0.18 - DB_SERVER_HOST=192.168.0.18 - MYSQL_DATABASE=zabbix - MYSQL_USER=zabbix - MYSQL_PASSWORD=password - PHP_TZ=Asia/Tokyo volumes: - ./certs:/etc/ssl/apache2 network_mode: "host" zabbix_agent: image: zabbix/zabbix-agent:alpine-3.4-latest privileged: true environment: - ZBX_SERVER_HOST=192.168.0.18 volumes: - /dev/xvda1:/dev/xvda1 network_mode: "host" |
動作確認
で管理画面にアクセスできます。
初期のユーザー名/パスワードはadmin/zabbixです。
chromeで自己証明書だとこんな画面が出ますが、詳細設定から無理ありアクセスすれば「保護されていない通信」と表示されますが、httpsでアクセスできます。
最後に
公式に書いてある通りやっただけですが、便利ですね。
公式の用意してくれているDockerfileは参考になります。
コメント