【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すれば完了。
【Vagrant】 apacheの設定方法
環境 CentOS 7.0 apache2.4.6
httpdのインストール、起動はVagrantに限らず、通常のCentOS7の手順と同じ。
$ sudo yum install -y httpd httpd-devel $ sudo systemctl start httpd
自動起動の設定をするなら、
$ sudo systemctl enable httpd.service
これで状態を確認すると、
sudo systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2016-01-05 22:33:04 JST; 6min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 3066 (httpd) Status: "Total requests: 10; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─3066 /usr/sbin/httpd -DFOREGROUND ├─3067 /usr/sbin/httpd -DFOREGROUND ├─3068 /usr/sbin/httpd -DFOREGROUND ├─3069 /usr/sbin/httpd -DFOREGROUND ├─3070 /usr/sbin/httpd -DFOREGROUND ├─3071 /usr/sbin/httpd -DFOREGROUND └─3072 /usr/sbin/httpd -DFOREGROUND Jan 05 22:33:03 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... Jan 05 22:33:04 localhost.localdomain httpd[3066]: AH00558: httpd: Could not reliably determine the server's fully qualifi...ssage Jan 05 22:33:04 localhost.localdomain systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
さてこれにアクセスできるようにするには、Vagrantfileの以下の行からコメントをはずせばよい。
config.vm.network "private_network", ip: "192.168.33.10"
これで、vagrant reload
し、192.168.33.10
にブラウザからアクセスすればよい。
【Node.js】 いつの間にかバージョン表記が変わってた
環境 CentOS 7.0 Node.js 5.3.0
Node.jsを最新版にしようと思って、最新版を調べたら、バージョンが5.3.0?
□ CentOS7.0にNode.js最新版をインストール - takafumi blog
のときは0.12.2とかだったのに。
で気が付いたんですが、Node.jsとio.jsが統合したんでしたね。
バージョンがio.jsを引き継いで、3から4として扱われたらしい。
□ JavaScriptプラットフォーム「Node.js v4.0.0」がリリース、io.jsと統合し、今後は定期的なリリースに移行:CodeZine(コードジン)
インストール方法は変わりなし。
【Vagrant】 プロビジョニングで環境を自動構築
環境 Vagrant 1.8.1 VirtualBox 5.0.12
プロビジョニングの実行タイミング
はじめてvagrant up
を行ったときに、実行される処理。
2回目以降は以下のようなメッセージが表示されている。
==> default: flag to force provisioning. Provisioners marked to run always will still run.
明示的に、プロビジョニングを実行する場合は
vagrant up --provision
vagrant reload --provision
とする。
プロビジョニングの書き方
1. Vagrantfileにインラインで書く
以下のように書く。
Vagrant.configure("2") do |config| config.vm.provision "shell", inline: <<-SHELL echo 'HELLO!' date yum insatall -y mysql-server SHELL end
以下のようにも書ける。
script = <<SCRIPT echo 'HELLO!' date yum insatall -y mysql-server SCRIPT Vagrant.configure("2") do |config| config.vm.provision :shell, :inline => script end
2. 別ファイルに書く
Vagrant.configure("2") do |config| config.vm.provision "shell", path: "provision.sh" end
pathの部分はホスト側(Windows)のパスになる。
ただし実行するファイル(provision.sh)内のパスは、ゲスト側(CentOS)のパスになる事に注意。
chefやansibleも同様に書ける。
と言う事で作ってみた。
最小限の構成だけど、完全に自動化しようとすると結構大変。
これで今後は、デスクトップPCとノートPCの環境が統一できるかな?