【Vagrant】 複数台構成の調査
環境 Vagrant 1.8.1 VirtualBox 5.0.12
Vagrantfileを以下のようにする。
Vagrant.configure(2) do |config| config.vm.provider "virtualbox" do |vb| vb.gui = true end config.vm.define "server1" do |server| config.vm.box = "bento/centos-7.1" server.vm.network "private_network", ip: "192.168.33.10" config.vm.provision "shell", path: "provision1.sh" end config.vm.define "server2" do |server| config.vm.box = "bento/centos-7.1" server.vm.network "private_network", ip: "192.168.33.11" config.vm.provision "shell", path: "provision2.sh" end # Plugin config.vbguest.auto_update = false end
でvagrant up
すれば両方起動。
どちらかにしたいときは
PS> vagrant up server1 PS> vagrant up server2
とかでOK。
で、ちょっと気になった事を確認してみた。
- プロビジョニングは別のものを指定できる
当たり前だけど可能。
ただ、デフォルトのホストとのファイル共有はserver1もserver2も同じ。
なので同じファイルを使うようなときは注意が必要。
- それぞれのサーバーへの接続
ホスト -> server1 : ssh 127.0.0.1:2222
ホスト -> server2 : ssh 127.0.0.1:2200
server1 -> server2 : ssh 192.168.33.11
server2 -> server1 : ssh 192.168.33.10
となる。つまりprivate_networkを設定してないと、ゲスト間は接続できない。
Proxyを乗り越えろ!
環境 Vagrant 1.8.1 VirtualBox 5.0.12
という事で、プロキシのある環境でgitとか、Vagrant等、随分引っかかって苦労したので、メモっとく。
Linux全般 / wget / curl
基本的に環境変数が使われる。
以下を実行するか、.bash_profile等にセットすればよい。
大文字と小文字が、アプリケーションによって異なる場合がある。
$ export http_proxy=http://<ユーザー名>:<パスワード>@proxy.server:port $ export https_proxy=https://<ユーザー名>:<パスワード>@proxy.server:port $ export HTTP_PROXY=http://<ユーザー名>:<パスワード>@proxy.server:port $ export HTTPS_PROXY=https://<ユーザー名>:<パスワード>@proxy.server:port
git
git configで設定。
$ git config --global http.proxy http://<ユーザー名>:<パスワード>@proxy.server:port $ git config --global https.proxy http://<ユーザー名>:<パスワード>@proxy.server:port
yum
【追記】以下でもできますが、基本的に環境変数がセットされてればOKみたいです。
/etc/yum.conf
にproxyを設定する。
以下を追加
proxy=http://proxy.server:port proxy_username=<ユーザー名> proxy_password=<パスワード>
mercurial
~/.hg
に設定を書いてもいいが、めったに使わないので、ワンライナーで。
$ hg --config http_proxy.host=http://<ユーザー名>:<パスワード>@proxy.server:port clone <リポジトリ> <ローカル名>
Vagrant
というか、vagrant up
とかを使うコンソール。
Linux系なら、環境変数をセットすればよい。
$ export http_proxy=http://<ユーザー名>:<パスワード>@proxy.server:port $ export https_proxy=https://<ユーザー名>:<パスワード>@proxy.server:port
VirtualBox
VirtualBoxの設定からプロキシをセット。
ただゲストOSがLinuxなら、.bash_profileに環境変数セットしても同じ
$ export http_proxy=http://<ユーザー名>:<パスワード>@proxy.server:port $ export https_proxy=https://<ユーザー名>:<パスワード>@proxy.server:port
msysgit
gitが使えればいい気がするけど、wgetとかしたいとき。
基本的にはLinuxと同じく環境変数をセットすればいい。
export http_proxy=http://<ユーザー名>:<パスワード>@proxy.server:port export https_proxy=https://<ユーザー名>:<パスワード>@proxy.server:port
これでOK。
【Play Framework】 PlayFramework最新版をインストール
環境 Play Framework 2.4.6 CentOS7.0
インストール
java,javacがなければ、インストールしておく。
$ # インストール $ cd /usr/local/src $ sudo wget https://downloads.typesafe.com/typesafe-activator/1.3.7/typesafe-activator-1.3.7-minimal.zip $ sudo unzip typesafe-activator-1.3.7-minimal.zip $ sudo chmod +x activator-1.3.7-minimal/activator $ # コマンドをショートカットで作成 $ cd /usr/local/bin $ sudo ln -s ../src/activator-1.3.7-minimal/activator . $ # 確認 $ activator -h Usage: activator <command> [options] ...<省略>
アプリケーションを作成
$ activator new myapp Fetching the latest list of templates... Browse the list of templates: http://typesafe.com/activator/templates Choose from these featured templates or enter a template name: 1) minimal-akka-java-seed 2) minimal-akka-scala-seed 3) minimal-java 4) minimal-scala 5) play-java 6) play-scala (hit tab to see a list of all templates) > play-scala OK, application "myapp" is being created using the "play-scala" template.
newすると、テンプレートを選択する。
activator new myapp play-scala
のようにすれば、ワンライナーでテンプレートを選択できる。
アプリケーション実行
$ cd myapp
$ activator run
これでhttp://<ホスト名>:9000
にアクセスする事で、サンプルページにアクセスできる。
おまけ:Vagrantで動かす
ポートをフォワードする必要がある。 Vagrantfileに以下を記述
Vagrant.configure(2) do |config| config.vm.network :forwarded_port, host: 9000, guest: 9000 end これで`http://127.0.0.1:9000`にてアクセス可能。
【Redis】 CentOS7にRedisの最新版をmakeインストール
環境 CentOS 7.0 Redis 3.0.6$nbsp;
yumのバージョンを確認してみる
とりあえずyumを確認。
$ sudo yum list redis sudo yum list redis Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.riken.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp Available Packages redis.x86_64 2.8.19-2.el7 epel
epelリポジトリからインストールできる模様。
ただバージョンが2系。
せっかくなので、3系をインストールしてみる。
最新版をmakeインストール
$ # ソースを取得 $ sudo wget http://download.redis.io/releases/redis-3.0.6.tar.gz $ # 展開 $ sudo tar zxvf redis-3.0.6.tar.gz $ cd redis-3.0.6 $ # インストール $ sudo make $ sudo make install
これでインストール完了。
インストールを確認。
$ . ~/.bash_profile $ which redis-cli /usr/local/bin/redis-cli
OK。
ただ設定ファイルredis.confが無い。
yumだと勝手に作られるが、tarボールだと手動で作る必要がある。
$ sudo mkdir /etc/redis/
$ sudo cp redis.conf /etc/redis/
設定ファイルを編集する。
とりあえず、デーモンモードに変更と、ログを出力しておく。
$ diff -u redis.conf.ORI redis.conf
--- redis.conf.ORI 2016-01-10 17:12:20.898328665 +0900 +++ redis.conf 2016-01-10 17:15:13.952769838 +0900 @@ -39,7 +39,7 @@ # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. -daemonize no +daemonize yes # When running daemonized, Redis writes a pid file in /var/run/redis.pid by # default. You can specify a custom pid file location here. @@ -105,7 +105,7 @@ # Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null -logfile "" +logfile "/var/log/redis.log" # To enable logging to the system logger, just set 'syslog-enabled' to yes, # and optionally update the other syslog parameters to suit your needs.
サービスを起動
$ sudo /usr/local/bin/redis-server /etc/redis/redis.conf
接続を確認する。
$ redis-cli ping PONG
接続OK。
毎度、サービス起動するときにコマンドを叩かなくても済むよう、.serviceファイルを作る。
$ vi /etc/systemd/system/redis.service
[Unit] Description=Load redis daemon. [Service] ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf RemainAfterExit=yes [Install] WantedBy=multi-user.target
ちなみにファイルの書き方は適当。
Linux - systemdの*.serviceファイルの書き方 - Qiita
こちらを参考にさせてもらいました。
本当はredisユーザーとか作って、User,Groupも指定するべきかも。
サービスの起動と、自動起動を設定。
$ # 起動 $ sudo systemctl start redis.service $ # 自動起動設定 $ sudo systemctl enable redis sudo systemctl status redis.service ● redis.service - Load redis daemon. Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled) Active: active (exited) since Sun 2016-01-10 17:38:28 JST; 4min 14s ago Main PID: 7473 (code=exited, status=0/SUCCESS) CGroup: /system.slice/redis.service └─7474 /usr/local/bin/redis-server *:6379 Jan 10 17:38:28 localhost.localdomain systemd[1]: Started Load redis daemon.. Jan 10 17:38:28 localhost.localdomain systemd[1]: Starting Load redis daemon.... $ # 接続確認 $ redis-cli ping PONG
とりあえず動いている。
【PHP】 PHPBrewでPHP7をインストール
環境 CentOS 7.0 phpbrew 1.20.5 PHP 7.0.1
PHPBrewを使って、PHP7を試してみる。
事前準備
PHPBrewを使うには、php-cli
の5.3以上が必要になる。
$ sudo yum install -y php-cli
そして、他に必要になるモジュールを追加。
Apacheと連携するので、httpdも追加。
httpdをインストールすると、同時にapxs(apacheに拡張モジュールを、コンパイルしてくれるツール)もインストールされる。
$ sudo yum install -y httpd httpd-devel $ sudo yum install -y bzip2-devel $ sudo yum install -y libxml2-devel $ sudo yum install -y libxslt-devel
apxsでモジュールを追加しるため、以下のディレクトリにパーミッションを付与。
sudo chmod -R oga+rw /usr/lib64/httpd/modules sudo chmod -R oga+rw /etc/httpd/conf
そして、GitHubからPHPBrewを取得する。PHPBrewはphpr形式で提供されているので、ファイルを取ってくれば動作する。
cd /usr/local/bin sudo curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew sudo chmod +x phpbrew
必要に応じて、. ~/.bash_profile
をしておく。
PHPBrewを使ったPHPのインストール
まず初期化する
$ phpbrew init
インストールできるPHPのバージョンを確認
$ phpbrew known ===> Fetching release list... [==================================================================] 1.31/1.31KB 100% 7.0: 7.0.1, 7.0.0 ... 5.6: 5.6.16, 5.6.15, 5.6.14, 5.6.13, 5.6.12, 5.6.11, 5.6.10, 5.6.9 ... 5.5: 5.5.30, 5.5.29, 5.5.28, 5.5.27, 5.5.26, 5.5.25, 5.5.24, 5.5.23 ... 5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 ... 5.3: 5.3.29, 5.3.28, 5.3.27, 5.3.26, 5.3.25, 5.3.24 ... You can run `phpbrew update` to get a newer release list.
このバージョンを選択できる。今回は最新の7.0.1をインストール。
yum install
とかだと、php-pdo,php-mysqlもyum
で導入できるが、phpbrew
だと独自のオプションを選択し導入する。
選択可能なオプションはいかのように確認できる。
$ phpbrew variants Variants: all, apxs2, bcmath, bz2, calendar, cgi, cli, ctype, curl, dba, debug, dom, embed, exif, fileinfo, filter, fpm, ftp, gcov, gd, gettext, gmp, hash, iconv, icu, imap, inifile, inline, intl, ipc, ipv6, json, kerberos, libgcc, mbregex, mbstring, mcrypt, mhash, mysql, opcache, openssl, pcntl, pcre, pdo, pgsql, phar, phpdbg, posix, readline, session, soap, sockets, sqlite, static, tidy, tokenizer, wddx, xml, xml_all, xmlrpc, zip, zlib, zts Virtual variants: dbs: sqlite, mysql, pgsql, pdo mb: mbstring, mbregex neutral: default: bcmath, bz2, calendar, cli, ctype, dom, fileinfo, filter, ipc, json, mbregex, mbstring, mhash, mcrypt, pcntl, pcre, pdo, phar, posix, readline, sockets, tokenizer, xml, curl, openssl, zip everything: dba, ipv6, dom, calendar, wddx, static, inifile, inline, cli, fpm, ftp, filter, gcov, zts, json, hash, exif, mbstring, mbregex, libgcc, pdo, posix, embed, sockets, debug, phpdbg, zip, bcmath, fileinfo, ctype, cgi, soap, pcntl, intl, phar, session, tokenizer, opcache, imap, tidy, kerberos, xmlrpc, pcre, mhash, mcrypt, zlib, curl, readline, gd, icu, openssl, mysql, sqlite, pgsql, xml, xml_all, gettext, iconv, bz2, ipc, gmp Using variants to build PHP: phpbrew install php-5.3.10 +default phpbrew install php-5.3.10 +mysql +pdo phpbrew install php-5.3.10 +mysql +pdo +apxs2 phpbrew install php-5.3.10 +mysql +pdo +apxs2=/usr/bin/apxs2
今回はPDOとMYSQLを選択し、PHP7.0.1を使えるようにする。
$ phpbrew install 7.0.1 +pdo +mysql +apxs2=/usr/bin/apxs ===> phpbrew will now build 7.0.1 ===> Loading and resolving variants... Checking distribution checksum... Checksum matched: c999d29cb8861aa71574a11e8c635691 ===> Distribution file was successfully extracted, skipping... Found existing Makefile, running make clean to ensure everything will be rebuilt. You can append --no-clean option after the install command if you don't want to rebuild. ===> Running make clean: make -C /home/vagrant/.phpbrew/build/php-7.0.1 --quiet clean ===> Applying patch - apxs2 module version name ... Found existing build.log, renaming it to /home/vagrant/.phpbrew/build/php-7.0.1/build.log.1451999982 ===> Configuring 7.0.1... Use tail command to see what's going on: $ tail -F /home/vagrant/.phpbrew/build/php-7.0.1/build.log ===> Building... Build finished: 3.3 minutes. Installing... ---> Creating php-fpm.conf ---> Creating php.ini ---> Copying /home/vagrant/.phpbrew/build/php-7.0.1/php.ini-development Found existing /home/vagrant/.phpbrew/php/php-7.0.1/etc/php.ini. ---> Found date.timezone is not set, patching... Congratulations! Now you have PHP with 7.0.1 as php-7.0.1 To use the newly built PHP, try the line(s) below: $ phpbrew use php-7.0.1 Or you can use switch command to switch your default php to php-7.0.1: $ phpbrew switch php-7.0.1 Enjoy!
これでphp7.0.1がコンパイルされる。 現在PHPBrewで使えるバージョンは以下で確認
$ phpbrew list * (system) php-7.0.1
ここで以下のコマンドを打っておく
$ . ~/.phpbrew/bashrc
一時的にバージョンを切り替える場合は
$ phpbrew use 7.0.1
デフォルトを変更するなら
$ phpbrew switch 7.0.1
とする。
$ php -v PHP 7.0.1 (cli) (built: Jan 5 2016 23:15:33) ( NTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
Apacheと連携
特に特別な事はなし。
httpd.conf
に以下の行を追加。
<IfModule mime_module> # etc. AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule>
AddType~の2行を、
その後、httpdをrestartすれば完了。