2016/12/11

AWSで安価にWordPressで18禁ブログを作成する

海外行きまくってる友人がそのときの風俗放浪記をブログに残すということになりまして、システムを構築してあげることにしました。アフィリエイトで儲かったら焼き肉おごれよと言いつつ。

ブログを書くだけならAmebaなどが有名ですが、エロ系で稼ぐとなってくるとちょっと事情が変わってきます。まず、ほとんどのブログサービスでは規約でエロ系を禁止しています。更にアフィリエイトを貼ろうとするともっと選択範囲が狭くなり、更に更に、将来の拡張性や保守性を担保しようとするとASPでは物足りなくなってきます。ということで格安でAWS(Amazon Web Services)を利用することにしました。それも、t2.nanoやt2.microインスタンスに限定。メモリが500Mとかしかありませんが、とりあえず動いています。年額一括払いにすると、1時間0.006$とリーズナブルです。

とりあえず下記は、インスタンスの購入までは独力でやれて、root権限が必要かどうかは判断がつく方を読者対象にしています。


ちなみに簡潔に先にポイントだけ書いておくと、SWAP領域を作るのとPingBackのセキュリティ設定をするのがコツです。


時間帯の変更

Amazon LinuxインスタンスではUTCに設定されているため、日本時間に設定し直します。まず現状の確認です。UTCになってしまっていることを確認します。
# date
Mon Sep 26 15:44:15 UTC 2016
# strings /etc/localtime
TZif2
TZif2
UTC0
インスタンスで使用する時間帯を特定します。
# ls /usr/share/zoneinfo
Africa Chile GB Indian MST PRC UTC
America CST6CDT GB-Eire Iran MST7MDT PST8PDT WET
Antarctica Cuba GMT iso3166.tab Navajo right W-SU
Arctic EET GMT0 Israel NZ ROC zone.tab
Asia Egypt GMT-0 Jamaica NZ-CHAT ROK Zulu
Atlantic Eire GMT+0 Japan Pacific Singapore
Australia EST Greenwich Kwajalein Poland Turkey
Brazil EST5EDT Hongkong Libya Portugal UCT
Canada Etc HST MET posix Universal
CET Europe Iceland Mexico posixrules US
# ls /usr/share/zoneinfo/Asia/
Aden Calcutta Hong_Kong Kuala_Lumpur Pyongyang Tel_Aviv
Almaty Chita Hovd Kuching Qatar Thimbu
Amman Choibalsan Irkutsk Kuwait Qyzylorda Thimphu
Anadyr Chongqing Istanbul Macao Rangoon Tokyo
Aqtau Chungking Jakarta Macau Riyadh Tomsk
Aqtobe Colombo Jayapura Magadan Saigon Ujung_Pandang
Ashgabat Dacca Jerusalem Makassar Sakhalin Ulaanbaatar
Ashkhabad Damascus Kabul Manila Samarkand Ulan_Bator
Baghdad Dhaka Kamchatka Muscat Seoul Urumqi
Bahrain Dili Karachi Nicosia Shanghai Ust-Nera
Baku Dubai Kashgar Novokuznetsk Singapore Vientiane
Bangkok Dushanbe Kathmandu Novosibirsk Srednekolymsk Vladivostok
Barnaul Gaza Katmandu Omsk Taipei Yakutsk
Beirut Harbin Khandyga Oral Tashkent Yekaterinburg
Bishkek Hebron Kolkata Phnom_Penh Tbilisi Yerevan
Brunei Ho_Chi_Minh Krasnoyarsk Pontianak Tehran
タイムゾーンを変更します。
# cp -p /etc/localtime /etc/localtime_yyyymmdd
# ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
この時点でタイムゾーンが即座に変わります。ただ、再起動するとUTCに戻ります。
再起動時に戻らないための対応をします。
# cp -p /etc/sysconfig/clock /etc/sysconfig/clock_yyyymmdd
エディタで編集します。UTC=true エントリを別の値に変更しないでください。このエントリは、ハードウェアクロックに使用されるため、インスタンスで別のタイムゾーンを設定する場合は調整する必要はありません。
ZONE="Asia/Tokyo"
UTC=true
確認
# shutdown -r now
# strings /etc/localtime


SWAP領域を作成する

t2.microにはスワップ領域がありません。そのため、apacheと組み合わせて利用しているとメモリが足りずに次のようなエラーが表示されます。
/usr/libexec/mysql55/mysqld: error while loading shared libraries: cannot alloca
te symbol search list: Cannot allocate memory
mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
そこでサイズが2048Mのスワップ領域を作成。ブロックサイズを大きくしすぎると作成中に恐らく固まるので、1M程度にしておきます。これはt2.microのメモリは1Gしかなく、WordPressをなんとか動かすためにはやったほうが良いです。
また、セキュリティ上chmod 600しておきます。スワップの状況はfreeコマンドで確認できます。
# free
total used free shared buffers cached
Mem: 1019332 209980 809352 152 10836 101300
-/+ buffers/cache: 97844 921488
Swap: 0 0 0
# sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
20480+0 records in
20480+0 records out
21474836480 bytes (21 GB) copied, 333.891 s, 64.3 MB/s
# sudo chmod 600 /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=c361f96b-4670-4d93-9094-c570c0bd2c5c
# sudo swapon /swapfile
# free
/etc/fstabを編集してシステムの起動時にswapファイルが自動的にマウントされるようにします。
/swapfile swap swap defaults 0 0
ちなみに、Swapファイルを作りなおすために削除する場合は次のようにします。
# free
# sudo swapoff -v /swapfile


Apacheのインストール

# free
total used free shared buffers cached
Mem: 1019332 209980 809352 152 10836 101300
-/+ buffers/cache: 97844 921488
Swap: 0 0 0
# yum list httpd
Available Packages
httpd.x86_64 2.2.31-1.8.amzn1 amzn-updates
# yum install httpd
自動起動の設定。
# chkconfig httpd on
# chkconfig --list httpd
起動。
# service httpd on


MySQLのインストール

まず、バージョンを確認します。WordPress対応のため、バージョン5.0(できれば5.6)以上が必要であることに注意してください。
# yum list mysql
mysql.noarch 5.5-1.6.amzn1 amzn-main
# yum install mysql mysql-server mysql-devel
起動。
# service mysqld start
自動起動。
# chkconfig mysqld on
# chkconfig --list mysqld
rootのパスワードを設定し、また、セキュリティを高めます。
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!
ログイン確認します。
# mysql -u root -p
死活確認します。
# mysqladmin -h 127.0.0.1 -P 3306 -u root -p ping
mysqld is alive
#echo $?
0
セキュリティチェックします。
# mysqladmin -h www.xxxxx.net -u root ping
mysqladmin: connect to server at 'www.xxxxx.net' failed
error: 'Can't connect to MySQL server on 'www.xxxxx.net' (110)'
Check that mysqld is running on www.xxxxx.net and that the port is 3306.
You can check this by doing 'telnet www.xxxxx.net 3306'
文字コード等、MySQLの設定をする場合はmy.cnfをいじってください。


PHP

# yum list php
php.x86_64 5.3.29-1.8.amzn1 amzn-main
#echo yum install php php-mysql php-mbstring


後はWordPressをインストールして、xmlrpc.phpのPingBack対策をすれば終了です。

2016/08/14

メッセンジャーを無料で暗号化

しなです。

クラウドの暗号化はすでにやっていたのですが,メッセンジャーの暗号化もやってみたくなったので色々調べてみた。


----
結論は OTR(Off-the-Record-Messaging) over XMPPでやり取りすることに。


・Windowsクライアント Pidgin OTR for Pidgin
#skypeプラグインもあり skype4pidgin

・Androidクライアント Chatsecure  Zom+ Orbot 
# Chatsecure(Android) はZomへ
#セキュリティおちるけど,Xabber も無料で使用可能

・iOSクライアント  Chatsecure 


その他のクライアント
ConversationsAndroid) は有料。
IronChat(Android)はGooglePlayの検索で引っかからず。
Jitsi(Android)はGooglePlayの検索で引っかからず。
kadu(Android)はGooglePlayの検索で引っかからず。
LeechCraft(Android)はGooglePlayの検索で引っかからず。
Psi(Android)はGooglePlayの検索で引っかからず。






ログインは公開XMPPサーバーでアカウントを取得するかgmailでもOK。

公開XMPPサーバ一覧 。日本だと http://www.xmpp.jp/  http://step.im/

XMPPサーバ調べていてわかったのだが,自前でXMPPサーバがたてられる模様。

ソフトは以下の2つだが試してません。人柱щ(゚д゚щ)カモーン

Openfire 
http://www.igniterealtime.org/projects/openfire/
http://www.moongift.jp/2009/01/openfire/

ejabberd
https://www.process-one.net/en/ejabberd/
http://ytyng.com/w/?XMPP%A5%DC%A5%C3%A5%C8-ejabberd%A5%B5%A1%BC%A5%D0%A4%CE%A5%A4%A5%F3%A5%B9%A5%C8%A1%BC%A5%EB
http://d.hatena.ne.jp/hiro_nemu/20140211/1392130527





以下 参考情報
http://gigazine.net/news/20141105-secure-messaging-scorecard/
http://www.baldanders.info/spiegel/log2/000782.shtml
http://blog.kaspersky.co.jp/cryptomessaging/3340/
http://blog.kaspersky.co.jp/nine-secure-messengers/5482/