[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
Java から mysql に接続する際に java.sql.SQLException: The server timezone value '????(?)' is unrecognized or represents more than one timezone.
と言われて上手く行かなかった。どうも TimeZone の引き渡しが上手く行っていないようだ。
とりあえず、接続時の URL に serverTimezone
の値を入れてやったらうまくいった。ただ、サーバ側のデフォルトタイムゾーンをきちっと定めてやれば動くようである。mysql の設定ファイルに default-time-zone
の値を加筆してやり、再起動すれば設定できるようである。
業務上 DB と付き合うことは今までほとんどなかったし、趣味でも DB 使わないといけない状態になるとは今までほとんどなかったので、ちょこちょこ「ここつまったー」とか書いていく。
なお、mysql-connector-java は 8.0.15 を使っていた。5.1.33 ~ 5.1.37 はその辺のバグがあって動かないという話もあるようだが、それには当たらないようだ。
この辺の話を考えたり解いたりするのに java - MySQL JDBC Driver 5.1.33 - Time Zone Issue - Stack Overflow にお世話になったりした。
会社で少し話題になったので nginx で接続元制限をかける手順をごりごり確認する。
Module ngx_http_access_module に詳しく書いてあるので、こちらを読もう。試しに以下のように設定してみる。実行する前に ifconfig (Windows なら ipconfig) コマンドを実行し、自分の持っている IP アドレスを確認しておく。これを試した時点では 192.168.1.17
だった。なので、 nginx.conf に次のように記述する。
server { # 中略 location /google { proxy_pass https://google.com; allow 192.168.1.17/32; deny all; } }
以上の設定をしたうえで nginx を再起動 (私の手元は ubuntu なので service nginx restart
)。http://localhost/google に手元からつなぐと127.0.0.1 からのアクセスと見られて403 が返ってくる。
http://192.168.1.17/google に手元から繋ぐと問題なく google に転送される。ただし、手元のスマートフォンから同じところにアクセスを試みると192.168.1.17からのアクセスではないので 403 が返ってくる。なお、上の記述だと /google
のみに設定しているので他には localhost からでも問題なくつなげる。
nginx デフォルトの 403 画面は可愛くないのでかわいいのに変更する。
server { # 中略 error_page 403 /forbidden.html; location = /forbidden.html { root /tmp; internal; } location /google { proxy_pass https://google.com; allow 192.168.1.17/32; deny all; } }
さらに /tmp
に forbidden.html
を配置し、かわいい内容を書いておく。この上でhttp://localhost/googleにアクセスを試みると /tmp/forbidden.html
の内容が表示されるはずである。
internal
を入れたことによってどんな影響があるのかは http://localhost/forbidden.html にアクセスしてみると分かる。/tmp/forbidden.html
の内容ではなく 404 が返ってくる。詳しい話は Module ngx_http_core_module に記載されている。error_page
についてはあまり説明はいらない気がするが Module ngx_http_core_module に同様に記載がある。
nginx には return なる機能があると Module ngx_http_rewrite_module にはある。これによると Stops processing and returns the specified
(処理を停止し、特定の HTTP ステータスコードをクライアントに返す。HTTP ステータスコードのルールに存在しない 444 を返そうとした場合、レスポンスヘッダの返答もなく接続を断ち切る)。最初に設定した接続元制限で接続を拒絶した場合に 403 すら返さず接続を切断してみる。code
to a client. The non-standard code 444 closes a connection without sending a response header.
server { # 中略 error_page 403 =444 /forbidden.html; location = /forbidden.html { return 444; } location /google { proxy_pass https://google.com; allow 192.168.1.17/32; deny all; } }
もちろん、418 とか 451 とかを返すこともできる。返したいかはともかくとして。
yaml をシェル内で扱いたい、という相談を後輩からされた。「今は シェルから sed でやっている。シェルから乗り換えるのは避けたい。何かいい手段はないか」……ちょっとぐぐってみたらみつかった。yq なる少し jq に似た名前のコマンドだ。
使い方は jq と同じであり、 jq 慣れしていればすぐに扱えるだろう。Python が入っていないと使えないが、今時 yaml を操作しなければならないような環境下ではだいたい Python が入っているだろうから気にならない。
業務で yaml や python を触る機会が増えていて少しつらいひよこであった。Python を読むのは OpenStack を扱っていた関係でそれなりに多かったが、Python を書くのは最近やっと始めたところ。オンセツールでも Python で書いてみるかな……最近会社で作ったアプリも Java8 で書いちゃったし……
会社の PC (Ubuntu) に Jenkins を入れようとした。が、うまくいかない。E: Sub-process /usr/bin/dpkg returned an error code (1) と怒られる。
$ sudo apt-get install jenkins Reading package lists... Done Building dependency tree Reading state information... Done jenkins is already the newest version (2.121.1). The following packages were automatically installed and are no longer required: linux-headers-4.4.0-101 linux-headers-4.4.0-101-generic linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic linux-headers-4.4.0-108 linux-headers-4.4.0-108-generic linux-headers-4.4.0-109 linux-headers-4.4.0-109-generic linux-headers-4.4.0-112 linux-headers-4.4.0-112-generic linux-headers-4.4.0-119 linux-headers-4.4.0-119-generic linux-headers-4.4.0-121 linux-headers-4.4.0-121-generic linux-headers-4.4.0-124 linux-headers-4.4.0-124-generic linux-image-4.4.0-101-generic linux-image-4.4.0-103-generic linux-image-4.4.0-104-generic linux-image-4.4.0-108-generic linux-image-4.4.0-109-generic linux-image-4.4.0-112-generic linux-image-4.4.0-119-generic linux-image-4.4.0-121-generic linux-image-4.4.0-124-generic Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 148 not upgraded. 1 not fully installed or removed. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] Setting up jenkins (2.121.1) ... Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details. invoke-rc.d: initscript jenkins, action "start" failed. dpkg: error processing package jenkins (--configure): subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: jenkins E: Sub-process /usr/bin/dpkg returned an error code (1)
ログから何となくわかる通り、Jenkins の設定中にうまくいかなかったようだ。
$ dpkg -l jenkins Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=======================-================-================-=================================================== iF jenkins 2.121.1 all Jenkins is an open source automation server which e
原因は /var/log/syslog を確認したらすぐに分かった。No Java executable found in current PATH だそうだ。apt 実行時のログに出ないのでスッと分からなかったが、冷静に考えればそりゃそうである。
$ cat syslog systemd[1]: Starting LSB: Start Jenkins at boot time... jenkins[22149]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin jenkins[22149]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 'type -p java' returns the java executable path
MySQL をお仕事でインストールしなきゃいけないことがちょこちょこあるのでメモ。ただ、ちょこちょこあるならもはやスクリプトにしたり、最初から入れたイメージを作った方がいい気もする。
# インストール $ sudo apt update $ sudo apt install mysql-server mysql-client
フルオープンにするなら /etc/mysql/mysql.conf.d/mysqld.cnf
を編集し、 bind-address
をコメントアウトすればよい。ないしは /etc/mysql/my.cnf
を編集し、bind-address
を設定する。この手の作業で入れる環境は大体内部の閉じられた環境だろうからフルオープンでよい気はする。
その後、$ sudo systemctl restart mysql
で再起動する。この後、新しくユーザを作り、接続元を設定したり権限を付与したりすること。
社内の 〇〇 さんが本番環境の接続情報 with パスワードをコードべた書き and 社内 GitLab に push していたのはちょっとどうかなって思った。