Fedora22のログインシェルを楽しげに表示する
ログインシェルをこうする。
楽しげなパッケージをインストール
[root@host ~]# yum install cowsay fortune-mod figlet Yum command has been deprecated, redirecting to '/usr/bin/dnf install cowsay fortune-mod figlet'.
Fedora22からyumの代わりにdnfというパッケージ管理が採用された。
yumはpython2でしか動かない、Fedora23でpython3が入る予定。
dnf install cowsay fortune-mod figlet
.bashrcに以下を記載
exec fortune | cowsay figlet -f slant Welcome to the `hostname`
sshなどでログインすると牛が毎回しゃべる。
phoenix app using systemd on fedora22(GMO Conoha)
.serviceファイルを作る
[root@host ~]# touch /usr/lib/systemd/system/phoenix.service [root@host ~]# vim /usr/lib/systemd/system/phoenix.service [root@host ~]# cat /usr/lib/systemd/system/phoenix.service [Unit] Description = hello phoenix [Service] EnvironmentFile=/etc/environments/phoenix WorkingDirectory=/home/dela/www/hello/ ExecStart = /usr/local/src/elixir-1.1.1/bin/elixir -pa _build/prod/consolidated -S /usr/local/src/elixir-1.1.1/bin/mix phoenix.server Restart = always Type = simple User = dela [Install] WantedBy = multi-user.target
環境変数もファイルへ記述
[root@host ~]# mkdir /etc/environments/ [root@host ~]# vim /etc/environments/phoenix [root@host ~]# cat /etc/environments/phoenix MIX_ENV=prod PORT=4001
serviceが認識されているか確認
[root@host ~]# systemctl list-unit-files --type=service | grep phoenix phoenix.service disabled
自動起動に登録
[root@host ~]# sudo systemctl enable phoenix Created symlink from /etc/systemd/system/multi-user.target.wants/phoenix.service to /usr/lib/systemd/system/phoenix.service. [root@host ~]# systemctl list-unit-files --type=service | grep phoenix phoenix.service enabled
デーモン起動
[root@host ~]# sudo systemctl start phoenix
build nginx proxy for elixir phoenix app on fedora22(GMO Conoha)
phoenixアプリをポート80で動かせたけど、
別のサービスも同じサーバー上で動かすのを想定してnginxのproxyを立てた。
fedora使っていて思うのはパッケージが新しいバージョンを追いかけてるのと、
ssdのせいかもしれないけどインストール終わるがすごく速い。快適。
現在のstableバージョンがyumで入る。
[root@host ~]# yum install nginx #ささー [root@host ~]# nginx -v nginx version: nginx/1.8.0
nginx.serviceを自ら用意しないといけないかなと思ったけど自動で作られてた。
[root@host ~]# cat /lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=mixed PrivateTmp=true [Install] WantedBy=multi-user.target
nginx.confにproxy_pass追記
[root@host ~]# cat /etc/nginx/nginx.conf # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { # 省略 server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://localhost:4001; #ここだけ追記 } # 省略 } }
phoenixアプリの config/prod.exs の該当部分のみ
config :hello, Hello.Endpoint, http: [port: {:system, "PORT"}], url: [host: "localhost", port: 4001], cache_static_manifest: "priv/static/manifest.json"
nginxをsystemdで起動
[root@host ~]# systemctl start nginx
これでhttp://takeshionodera.net/phoenix/にアクセスするとport 4001にプロキシされてブラウザで表示されるようになった。
Firewalldのポート開放 & phoenix app 起動 @Fedora22(Conoha VPS)
phoenixのサンプル画面がブラウザから確認できなかった。
サーバー上でwgetすると取れるし、ローカルPCからpingも通る。
tcpdump port 4000 みてると、たしかにブラウザからのアクセスは届いてはいた。
ファイアーウォールまわりだろうとはすぐ絞れたけど
iptables使ってない、firewalldになったとかでハマった。
systemctl restart firewalld とするべきを firewall-cmd --reloadしていた。
/usr/lib/firewalld/services/http.xmlをコピーして
/etc/firewalld/services/http.xmlを書き換えるとか試したけど、コマンドでやるのが確実。
以下でポート開放された。
現状の確認
[root@host ~]# firewall-cmd --list-all FedoraServer (default, active) interfaces: eth0 sources: services: cockpit dhcpv6-client ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules:
サービスを追加
[root@host ~]# firewall-cmd --permanent --add-service=http success [root@host ~]# firewall-cmd --permanent --add-service=https success
ポートを開ける
[root@host ~]# firewall-cmd --permanent --add-port=80/tcp success [root@host ~]# firewall-cmd --permanent --add-port=4000/tcp success
firewalldを再起動
[root@host ~]# systemctl restart firewalld [root@host ~]# firewall-cmd --list-all FedoraServer (default, active) interfaces: eth0 sources: services: cockpit dhcpv6-client http https ssh ports: 4000/tcp 80/tcp masquerade: no forward-ports: icmp-blocks: rich rules:
phoenixのサンプルアプリを作成
[user@host app] mix phoenix.new app
アプリを port 4000 で起動
[user@host app]# mix phoenix.server
ビルドは以下に作られる
[user@host app]# tree -L 1 _build/ _build/ ├── dev └── prod
アプリのホスト名・ポートなどの設定変更は以下のファイルを書き換える。モード別に配置されている
tree -L 1 config/ config/ ├── config.exs ├── dev.exs ├── prod.exs ├── prod.secret.exs └── test.exs
production mode ( port 80 )で起動
[user@host app]# MIX_ENV=prod mix compile.protocols [user@host app]# sudo MIX_ENV=prod PORT=80 /usr/local/src/elixir-1.1.1/bin/elixir -pa _build/prod/consolidated -S /usr/local/src/elixir-1.1.1/bin/mix phoenix.server
Elixir Erlang@Fedora22(GMO Conoha VPS)
使ったことないのと東京リージョンに初期費用かからないのでGMO Conohaにした。
管理画面使いやすい。さくらVPSはどんなのだか忘れたけど。
Systemd使いたいのと触ったことないのでOSをFedora22にした。
Elixir と Erlang は yum install で入れた。
Elixir 1.0.3が入るけど1.1が最新なので後でsorceからビルドする。
[root@host ~]# yum install erlang #省略 Complete! [root@host ~]# erl Erlang/OTP 17 [erts-6.3] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false] Eshell V6.3 (abort with ^G) BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution [root@host ~]# yum install elixir # 省略 Installed: elixir.noarch 1.0.3-1.fc22 Complete! [root@host ~] # elixir -v Elixir 1.0.3
追記: Elixirをソースコードからビルド
Elixir 1.0.3を削除
[root@host ~]# yum remove elixir #省略 Removed: elixir.noarch 1.0.3-1.fc22 Complete!
バージョン1.1.1のコードをダウンロード、解答、ビルド
[root@host src]# pwd /usr/local/src [root@host src]# wget https://github.com/elixir-lang/elixir/archive/v1.1.1.tar.gz [root@host src]# tar xvzf v1.1.1.tar.gz #ぶわー [root@host src]# cd elixir-1.1.1/ [root@host elixir-1.1.1]# make clean test #ぶわー
完了、スムーズすぎる
[root@host elixir-1.1.1]# ./bin/elixir -v Elixir 1.1.1
go-example-webserver@Snappy Unbuntu Core On RaspberryPi2
前回の続き
webserverでパッケージ検索
(RaspberryPi2)ubuntu@localhost:~$ snappy search webserver Name Version Summary go-example-webserver 1.0.9 go-example-webserver xkcd-webserver 0.6 xkcd-webserver system-status.victor 1.0.10 System status web portal
go-example-webserverインストール
(RaspberryPi2)ubuntu@localhost:~$ sudo snappy install go-example-webserver Installing go-example-webserver Starting download of go-example-webserver 3.06 MB / 3.06 MB [========================================================================================] 100.00 % 89.10 KB/s Done Starting download of icon for package 40.35 KB / 40.35 KB [======================================================================================] 100.00 % 74.90 KB/s Done Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu go-example-webserver 2015-11-08 1.0.9 canonical hello-world 2015-11-08 1.0.18 canonical webdm 2015-11-08 0.9.4 sideload pi2 2015-09-25 0.16 canonical
http://サーバーIP:8081 にアクセスすればみれる。
READMEにビルド方法書いてあるけど、goインストールしないとダメ。
他所でビルドして、このサーバーに持ってきて動くかす方が楽そう。
RaspberryPiの中に入ってゴリゴリ書くのは違うと思う。
パッケージ削除の練習
(RaspberryPi2)ubuntu@localhost:~$ sudo snappy remove go-example-webserver Removing go-example-webserver Waiting for go-example-webserver_webserver_1.0.9.service to stop.
Snappy Ubuntu Core@Raspberry Pi 2
MacでSnappy Ubuntu を microSDカードに書いてRaspberry Pi 2にインストールした。
snappy コマンドを使ってみた。
用意したもの
- RaspberryPi2 Model B
- スマホ用ACアダプタ 5V2A
- microUSBケーブル
- SDカード16GB ※8GBあれば十分、速い方がいいかも。ddコマンドですごく時間がかかる
- MacBook (LANポートあり) ※無くても問題なし
- MacBook Air ※基本使ってるのはこっち
OSインストール
インストール方法は以下の通り。
Raspberry Pi 2 | Ubuntu developer portal
$ diskutil list /dev/disk0 # ~ 省略 ~ /dev/disk1 # ~ 省略 ~ /dev/disk2 #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *15.9 GB disk2 1: Windows_FAT_32 NO NAME 15.9 GB disk2s1
ドキュメントだとDOS_FAT_32になってるけどWindows_FAT_32で問題ない。
$ dela diskutil unmountDisk /dev/disk2 Unmount of all volumes on disk2 was successful
microSDカードに書き込み開始
$ sudo dd if='/Users/dela/Downloads/ubuntu-15.04-snappy-armhf-rpi2.img' of='/dev/rdisk2' load: 3.26 cmd: dd 1305 uninterruptible 0.18u 5.78s 56808+0 records in 56807+0 records out 29085184 bytes transferred in 161.721234 secs (179848 bytes/sec)
3.9GBあるのでかなり時間がかかる。
誤ってddを途中で止めてしまった場合はそのままddするとエラー
> sudo dd if='/Users/dela/Downloads/ubuntu-15.04-snappy-armhf-rpi2.img' of='/dev/rdisk2' dd: /dev/rdisk2: Resource busy
もう一度unmountDiskするとやり直せる
$ diskutil unmountDisk /dev/disk2 Unmount of all volumes on disk2 was successful $ sudo dd if='/Users/dela/Downloads/ubuntu-15.04-snappy-armhf-rpi2.img' of='/dev/rdisk2' load: 3.26 cmd: dd 1305 uninterruptible 0.18u 5.78s
進捗の確認は場合、 MacはCtrl + t で見れる
load: 1.45 cmd: dd 1305 uninterruptible 9.68u 313.88s 2763732+0 records in 2763731+0 records out 1415030272 bytes transferred in 37413.624032 secs (37821 bytes/sec)
すごく待ったわりに、しれっと終わる
7617187+0 records in 7617187+0 records out 3899999744 bytes transferred in 55525.879951 secs (70238 bytes/sec)
microSDカードをRaspberryPiに差し込む。
HDMIケーブルでディスプレイに写す。
ACアダプタ差し込んで起動する。
懐かしい嬉しさ。
ssh
自分のCoregaルーターの設定のせいですんなりsshできなかった。
ルーターの管理画面で無線アクセスポイント設定 / アクセス制限で無線端末間通信と無線‐有線間端末通信をどちらも有効にしたらsshできた。
原因の切り分けにLANポートありのMacBookが役立った。
ルーターを介さずに、インターネット共有を有効にして、
共有する接続経路: Wifi, 相手のコンピューターが使用するポート: Ethrnet にすればRaspberryPiにsshできたので、すぐルーターが怪しいと絞り込めた。
そもそも以下で他のマシーン出てこないのがおかしい
$ arp -a
ubuntuユーザーでログインできる。passwordは直感的にubuntuって打ったら入れた。ですよねー
ssh ubuntu@192.168.1.27 ubuntu@192.168.1.27's password: Welcome to Ubuntu 15.04 (GNU/Linux 4.2.0-1008-raspi2 armv7l) * Documentation: https://help.ubuntu.com/ Welcome to snappy Ubuntu Core, a transactionally updated Ubuntu. * See https://ubuntu.com/snappy It's a brave new world here in snappy Ubuntu Core! This machine does not use apt-get or deb packages. Please see 'snappy --help' for app installation and transactional updates. Last login: Sun Nov 8 13:21:12 2015 from 192.168.2.1
snappy コマンド
snappy --helpで何ができるか把握
OS情報の確認
(RaspberryPi2)ubuntu@localhost:~$ snappy info release: ubuntu-core/15.04/stable architecture: armhf frameworks: webdm apps: hello-world.canonical
間違えても教えてくれる。普通ですね、はい
(RaspberryPi2)ubuntu@localhost:~$ snappy version Unknown command `version', did you mean `versions'?
snappy versionsはそのうち使わなくなるみたい
(RaspberryPi2)ubuntu@localhost:~$ snappy versions The "versions" command is no longer available. Please use the "list" command instead to see what is installed. The "list -u" (or "list --updates") will show you the available updates and "list -v" (or "list --verbose") will show all installed versions.
インストールされてパッケージの確認
(RaspberryPi2)ubuntu@localhost:~$ snappy list Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu webdm 2015-11-08 0.9.4 sideload pi2 2015-09-25 0.16 canonical
パッケージ検索
(RaspberryPi2)ubuntu@localhost:~$ snappy search hello-world Name Version Summary glowapi.vtuson 0.1.2 PiGlow RestAPi hello-dbus-fwk 1.0.2 hello-dbus-fwk hello-world 1.0.18 hello-world (forks not shown: 2) spi-test.pedronis 0.3 spi-test saythis 1.3 saythis say 1.4 say Use --show-all to see all available forks.
パッケージインストール
(RaspberryPi2)ubuntu@localhost:~$ sudo snappy install hello-world Installing hello-world Starting download of hello-world 21.60 KB / 21.60 KB [====================================================================================>_] 100.00 % 82.01 KB/s Done Starting download of icon for package 33.77 KB / 33.77 KB [======================================================================================] 100.00 % 68.73 KB/s Done Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu hello-world 2015-11-08 1.0.18 canonical webdm 2015-11-08 0.9.4 sideload pi2 2015-09-25 0.16 canonical
パッケージが増えたのを確認するのは以下
(RaspberryPi2)ubuntu@localhost:~$ snappy list Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu hello-world 2015-11-08 1.0.18 canonical webdm 2015-11-08 0.9.4 sideload pi2 2015-09-25 0.16 canonical
お試し実行。もちろんevilでしょう
(RaspberryPi2)ubuntu@localhost:~$ hello-world.#tabキー hello-world.echo hello-world.env hello-world.evil hello-world.sh hello-world.showdev hello-world.usehw (RaspberryPi2)ubuntu@localhost:~$ hello-world.evil Hello Evil World!
そして週末が終わってた。