技術ネタはQiitaに移りました。壁もどこぞに。

yum でインストールした Tomcat に JVM オプションを設定

TomcatJVM オプションを設定しようと思ったら、
通常、catalina.sh などを編集することになると思う。

ただ、yumTomcat をインストールした場合、
この catalina.sh は作成されず、Tomcat はデーモンとして登録される。

こんなときに、JVM オプションを設定しなければ
ならなくなったらどうしたらいいのか…。

いろいろとディレクトリをあさってみたところ、
tomcat.conf に CATALINA_OPTS というエントリを追記することで、
JVM オプションを追加できそうな雰囲気。

$ cat /usr/share/tomcat/conf/tomcat.conf
# System-wide configuration file for tomcat services
# This will be sourced by tomcat and any secondary service
# Values will be overridden by service-specific configuration
# files in /etc/sysconfig
#
# Use this one to change default values for all services
# Change the service specific ones to affect only one service
# (see, for instance, /etc/sysconfig/tomcat)
#

# Where your java installation lives
JAVA_HOME="/usr/lib/jvm/jre"

# Where your tomcat installation lives
CATALINA_BASE="/usr/share/tomcat"
CATALINA_HOME="/usr/share/tomcat"
JASPER_HOME="/usr/share/tomcat"
CATALINA_TMPDIR="/var/cache/tomcat/temp"

# You can pass some parameters to java here if you wish to
#JAVA_OPTS="-Xminf0.1 -Xmaxf0.3"

# Use JAVA_OPTS to set java.library.path for libtcnative.so
#JAVA_OPTS="-Djava.library.path=/usr/lib64"

# What user should run tomcat
TOMCAT_USER="tomcat"

# You can change your tomcat locale here
#LANG="en_US"

# Run tomcat under the Java Security Manager
SECURITY_MANAGER="false"

# Time to wait in seconds, before killing process
SHUTDOWN_WAIT="30"

# Whether to annoy the user with "attempting to shut down" messages or not
SHUTDOWN_VERBOSE="false"

# Set the TOMCAT_PID location
CATALINA_PID="/var/run/tomcat.pid"

# Connector port is 8080 for this tomcat instance
#CONNECTOR_PORT="8080"

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)

試しに末尾へ、以下を追加してみる。

CATALINA_OPTS="-Xms512M -Xmx1024M -XX:PermSize=512M -XX:MaxPermSize=1024M"

$ sudo vi /usr/share/tomcat/conf/tomcat.conf

...

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)

## JVM Options
CATALINA_OPTS="-Xms512M -Xmx1024M -XX:PermSize=512M -XX:MaxPermSize=1024M"

最後に Tomcat を再起動して、
ただしく設定されているかどうかを確認。

$ sudo systemctl restart tomcat

$ ps aux | grep catalina
tomcat    2466  134  9.4 3170640 115440 ?      Sl   17:20   0:04 java -Xms512M -Xmx1024M -XX:PermSize=512M -XX:MaxPermSize=1024M -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat/temp -Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start
yo1000    2480  0.0  0.0 112656   968 pts/1    S+   17:20   0:00 grep --color=auto catalina

よさげ。

Redis リモートアクセスと GUI クライアント

Redis のセットアップ自体は
以下記事のとおり早々に済ませていたものの、

CentOS7 セットアップ Redis - 作業ノート

設定関連については一切していなかったので
いざリモートホストから使おうとしても、
まだ接続ができない状態になっている。
そこで今回は、リモートホストから接続できるように設定を変更する。

/etc/redis.conf の64行目付近。
"bind" で検索してヒットした付近を変更する。
念のためファイルのバックアップをとってから。

sudo cp /etc/redis.conf /etc/redis.conf.0
sudo vi /etc/redis.conf
# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
bind 127.0.0.1

最後の "bind 127.0.0.1" に続いて、半角スペース区切りで
接続を許可する IP を追記する。

任意の IP アドレスからの接続を許可する場合は、
"0.0.0.0" を設定する。

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
bind 0.0.0.0

これでリモートホストからの接続ができるようになった。
確認を毎度コマンドでやるのも面倒かつ、可視性に欠けるので、
今回は GUI クライアント経由で接続を確認してみる。

Redis Desktop Manager というのが無償で使えて良さげ。
Redis Desktop Manager - Redis GUI management tool for Windows, Mac OS X, Ubuntu and Debian.

インストールしたら、接続を追加する。
サイドメニュー下部の[Add New Connection]から。

f:id:Yoichi-KIKUCHI:20150103001215p:plain

[Name]は任意の接続名。
[Host:]は接続先ホスト名、または IP アドレス。
[Port:]は接続ポート。デフォルト "6379"。

f:id:Yoichi-KIKUCHI:20150103001305p:plain

これで接続が確認できた。

f:id:Yoichi-KIKUCHI:20150103001851p:plain

IntelliJ IDEA Tomcat ログの Output コンソール文字化け

デフォだと Tomcat ログ側の文字コードUTF-8 になっていないようで
Output コンソールのところどころで文字が ? に化けてしまう。
今回はこれに対応。

未設定状態だとこう。

f:id:Yoichi-KIKUCHI:20141231140907p:plain

Tomcat の起動構成を編集。
VM options:]に "-Dfile.encoding=UTF-8" を設定する。

f:id:Yoichi-KIKUCHI:20141230151413p:plain

f:id:Yoichi-KIKUCHI:20141231141059p:plain

f:id:Yoichi-KIKUCHI:20141231141128p:plain

無事に文字化けがなおった。

f:id:Yoichi-KIKUCHI:20141231141354p:plain

IntelliJ IDEA アプリケーションコンテキストの設定

おもに Java で書いてると離れられなくなる IntelliJ
軽快で補完も優秀なので大変便利に使えるのだが、
ときどき他の IDE と設定の方法が違ったりして手が止まることがある。
今回はそんなもののひとつである、アプリケーションコンテキストについて。

Tomcat なんかでデバッグ起動する場合、Eclipse などでは
プロジェクト名がアプリケーションコンテキストとして使用されるが、
IntelliJ ではこれが異なる。

デフォのままで起動すると、"localhost:8080" に
アプリケーションがデプロイされる。
このとき、アプリケーションコンテキストは "/" になっているよう。

ただ、実際にはやはり、war の名前がコンテキストになる場合が
多いと思われるので、localhost:8080/appctx のように
デプロイされて欲しいところ。

以下手順。
まずは画面上部の起動構成のプルダウンから、
[Edit Configurations…]を選択。

f:id:Yoichi-KIKUCHI:20141230151413p:plain

サイドメニューから、変更する起動構成(今回は "Tomcat 7.0")を選択する。
[Server]タブでは[Startup page:]が、
"http://localhost:8080/" になっていることが確認できる。

f:id:Yoichi-KIKUCHI:20141230151618p:plain

次に[Deployment]タブに移動する。
[Application context:]が、"/" になっていることが確認できる。

f:id:Yoichi-KIKUCHI:20141230152048p:plain

ここを編集することで、任意のアプリケーションコンテキストを
設定することができる。今回は、"appctx" としてみる。
デフォが "/" だったからといって、末尾に "/" をつけてはいけない。

f:id:Yoichi-KIKUCHI:20141230152151p:plain

アプリケーションコンテキストを設定できたので、
これで起動すれば、アプリケーションは
"localhost:8080/appctx" にデプロイされる。

しかし、このままだとサーバー起動時にいっしょに開くブラウザの初期 URL は、
"http://localhost:8080/" のままなので、起動直後は 404 が表示されてしまう。
そこで、仕上げに[Server]タブに戻り、[Startup page:]を編集する。

[Startup page:]に、先ほど設定したアプリケーションコンテキストを
反映して、"http://localhost:8080/appctx" を入力したら今度こそ完了。

f:id:Yoichi-KIKUCHI:20141230152730p:plain

CentOS7 セットアップ MariaDB - 文字コード設定

MySQL のままな部分が多いので、文字コード確認しておく。
きっとどっかに latin1 がいるんだろ…と思いつつ。

ググりながら設定確認と変更していく。
MariaDB で日本語を扱う場合の文字コードの設定 | 雪猫ノート

$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye

やっぱりあった、latin1。
後から変えるのはすごく大変なので今のうちに。

そして設定ファイルまで MySQL 時代のまま。

$ cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

/etc/my.cnf.d にあるファイルがインクルードされるよう。
なんでこんなに MySQL なんだろう…。
もしかして MySQL から設定ファイルとかもろもろ
そのまま移行とかできたりするんだろうか。

[mysqld] に、character-set-server = utf8 を追記。

$ sudo vi /etc/my.cnf.d/server.cnf

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
character-set-server = utf8

# this is only for embedded server
[embedded]

# This group is only read by MariaDB-5.5 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mysqld-5.5]

# These two groups are only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

[mariadb-5.5]

サービスを再起動して、文字コードを確認。

$ sudo systemctl restart mariadb

$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye

CentOS7 セットアップ MariaDB

つづいて RDB
べつになんでもいいんだけど、今回は Maria を試す。
といっても MySQL と何ら変わらないはず…。

$ yum list | grep mariadb
mariadb-libs.x86_64                     1:5.5.40-1.el7_0               @CentOS-7-update
mariadb.x86_64                          1:5.5.40-1.el7_0               updates
mariadb-bench.x86_64                    1:5.5.40-1.el7_0               updates
mariadb-devel.i686                      1:5.5.40-1.el7_0               updates
mariadb-devel.x86_64                    1:5.5.40-1.el7_0               updates
mariadb-embedded.i686                   1:5.5.40-1.el7_0               updates
mariadb-embedded.x86_64                 1:5.5.40-1.el7_0               updates
mariadb-embedded-devel.i686             1:5.5.40-1.el7_0               updates
mariadb-embedded-devel.x86_64           1:5.5.40-1.el7_0               updates
mariadb-libs.i686                       1:5.5.40-1.el7_0               updates
mariadb-server.x86_64                   1:5.5.40-1.el7_0               updates
mariadb-test.x86_64                     1:5.5.40-1.el7_0               updates

$ sudo yum install mariadb mariadb-server mariadb-devel mariadb-libs

$ systemctl status mariadb
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
   Active: inactive (dead)

入った。
起動してみる。

$ sudo systemctl start mariadb
$ systemctl status mariadb
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
   Active: active (running) since 月 2014-12-29 20:23:53 JST; 4s ago
  Process: 19850 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 19770 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 19849 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─19849 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─20006 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/...

ところどころ MySQL の文字。
わかるけどさあ…もうちょっとなんとかならんの。

そしてクライアントも MySQL という…。

$ mariadb
-bash: mariadb: コマンドが見つかりません

$ maria
-bash: maria: コマンドが見つかりません

$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

もうちょっとちゃんと Maria にしてほしかったな…。

CentOS7 セットアップ Jenkins

つづいて Jenkins。
公式サイト見る限り、最近だと yum 経由でのインストールも出来るよう。
今回はこれ試してみることにする。

サイトの説明に従って。
http://pkg.jenkins-ci.org/redhat/

$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

yum list でリポジトリ追加されていることを確認。 念のため update もしておく。

$ yum list | grep jenkins
hudson.noarch                           1.395-1.1                      jenkins
jenkins.noarch                          1.595-1.1                      jenkins

$ sudo yum update

リポジトリを確認したのでインストールする。
けっこうサイズが大きいので多少時間がかかる。

$ sudo yum install jenkins

$ systemctl status jenkins
jenkins.service - LSB: Jenkins continuous build server
   Loaded: loaded (/etc/rc.d/init.d/jenkins)
   Active: inactive (dead)

入った。
すぐ起ち上げたいとこだけど、Tomcat あたりが
デフォルトポートで上がってるとポートがぶつかるので
上がっているようであれば先に止めておいてから起動する。

$ sudo systemctl stop tomcat

$ sudo systemctl start jenkins
jenkins.service - LSB: Jenkins continuous build server
   Loaded: loaded (/etc/rc.d/init.d/jenkins)
   Active: active (running) since 月 2014-12-29 11:18:43 JST; 3min 28s ago
  Process: 18745 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/jenkins.service
           └─18758 java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -ja...

起動できた。
アクセスするときはブラウザから、{hostname or ip-address}:8080 で。
ひさびさの Jenkins はずいぶんデザインもスッキリして良くなってた。
古い Jenkins はあのスタイルがダサくて、画面見るたびに
ずっとやる気なくしてたので、この Jenkins は好きになれそうでよい。

f:id:Yoichi-KIKUCHI:20141229112904p:plain