2019年10月4日金曜日

beegoのローカル開発環境でsslを使う方法

自己証明書を作成

  • プライベートキーを作成
$ openssl genrsa -out private_key 2048
Generating RSA private key, 2048 bit long modulus
...........................................+++
...........................+++
e is 65537 (0x10001)
  • パブリックキーを作成
$ openssl req -new -x509 -key private_key -out public_key -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) []:jp
State or Province Name (full name) []:tokyo
Locality Name (eg, city) []:tokyo
Organization Name (eg, company) []:dmm.com
Organizational Unit Name (eg, section) []:dmm.com
Common Name (eg, fully qualified host name) []:test.dmm.com
Email Address []:test@dmm.com

sslを有効にするため、設定ファイル(app.con)に情報を追加

設定ファイル(./conf/app.conf)に、以下の情報を追加します。
EnableHTTPS = true
HTTPSPort = 443
HTTPSCertFile = "./local_cert/public_key" # 前のステップで作ったパブリックキーのファイルのフルパスを入れる。 自分の場合は「プロジェクトのパス/local_cert/」の直下に置いたのでそのような設定
HTTPSKeyFile = "./local_cert/private_key" # 前のステップで作ったプライベートキーのファイルのフルパスを入れる

beeコマンドで再起動

bee runコマンドで再起動します。以下のような情報が表示されるはずです。
$ bee run
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v1.10.0
2019/10/03 15:41:27 INFO     ▶ 0001 Using 'example-web' as 'appname'
2019/10/03 15:41:27 INFO     ▶ 0002 Initializing watcher...
2019/10/03 15:41:34 SUCCESS ▶ 0003 Built Successfully!
2019/10/03 15:41:34 INFO     ▶ 0004 Restarting 'magazine-front'...
2019/10/03 15:41:34 SUCCESS ▶ 0005 './magazine-front' is running...
2019/10/03 15:41:34.828 [I] [asm_amd64.s:1337]  http server Running on http://:8080
2019/10/03 15:41:34.829 [I] [asm_amd64.s:1337]  https server Running on https://:443
2019/10/03 15:42:06.284 [server.go:3010]  [HTTP] http: TLS handshake error from 127.0.0.1:56856: remote error: tls: unknown certificate
2019/10/03 15:42:09.062 [server.go:3010]  [HTTP] http: TLS handshake error from 127.0.0.1:56881: remote error: tls: unknown certificate

ブラウザーでsslページの動作を確認

最後ブラウザーに「https://127.0.0.1」を入れて、動作を確認します。「この接続ではプライバシーが保護されません...」が表示されたら、「詳細設定」/「127.0.0.1 にアクセスする(安全ではありません)」の順に進めます。

2019年10月2日水曜日

awsコマンドで入力した文字列をs3のオブジェクトと保存

表題の通りに、awsコマンドを使って文字列をs3のオブジェクトとして保存したいです。
例えバケット名はexample、保存するオブジェクトの名前hoge.txtの場合:
echo "保存したい文字列" | aws s3 cp - s3://example/hoge.txt

2019年9月26日木曜日

centos6.7にpython3.6のインストール方法

centos6にディフォルトpython2.6がインストールされている状態ですが、python3系を使いたいので、早速インストールしてみます。

まず、iusリポジトリーが有効にします。

# yum install -y https://centos6.iuscommunity.org/ius-release.rpm
Loaded plugins: fastestmirror, security
Setting up Install Process
Cannot open: https://centos6.iuscommunity.org/ius-release.rpm. Skipping.
Error: Nothing to do

理由はよくわからないですが、リポジトリーを足せなかったです。
むりやり、rpmファイルを落としてきます。
# wget https://centos6.iuscommunity.org/ius-release.rpm
rpmでインストールします。
# rpm -ivh ius-release.rpm
インストールできたことを確認します。
# yum repolist all | grep 'ius'
ius                    IUS for Enterprise Linux 6 - x86_64        enabled:   244
ius-archive            IUS for Enterprise Linux 6 - Archive - x86 disabled
ius-archive-debuginfo  IUS for Enterprise Linux 6 - Archive - x86 disabled
ius-archive-source     IUS for Enterprise Linux 6 - Archive - Sou disabled
ius-debuginfo          IUS for Enterprise Linux 6 - x86_64 - Debu disabled
ius-source             IUS for Enterprise Linux 6 - Source        disabled
ius-testing            IUS for Enterprise Linux 6 - Testing - x86 disabled
ius-testing-debuginfo  IUS for Enterprise Linux 6 - Testing - x86 disabled

ius-testing-source     IUS for Enterprise Linux 6 - Testing - Sou disabled

Python3.6をインストールします。

インストール可能なパッケージがあるかを確認
# yum --enablerepo=ius search python36
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * extras: ftp-srv2.kddilabs.jp
 * updates: ftp-srv2.kddilabs.jp
============================================================================== N/S Matched: python36 ===============================================================================
python36u-test.x86_64 : The self-test suite for the main python36u package
python36.x86_64 : Interpreter of the Python programming language
python36-debug.x86_64 : Debug version of the Python runtime
python36-devel.x86_64 : Libraries and header files needed for Python development
python36-gunicorn.noarch : Python WSGI application server
python36-idle.x86_64 : A basic graphical development environment for Python
python36-libs.x86_64 : Python runtime libraries
python36-lxml.x86_64 : XML processing library combining libxml2/libxslt with the ElementTree API
python36-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python36-pip.noarch : A tool for installing and managing Python packages
python36-redis.noarch : Python interface to the Redis key-value store
python36-setproctitle.x86_64 : Python module to customize a process title
python36-setuptools.noarch : Easily build and distribute Python packages
python36-test.x86_64 : The self-test suite for the main python3 package
python36-tkinter.x86_64 : A GUI toolkit for Python
python36u.x86_64 : Interpreter of the Python programming language
python36u-debug.x86_64 : Debug version of the Python runtime
python36u-devel.x86_64 : Libraries and header files needed for Python development
python36u-gunicorn.noarch : Python WSGI application server
python36u-libs.x86_64 : Python runtime libraries
python36u-lxml.x86_64 : XML processing library combining libxml2/libxslt with the ElementTree API
python36u-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python36u-pip.noarch : A tool for installing and managing Python packages
python36u-redis.noarch : Python interface to the Redis key-value store
python36u-setproctitle.x86_64 : Python module to customize a process title
python36u-setuptools.noarch : Easily build and distribute Python packages
python36u-tkinter.x86_64 : A GUI toolkit for Python
python36u-tools.x86_64 : A collection of tools included with Python including 2to3 and idle
uwsgi-plugin-python36u.x86_64 : uWSGI - Plugin for Python support
いよいよインストールします。
# yum --enablerepo=ius install python36
インストールできたことを確認
# python36 --version
Python 3.6.8