tag:blogger.com,1999:blog-31069039007504747512024-03-13T20:21:51.007+09:00yoshi blogIT infra engineer working at Tokyo, Japan. coding on weekends just for fun.yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-3106903900750474751.post-71548947347061191432019-12-01T17:14:00.001+09:002019-12-01T17:14:49.217+09:00How to restart apache with Bitnami EC2?<br />
<br />
use "/opt/bitnami/ctlscript.sh"<br />
<br />
<pre class="prettyprint"><code class="language-python">
sudo /opt/bitnami/ctlscript.sh restart apache
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-32844205369293576402018-04-14T19:22:00.001+09:002018-04-14T19:23:17.301+09:00Let's Encrypt certification renewal on EC2<br />
<p>Let's Encrypt certificate is replaced by the command below<br />
"--dry-run": testing process. no execution <br />
"--force-renew": force renew certificate. Without this option, certificate which needs more time to expired is not replaced.<br />
<br />
<pre class="prettyprint"><code class="language-bash"># ./certbot-auto renew --force-renew --dry-run
</code></pre></p><br />
<p>Encountered error below.<br />
<pre class="prettyprint"><code class="language-bash"># ./certbot-auto renew --force-renew --dry-run
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
Traceback (most recent call last):
File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 10, in <module>
import josepy as jose
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/__init__.py", line 41, in <module>
from josepy.interfaces import JSONDeSerializable
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/interfaces.py", line 8, in <module>
from josepy import errors, util
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/util.py", line 4, in <module>
import OpenSSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/rand.py", line 12, in <module>
from OpenSSL._util import (
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/_util.py", line 6, in <module>
from cryptography.hazmat.bindings.openssl.binding import Binding
ImportError: No module named cryptography.hazmat.bindings.openssl.binding
</code></pre></p><br />
<p>Error message wouldn't change even the modules are installed.<br />
<pre class="prettyprint"><code class="language-bash"># pip install cryptography hazmat bindings openssl binding
Collecting cryptography
</code></pre><br />
<pre class="prettyprint"><code class="language-bash"># ./certbot-auto renew --force-renew --dry-run
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
Traceback (most recent call last):
File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 10, in <module>
import josepy as jose
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/__init__.py", line 41, in <module>
from josepy.interfaces import JSONDeSerializable
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/interfaces.py", line 8, in <module>
from josepy import errors, util
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/util.py", line 4, in <module>
import OpenSSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/rand.py", line 12, in <module>
from OpenSSL._util import (
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/_util.py", line 6, in <module>
from cryptography.hazmat.bindings.openssl.binding import Binding
ImportError: No module named cryptography.hazmat.bindings.openssl.binding
</code></pre></p><br />
<p>Error message is changed after executing the command below. It means pip path used by Let's Encrypt is different.<br />
<pre class="prettyprint"><code class="language-bash"># /opt/eff.org/certbot/venv/bin/pip install -U certbot
</code></pre><br />
<br />
<pre class="prettyprint"><code class="language-bash"># sudo ./certbot-auto renew --force-renew --dry-run --debug
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
Traceback (most recent call last):
File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 10, in <module>
import josepy as jose
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/__init__.py", line 44, in <module>
from josepy.interfaces import JSONDeSerializable
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/interfaces.py", line 8, in <module>
from josepy import errors, util
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/util.py", line 4, in <module>
import OpenSSL
ImportError: No module named OpenSSL
</code></pre><br />
</p><br />
<p>Install "openssl" with the pip path.<br />
<br />
<pre class="prettyprint"><code class="language-bash"># /opt/eff.org/certbot/venv/bin/pip install pyOpenSSL
</code></pre><br />
<pre class="prettyprint"><code class="language-bash"># sudo ./certbot-auto renew --force-renew --dry-run --debug
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
Traceback (most recent call last):
File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 10, in <module>
import josepy as jose
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/__init__.py", line 44, in <module>
from josepy.interfaces import JSONDeSerializable
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/interfaces.py", line 8, in <module>
from josepy import errors, util
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/util.py", line 4, in <module>
import OpenSSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in <module>
from cryptography import x509
ImportError: No module named cryptography
</code></pre></p><br />
<p><br />
Also install "cryptigraphy".<br />
"no module named cryptography" error even cryptography module is installed successfully.<br />
<pre class="prettyprint"><code class="language-bash"># /opt/eff.org/certbot/venv/bin/pip install cryptography
</code></pre><br />
<pre class="prettyprint"><code class="language-bash"># sudo ./certbot-auto renew --force-renew --dry-run --debug
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
Traceback (most recent call last):
File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 10, in <module>
import josepy as jose
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/__init__.py", line 44, in <module>
from josepy.interfaces import JSONDeSerializable
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/interfaces.py", line 8, in <module>
from josepy import errors, util
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/josepy/util.py", line 4, in <module>
import OpenSSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in <module>
from cryptography import x509
ImportError: No module named cryptography
</code></pre><br />
</p><br />
<br />
<p>only put "sudo" to avoid the error.<br />
<br />
<pre class="prettyprint"><code class="language-bash"># sudo /opt/eff.org/certbot/venv/bin/pip install cryptography
</code></pre><br />
<pre class="prettyprint"><code class="language-bash"># sudo ./certbot-auto renew --force-renew --dry-run --debug
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
Traceback (most recent call last):
File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/certbot/main.py", line 11, in <module>
import zope.component
File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/zope/component/__init__.py", line 16, in <module>
from zope.interface import Interface
ImportError: No module named interface
</code></pre></p><br />
<p>Install "interface" as same way.<br />
<br />
<pre class="prettyprint"><code class="language-bash"># sudo /opt/eff.org/certbot/venv/bin/pip install interface
</code></pre></p><br />
<p>Successfully replaced certificate, finally!<br />
<br />
<pre class="prettyprint"><code class="language-bash"># sudo ./certbot-auto renew --force-renew --dry-run --debug
Saving debug log to /var/log/letsencrypt/letsencrypt.log
-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/www.yoshiislandserver.net.conf
-------------------------------------------------------------------------------
Plugins selected: Authenticator standalone, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.yoshiislandserver.net
Waiting for verification...
Cleaning up challenges
-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/www.yoshiislandserver.net/fullchain.pem
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/www.yoshiislandserver.net/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
-------------------------------------------------------------------------------
IMPORTANT NOTES:
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
</code></pre></p>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-25744397100603785422018-01-03T19:22:00.000+09:002018-01-03T19:25:45.837+09:00csv update app with spyre pythonnow I created csv update app with <a href="https://github.com/adamhajari/spyre" target="_blank">spyre</a>. full code is <a href="https://github.com/yoshi-island/spyre_work" target="_blank">here</a>.<br />
<br />
<h1>Preparation</h1>set python vision and install dataspyre.<br />
<pre class="prettyprint"><code class="language-python">% python -V
Python 3.5.0
% pip install dataspyre
</code></pre><br />
set directory tree as below. "test_data.csv" is the csv file to edit. number of columns have to be 5.<br />
<br />
<pre class="prettyprint"><code class="language-python">% tree
.
├── csv_update.py
├── data
│ ├── test_data.csv
</code></pre><br />
<pre class="prettyprint"><code class="language-python">% cat data/test_data.csv
data1,data2,data3,data4,data5
haha,hihi,huhu,hehe,hoho
gaga,gigi,gugu,gege,gogo
rara,riri,ruru,rere,roro
</code></pre><br />
<h1>Execution</h1><br />
<pre class="prettyprint"><code class="language-python">% python csv_update.py
</code></pre><br />
Then, access to "http://127.0.0.1:9093"<br />
input file name and push "get data" button.<br />
<br />
<a href="http://2.bp.blogspot.com/-ElOfbWMwtGI/WkyueiwxokI/AAAAAAAAAEw/0SKJCNfV7d4Gc0VqlD0ScuFfYfE47h7_gCK4BGAYYCw/s1600/2018-01-03%2B17.38.33.png" imageanchor="1"><img border="0" height="310" src="https://2.bp.blogspot.com/-ElOfbWMwtGI/WkyueiwxokI/AAAAAAAAAEw/0SKJCNfV7d4Gc0VqlD0ScuFfYfE47h7_gCK4BGAYYCw/s320/2018-01-03%2B17.38.33.png" width="320" /></a><br />
<br />
input data and push "add data" button.<br />
<br />
<a href="http://3.bp.blogspot.com/-7xg-_3hsLEE/WkyujUlbYhI/AAAAAAAAAE4/W42IehxWJiQc9iWSBzYxGRdos40jQ0DLACK4BGAYYCw/s1600/2018-01-03%2B17.43.19.png" imageanchor="1"><img border="0" height="302" src="https://3.bp.blogspot.com/-7xg-_3hsLEE/WkyujUlbYhI/AAAAAAAAAE4/W42IehxWJiQc9iWSBzYxGRdos40jQ0DLACK4BGAYYCw/s320/2018-01-03%2B17.43.19.png" width="320" /></a><br />
<br />
<br />
push "get data" button again to check added data.<br />
backup data added under "data" directory in case.<br />
<br />
<a href="http://1.bp.blogspot.com/-M915mhFyeNk/WkyunU6V53I/AAAAAAAAAFA/iFQzqFmKkgsHrjp4UMiRXd9Aqk4AmsZ-QCK4BGAYYCw/s1600/2018-01-03%2B17.43.40.png" imageanchor="1"><img border="0" height="303" src="https://1.bp.blogspot.com/-M915mhFyeNk/WkyunU6V53I/AAAAAAAAAFA/iFQzqFmKkgsHrjp4UMiRXd9Aqk4AmsZ-QCK4BGAYYCw/s320/2018-01-03%2B17.43.40.png" width="320" /></a><br />
<br />
<br />
<pre class="prettyprint"><code class="language-python">% tree
.
├── csv_update.py
├── data
│ ├── test_data.csv
│ ├── test_data.csv_20180103173523
│ └── test_data.csv_20180103174330
</code></pre><br />
<pre class="prettyprint"><code class="language-python">% cat data/test_data.csv
data1,data2,data3,data4,data5
haha,hihi,huhu,hehe,hoho
gaga,gigi,gugu,gege,gogo
rara,riri,ruru,rere,roro
data1,data2,data3,data4,data5
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-24689967842220912882017-12-02T14:37:00.000+09:002017-12-02T14:37:01.324+09:00Where is the gateway IP address with NAT on VMware Fusion?<h1>(1) check NAT network assigned by ifcofig</h1><br />
<div><pre class="prettyprint"><code class="language-bash">% ifconfig
......
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether xxxxx
inet 192.168.167.1 netmask 0xffffff00 broadcast 192.168.167.255
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether xxxxx
inet 192.168.154.1 netmask 0xffffff00 broadcast 192.168.154.255
......
</code></pre><br />
vmnet1 is for host-only network. now, I use vmne8 (NAT) network to fix geteway IP of the VM.<br />
<br />
</div><br />
<br />
<br />
<h1>(2) check vmnet8 config file</h1><br />
find gateway address on /Library/Preferences/VMware Fusion/vmnet8<br />
<br />
<div><pre class="prettyprint"><code class="language-bash">/Library/Preferences/VMware Fusion/vmnet8
% cat nat.conf
# VMware NAT configuration file
# Manual editing of this file is not recommended. Using UI is preferred.
[host]
# NAT gateway address
ip = 192.168.154.2 # <== here!
netmask = 255.255.255.0
# VMnet device if not specified on command line
device = vmnet8
.......
</code></pre></div>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-67985640192120375402017-07-08T17:09:00.002+09:002017-08-30T23:11:43.824+09:00deploy proxy server with nginxthe proxy server is built on nginx. environment is shown below. two ubuntu virtual machines deployed by vagrant and each virtual machine has nginx.<br />
<a href="https://3.bp.blogspot.com/-qffrAeNJDCA/WWCHW7cpFvI/AAAAAAAAADw/0aXey2WiJwE65bCEjGvxlISc268OpTvgACLcBGAs/s1600/IMG_0118.PNG" imageanchor="1" ><img border="0" src="https://3.bp.blogspot.com/-qffrAeNJDCA/WWCHW7cpFvI/AAAAAAAAADw/0aXey2WiJwE65bCEjGvxlISc268OpTvgACLcBGAs/s320/IMG_0118.PNG" width="320" height="240" data-original-width="640" data-original-height="480" /></a><br />
<br />
one(192.168.33.10) is for webserver and the other(192.168.33.11) is for proxy.<br />
<a href="https://3.bp.blogspot.com/-_LaUamWH8vQ/WWCCxV4ev6I/AAAAAAAAADk/axrwlaSBmCApuaMGBQGN_z2lHagi7rRnACLcBGAs/s1600/IMG_0117.PNG" imageanchor="1" ><img border="0" src="https://3.bp.blogspot.com/-_LaUamWH8vQ/WWCCxV4ev6I/AAAAAAAAADk/axrwlaSBmCApuaMGBQGN_z2lHagi7rRnACLcBGAs/s320/IMG_0117.PNG" width="320" height="240" data-original-width="640" data-original-height="480" /></a><br />
<br />
<br />
<h1># install virtualbox</h1><a href="http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html?ssSourceSiteId=otnus" target="_blank">http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html?ssSourceSiteId=otnus</a><br />
<br />
<br />
<h1># install vagrant</h1><a href=https://www.vagrantup.com/downloads.html target="_blank">https://www.vagrantup.com/downloads.html</a><br />
<br />
check version which installed<br />
<pre class="prettyprint"><code class="language-bash">% vagrant --version
Vagrant 1.9.6
</code></pre><br />
<br />
<h1># deploy virtual machines</h1><h2>## 192.168.33.11(Proxy Server)</h2><pre class="prettyprint"><code class="language-bash">% cd
% mkdir vagrant_work
% cd vagrant_work
% vagrant init ubuntu/trusty64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
% vagrant up --provider virtualbox
</code></pre><br />
<br />
<h2>## 192.168.33.10(Web Server)</h2><pre class="prettyprint"><code class="language-bash">% cd
% mkdir vagrant_work2
% cd vagrant_work
% vagrant init ubuntu/trusty64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
% vagrant up --provider virtualbox
</code></pre><br />
<h2>## check point</h2>two virtual machines are running on virtualbox.<br />
<a href="https://2.bp.blogspot.com/-BqsEQ3MSL3E/WWCI5Psd9lI/AAAAAAAAAD4/ZYnMtUV0-S4XH5hebyJ5JSDN-LwMi5lBQCLcBGAs/s1600/virtualbox.png" imageanchor="1" ><img border="0" src="https://2.bp.blogspot.com/-BqsEQ3MSL3E/WWCI5Psd9lI/AAAAAAAAAD4/ZYnMtUV0-S4XH5hebyJ5JSDN-LwMi5lBQCLcBGAs/s320/virtualbox.png" width="320" height="248" data-original-width="809" data-original-height="627" /></a><br />
<br />
<br />
<h1># set IP address</h1><h2>## 192.168.33.11(Proxy Server)</h2>move to directory.<br />
<pre class="prettyprint"><code class="language-bash">% cd
% cd vagrant_work
</code></pre><br />
edit file.<br />
<pre class="prettyprint"><code class="language-bash">% vi Vagrantfile
% cat Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.33.11"
end
</code></pre><br />
restart virtual machine.<br />
<pre class="prettyprint"><code class="language-bash">% vagrant halt
==> default: Attempting graceful shutdown of VM...
% vagrant up
</code></pre><br />
check ping echo.<br />
<pre class="prettyprint"><code class="language-bash"> % ping -c 3 192.168.33.11
</code></pre><br />
<br />
<h2>## 192.168.33.10(Web Server)</h2>move to directory.<br />
<pre class="prettyprint"><code class="language-bash">% cd
% cd vagrant_work2
</code></pre><br />
edit file.<br />
<pre class="prettyprint"><code class="language-bash">% vi Vagrantfile
% cat Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.33.10"
end
</code></pre><br />
restart virtual machine.<br />
<pre class="prettyprint"><code class="language-bash">% vagrant halt
==> default: Attempting graceful shutdown of VM...
% vagrant up
</code></pre><br />
check ping echo.<br />
<pre class="prettyprint"><code class="language-bash"> % ping -c 3 192.168.33.10
</code></pre><br />
<br />
<h1># install nginx</h1><h2>## 192.168.33.11(Proxy Server)</h2>move to directory.<br />
<pre class="prettyprint"><code class="language-bash">% cd
% cd vagrant_work
% vagrant ssh
</code></pre><br />
install nginx on virtual machine.<br />
<pre class="prettyprint"><code class="language-bash"># apt-get install nginx
# cp /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.backup
</code></pre><br />
edit index.html like this.<br />
<pre class="prettyprint"><code class="language-bash"># vi /usr/share/nginx/html/index.html
# cat /usr/share/nginx/html/index.html
192.168.33.11
</code></pre><br />
<br />
<h2>## 192.168.33.10(Web Server)</h2>move to directory.<br />
<pre class="prettyprint"><code class="language-bash">% cd
% cd vagrant_work2
% vagrant ssh
</code></pre><br />
install nginx on virtual machine.<br />
<pre class="prettyprint"><code class="language-bash"># apt-get install nginx
# cp /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.backup
</code></pre><br />
edit index.html like this.<br />
<pre class="prettyprint"><code class="language-bash"># vi /usr/share/nginx/html/index.html
# cat /usr/share/nginx/html/index.html
192.168.33.10
</code></pre><br />
<br />
<h2>## check point</h2>then, check if http access available.<br />
<a href="http://192.168.33.11">http://192.168.33.11</a><br />
<a href="https://3.bp.blogspot.com/-uOrZVmd_cF8/WWCNPYqJZ7I/AAAAAAAAAEA/5T7aNgi5BYQxp6KDqVX-J6Y7rQROoMKcgCLcBGAs/s1600/11.png" imageanchor="1" ><img border="0" src="https://3.bp.blogspot.com/-uOrZVmd_cF8/WWCNPYqJZ7I/AAAAAAAAAEA/5T7aNgi5BYQxp6KDqVX-J6Y7rQROoMKcgCLcBGAs/s320/11.png" width="320" height="175" data-original-width="809" data-original-height="442" /></a><br />
<br />
<a href="http://192.168.33.10">http://192.168.33.10</a><br />
<a href="https://2.bp.blogspot.com/-bstIgHwMwn4/WWCNTIT8QwI/AAAAAAAAAEE/BJjTaqiV-HEuIqrbloK0h2b5lf5c9UP9gCLcBGAs/s1600/10.png" imageanchor="1" ><img border="0" src="https://2.bp.blogspot.com/-bstIgHwMwn4/WWCNTIT8QwI/AAAAAAAAAEE/BJjTaqiV-HEuIqrbloK0h2b5lf5c9UP9gCLcBGAs/s320/10.png" width="320" height="210" data-original-width="736" data-original-height="484" /></a><br />
<br />
<br />
<h1># proxy config (no ssl)</h1><h2>## 192.168.33.11(Proxy Server)</h2>move to directory.<br />
<pre class="prettyprint"><code class="language-bash">% cd
% cd vagrant_work
% vagrant ssh
</code></pre><br />
edit file like this.<br />
<pre class="prettyprint"><code class="language-bash"># vi /etc/nginx/conf.d/server.conf
# cat /etc/nginx/conf.d/server.conf
server {
listen 80;
server_name 192.168.33.11;
location / {
proxy_pass http://192.168.33.10/;
}
}
# service nginx restart
* Restarting nginx nginx [ OK ]
</code></pre><br />
<br />
<h2>## check point</h2>then check again. it shows 192.168.33.10 page. it means proxy server pass to webserver.<br />
<a href="http://192.168.33.11">http://192.168.33.11</a><br />
<a href="https://2.bp.blogspot.com/-4aEU-vNm_ug/WWCOo9X1JoI/AAAAAAAAAEQ/nqQM1tE1PyodxSBRyZ8t-UsOTON4M_0qACLcBGAs/s1600/11a.png" imageanchor="1" ><img border="0" src="https://2.bp.blogspot.com/-4aEU-vNm_ug/WWCOo9X1JoI/AAAAAAAAAEQ/nqQM1tE1PyodxSBRyZ8t-UsOTON4M_0qACLcBGAs/s320/11a.png" width="320" height="191" data-original-width="746" data-original-height="446" /></a><br />
<br />
<br />
<h1># proxy config (ssl)</h1><h2>## 192.168.33.11(Proxy Server)</h2>move to directory.<br />
<pre class="prettyprint"><code class="language-bash">% cd
% cd vagrant_work
% vagrant ssh
</code></pre><br />
ssl settings<br />
<pre class="prettyprint"><code class="language-bash"># mkdir /usr/local/tmp
# cd /usr/local/tmp/
# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
Enter pass phrase for server.key:[1234]
Verifying - Enter pass phrase for server.key:[1234]
# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:[1234]
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) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# cp server.key server.key.org
# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
writing RSA key
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd
Getting Private key
</code></pre><br />
<br />
<h2>## check point</h2><pre class="prettyprint"><code class="language-bash"># ls
server.crt server.csr server.key server.key.org
# pwd
/usr/local/tmp
</code></pre><br />
edit file.<br />
<pre class="prettyprint"><code class="language-bash"># vi /etc/nginx/conf.d/server.conf
# cat /etc/nginx/conf.d/server.conf
server {
listen 80;
server_name 192.168.33.11;
location / {
proxy_pass http://192.168.33.10/;
}
}
server {
listen 443;
server_name 192.168.33.11;
ssl on;
ssl_certificate /usr/local/tmp/server.crt;
ssl_certificate_key /usr/local/tmp/server.key;
ssl_protocols SSLv2 SSLv3 TLSv1;
location / {
proxy_pass http://192.168.33.10/;
}
}
</code></pre><br />
nginx service restart.<br />
<pre class="prettyprint"><code class="language-bash"># service nginx restart
* Restarting nginx nginx [ OK ]
</code></pre><br />
<br />
<h2>## check point</h2>then, access to https page.<br />
<a href="https://192.168.33.11">https://192.168.33.11</a><br />
<a href="https://1.bp.blogspot.com/-H6n2ETNqazY/WWCR6xAwACI/AAAAAAAAAEc/YIyzJ6ONgr0P8gJPmQcjrKEwzhfY10wzQCLcBGAs/s1600/ssl.png" imageanchor="1" ><img border="0" src="https://1.bp.blogspot.com/-H6n2ETNqazY/WWCR6xAwACI/AAAAAAAAAEc/YIyzJ6ONgr0P8gJPmQcjrKEwzhfY10wzQCLcBGAs/s320/ssl.png" width="320" height="165" data-original-width="809" data-original-height="417" /></a><br />
yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-32783944894497520842017-06-25T16:32:00.003+09:002017-06-25T16:33:43.091+09:00meeting timer
meeting timer
<br/>
<a href=https://github.com/yoshi-island/mtg_timer target="_blank">mtg_timer</a>
<br/>
<br/>
you can also see remain time on the tab.
<br/>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--multi device--!>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>TimeKeeper</title>
</head>
<body>
<!-- get current time --!>
<p>
current time is<label id="RealtimeClock"></label>
</p>
<!-- get end time --!>
<p>
end time is<input type="text"id="EndTime" value="18:00" size="10">
</p>
<!-- get remain time and set buttons --!>
<p>
<form name="timer">
remain time is</br>
<input type="text" value="10" size="10">min
<input type="text" value="0" size="10">sec<br>
<input type="button" value="start" onclick="cntStart()">
<input type="button" value="stop" onclick="cntStop()">
<input type="button" value="reset" onclick="reSet()">
</form>
<!-- get aleart message --!>
<font color="red"><label id="AlertMessage"></label></font>
</p>
<!-- get textbox --!>
<p>
<textarea name="freeans" rows="20" cols="30">Today's Agenda</textarea>
</p>
<!-- javascript --!>
<script type="text/javascript">
// display clock
function showClock() {
var nowTime = new Date();
var nowHour = setfig( nowTime.getHours() );
var nowMin = setfig( nowTime.getMinutes() );
var nowSec = setfig( nowTime.getSeconds() );
var msg = nowHour + ":" + nowMin + ":" + nowSec;
document.getElementById("RealtimeClock").innerHTML = msg;
}
setInterval('showClock()',1000);
// fix number of digits to two if its one
function setfig(num) {
var ret;
if( num < 10 ) { ret = "0" + num; }
else { ret = num; }
return ret;
}
// set timer id
var timer1;
// get countdown timer for 1000msec
function cntStart() {
document.timer.elements[2].disabled=true;
timer1=setInterval("countDown()",1000);
}
// stop timer
function cntStop() {
document.timer.elements[2].disabled=false;
clearInterval(timer1);
}
// countdowm timer
function countDown() {
var min=document.timer.elements[0].value;
var sec=document.timer.elements[1].value;
if( (min=="") && (sec=="") ) {
var msg="set time!";
document.getElementById("AlertMessage").innerHTML = msg;
reSet();
} else {
if (min=="") min=0;
min=parseInt(min);
if (sec=="") sec=0;
sec=parseInt(sec);
tmWrite(min*60+sec-1);
}
}
// get remain time
function tmWrite(int) {
int=parseInt(int);
if (int<=0)
{
reSet();
var msg="it's time!";
//alert(msg)
document.getElementById("AlertMessage").innerHTML = msg;
// aleart tab if remain time is zero
document.title = msg
} else {
// get remain min
rem_min=Math.floor(int/60);
// get remain sec
rem_sec=int % 60;
// get remain time
document.timer.elements[0].value=rem_min;
document.timer.elements[1].value=rem_sec;
// display remain time
document.title = 'remain time is ' + rem_min + ':' + rem_sec;
}
}
// reset form
function reSet() {
var msg="";
document.getElementById("AlertMessage").innerHTML = msg;
document.timer.elements[0].value="10";
document.timer.elements[1].value="0";
document.timer.elements[2].disabled=false;
clearInterval(timer1);
}
</script>
</body>
</html>
<br>
<pre class="prettyprint"><code class="language-html">
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--multi device--!>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>TimeKeeper</title>
</head>
<body>
<!-- get current time --!>
<p>
current time is<label id="RealtimeClock"></label>
</p>
<!-- get end time --!>
<p>
end time is<input type="text"id="EndTime" value="18:00" size="10">
</p>
<!-- get remain time and set buttons --!>
<p>
<form name="timer">
remain time is</br>
<input type="text" value="10" size="10">min
<input type="text" value="0" size="10">sec<br>
<input type="button" value="start" onclick="cntStart()">
<input type="button" value="stop" onclick="cntStop()">
<input type="button" value="reset" onclick="reSet()">
</form>
<!-- get aleart message --!>
<font color="red"><label id="AlertMessage"></label></font>
</p>
<!-- get textbox --!>
<p>
<textarea name="freeans" rows="20" cols="30">Today's Agenda</textarea>
</p>
<!-- javascript --!>
<script type="text/javascript">
// display clock
function showClock() {
var nowTime = new Date();
var nowHour = setfig( nowTime.getHours() );
var nowMin = setfig( nowTime.getMinutes() );
var nowSec = setfig( nowTime.getSeconds() );
var msg = nowHour + ":" + nowMin + ":" + nowSec;
document.getElementById("RealtimeClock").innerHTML = msg;
}
setInterval('showClock()',1000);
// fix number of digits to two if its one
function setfig(num) {
var ret;
if( num < 10 ) { ret = "0" + num; }
else { ret = num; }
return ret;
}
// set timer id
var timer1;
// get countdown timer for 1000msec
function cntStart() {
document.timer.elements[2].disabled=true;
timer1=setInterval("countDown()",1000);
}
// stop timer
function cntStop() {
document.timer.elements[2].disabled=false;
clearInterval(timer1);
}
// countdowm timer
function countDown() {
var min=document.timer.elements[0].value;
var sec=document.timer.elements[1].value;
if( (min=="") && (sec=="") ) {
var msg="set time!";
document.getElementById("AlertMessage").innerHTML = msg;
reSet();
} else {
if (min=="") min=0;
min=parseInt(min);
if (sec=="") sec=0;
sec=parseInt(sec);
tmWrite(min*60+sec-1);
}
}
// get remain time
function tmWrite(int) {
int=parseInt(int);
if (int<=0)
{
reSet();
var msg="it's time!";
//alert(msg)
document.getElementById("AlertMessage").innerHTML = msg;
// aleart tab if remain time is zero
document.title = msg
} else {
// get remain min
rem_min=Math.floor(int/60);
// get remain sec
rem_sec=int % 60;
// get remain time
document.timer.elements[0].value=rem_min;
document.timer.elements[1].value=rem_sec;
// display remain time
document.title = 'remain time is ' + rem_min + ':' + rem_sec;
}
}
// reset form
function reSet() {
var msg="";
document.getElementById("AlertMessage").innerHTML = msg;
document.timer.elements[0].value="10";
document.timer.elements[1].value="0";
document.timer.elements[2].disabled=false;
clearInterval(timer1);
}
</script>
</body>
</html>
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-70622280495667059822017-05-28T02:45:00.000+09:002017-05-28T02:45:34.210+09:00play with python turtledrawing by python is fun! You can start drawing with python script by importing "turtle module".
<br />
<h4>
1. sample code
</h4>
<pre class="prettyprint"><code class="language-python"># coding: utf-8
import turtle
t = turtle.Pen()
while True:
color_list = 'pink', 'green', 'purple'
import random
scale = random.randint(50, 100)
print("scale %s" % scale)
t.left(60)
for c in color_list:
i = 1
print("color %s" % c)
while i <= 360 / 60:
print("count %s" % i)
t.begin_fill()
t.forward(scale)
t.fillcolor(c)
t.left(30)
t.circle(scale/4, 180)
t.right(180)
t.circle(scale/4, 180)
t.left(30)
t.forward(scale)
t.left(180)
i = i + 1
t.end_fill()
scale = scale * 0.8
t.up()
location = random.randint(100, 300)
print("location %s" % location)
t.left(scale)
t.forward(location)
t.left(scale)
t.forward(location)
t.down()
turtle.done()</code></pre>
<h4>
2. execution
</h4>
<pre class="prettyprint"><code class="language-python">% python turtle_work.py
</code></pre>
<a href="http://2.bp.blogspot.com/-TFPnJyHP1qE/WSmXPes1qFI/AAAAAAAAABA/EXeq0PkLakMB9Rqdkn5kWvqN65XDUq4fwCK4B/s1600/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-28%2B00.11.23.png" imageanchor="1"><img border="0" height="272" src="https://2.bp.blogspot.com/-TFPnJyHP1qE/WSmXPes1qFI/AAAAAAAAABA/EXeq0PkLakMB9Rqdkn5kWvqN65XDUq4fwCK4B/s320/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-28%2B00.11.23.png" width="320" /></a>
yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-86979763556163513682017-05-28T02:44:00.002+09:002017-05-28T02:45:40.996+09:00check /etc/hosts by shell scriptTo practice shell script coding, I coded host check script which ping to hosts wrote in /etc/hosts file and generate check result logs.
<br />
<br />
<h4>
1. script
</h4>
<pre class="prettyprint"><code class="language-shell">#!/bin/bash
# make directory if unexist
DIR=./pinglog
if [ ! -d $DIR ]; then
mkdir $DIR
echo -e "directory created"
fi
# variables
LOGDIR=$DIR
NOW=$(date +"%Y%m%d-%H%M%S")
OKLOG=$LOGDIR/hostcheck_$NOW.log
NGLOG=$LOGDIR/hostcheck_error_$NOW.log
# check ping reply
while read line; do
hosts=$(echo $line | grep -v ^# | grep -v ^$ | grep -v localhost | cut -d " " -f 2)
# ping to hosts
if [ -n "$hosts" ]; then
ping -c 1 $hosts > /dev/null 2>&1
# it got reply "hostname : OK" else "hostname : NG"
# output OK-log and NG-log file
if [ $? -eq 0 ]; then
echo -e "$hosts : OK" >> $OKLOG
else
echo -e "$hosts : NG" >> $NGLOG
fi
fi
done < /etc/hosts
echo -e "done"
</code></pre>
github link is below
<a href="https://github.com/yoshi-island/shell-script_work/blob/master/check_hosts.sh" target="_blank">https://github.com/yoshi-island/shell-script_work/blob/master/check_hosts.sh</a>
<br />
<br />
<h4>
2. prepare
</h4>
In this case, I made active hosts by <a href="https://www.vagrantup.com/" target="_blank">vagrant</a> on <a href="https://www.virtualbox.org/" target="_blank">virtualbox</a>.
vagrantfile is wrote like this.
<br />
<pre class="prettyprint"><code class="language-shell">VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :server do |server|
server.vm.box = "centos7.0_x64"
server.vm.hostname = "server"
server.vm.network :private_network, ip: "192.168.111.223"
#server.ssh.private_key_path = "~/.ssh/id_rsa"
end
config.vm.define :client do |client|
client.vm.box = "centos7.0_x64"
client.vm.hostname = "client"
client.vm.network :private_network, ip: "192.168.111.224"
#client.ssh.private_key_path = "~/.ssh/id_rsa"
end
end</code></pre>
start machines on.
<br />
<pre class="prettyprint"><code class="language-shell">% vagrant up</code></pre>
<a href="http://2.bp.blogspot.com/-_tq8ABhK_Uo/WSmLHq-g16I/AAAAAAACZC8/PPqJFuVEXVIg2lGO2pPC0b7GRnDF0fz8ACK4B/s1600/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-27%2B23.18.09.png" imageanchor="1"><img border="0" height="133" src="https://2.bp.blogspot.com/-_tq8ABhK_Uo/WSmLHq-g16I/AAAAAAACZC8/PPqJFuVEXVIg2lGO2pPC0b7GRnDF0fz8ACK4B/s320/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-27%2B23.18.09.png" width="320" /></a>
</br>
/etc/hosts file is wrote like this.
<pre class="prettyprint"><code class="language-shell">% cat /etc/hosts | egrep -v "^#"
127.0.0.1 localhost
::1 localhost
192.168.111.223 server # active on virtualbox
192.168.111.224 client # active on virtualbox
111.111.111.111 dummy # dummyhost
</code></pre>
</br>
<h4>
3. execute
</h4>
execute</br>
<pre class="prettyprint"><code class="language-python">% bash check_hosts.sh
directory created
done
</code></pre>
results</br>
<pre class="prettyprint"><code class="language-python">% cat pinglog/hostcheck_20170527-232436.log
server : OK
client : OK
</code></pre>
<pre class="prettyprint"><code class="language-python">% cat pinglog/hostcheck_error_20170527-232436.log
dummy : NG
</code></pre>
yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-55252359148924524752017-05-28T02:43:00.002+09:002017-05-28T02:45:34.200+09:00hit and blow game coded by pythoncoding "hit and blow game" is a best way to get start studying new program language. I coded by python with my friends.</br>
</br>
<h4>
1. rules
</h4>
- find out correct 3 digits.</br>
- each digits used only at once, not like "555", "323"</br>
- if digit "correct" and place "incorrect", counted as "blow".</br>
- if digit "correct" and place "correct", counted as "hit".</br>
<pre class="prettyprint"><code class="language-python"></code>% python hitandblow.py
Enter three digits >>123
0 hit 0 blow
Enter three digits >>456
0 hit 1 blow
Enter three digits >>857
1 hit 2 blow
Enter three digits >>875
3 hit 0 blow
congratulation!
</code></pre>
</br>
<h4>
2. code sample
</h4>
<pre class="prettyprint"><code class="language-python">import random
def judge(c, u):
h=0
b=0
for x in range(3):
for y in range(3):
if c[x] == u[y]:
if x == y:
h = h + 1
else:
b = b + 1
print("%s hit %s blow" %(h,b))
if h == 3:
print("congratulation!")
return True
else:
return False
if __name__ == '__main__':
com = []
while len(com)!=3:
rannum = random.randint(0,9)
if rannum not in com:
com.append(rannum)
while True:
usrnum=input("Enter three digits >>")
usr = (int(usrnum[0]),int(usrnum[1]),int(usrnum[2]))
if judge(com,usr) == True:
break
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-84675525770180932042017-05-28T02:43:00.000+09:002017-05-28T02:45:23.841+09:00how to treat "<" ">" "&" on blogger post?<h4>
1. to write "<" ">" "&"
</h4>
when you want to write "<" ">" "&" on blogger post html editor. Use <a href="https://www.freeformatter.com/html-escape.html" target="_blank">FREEFORMATTER.COM</a>. get code and paste on your html.
<br />
<pre class="prettyprint"><code class="python">< > &</code></pre>
<br />
<h4>
2. to write "&lt; &gt; &amp;"
</h4>
To write "&lt; &gt; &amp;", write like this.</br>
<pre class="prettyprint"><code class="language-html">&amp;lt; &amp;gt; &amp;amp;
</code></pre>
How easy!yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-2329519374224015382017-05-28T02:42:00.001+09:002017-05-28T02:45:23.837+09:00highlight code on blogger with code-prettyMainly, there are two ways to highlight codes on blogger which are <a href="http://alexgorbatchev.com/SyntaxHighlighter/" target="_blank">syntaxhighlighter</a> and <a href="https://github.com/google/code-prettify" target="_blank">code-prettify</a>. I tried code-prettify and installation tips are below.
<br />
<br />
<h4>
1. config template
</h4>
open the http configuration page("theme" > "edit html")
<br />
<a href="http://3.bp.blogspot.com/-X4eUKw_iiok/WSlaPpJNs7I/AAAAAAACZCQ/JsjyoD87e-EecRsVurwCx5xVbtyT5n7ggCK4B/s1600/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-27%2B19.50.21.png" imageanchor="1"><img border="0" height="160" src="https://3.bp.blogspot.com/-X4eUKw_iiok/WSlaPpJNs7I/AAAAAAACZCQ/JsjyoD87e-EecRsVurwCx5xVbtyT5n7ggCK4B/s320/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-27%2B19.50.21.png" width="320" /></a><br />
<br />
put the script tag below just above "<head>".<br />
<pre><pre class="prettyprint"><code class="language-html"><script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
</code></pre></pre>
<a href="http://3.bp.blogspot.com/-plKHrecfGGY/WSlcKlXlSNI/AAAAAAACZCk/58jF7rS8IMgVdw3lWCjwbcPz3OoQCueCQCK4B/s1600/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-27%2B19.48.58.png" imageanchor="1"><img border="0" height="224" src="https://3.bp.blogspot.com/-plKHrecfGGY/WSlcKlXlSNI/AAAAAAACZCk/58jF7rS8IMgVdw3lWCjwbcPz3OoQCueCQCK4B/s320/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588%2B2017-05-27%2B19.48.58.png" width="320" /></a><br />
then push the save button.
<br />
<br />
<h4>
2. write blog post
</h4>
To write blog post, write like this. make sure you select "html" tab to edit post.
<pre class="prettyprint"><code class="language-html"><pre class="prettyprint"><code class="language-python">
# code here
print ("hogehoge")
</code></pre>
</code></pre>
shown like this.
<br />
<pre class="prettyprint"><code class="language-python"># code here
print ("hogehoge")
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-49389589217508965772017-05-28T02:30:00.003+09:002017-05-28T02:30:44.798+09:00hello golanghow to start <a href="https://golang.org" target="_blank">golang</a> on mac os.
</br>
<h4>
1. install golang
</h4>
<pre class="prettyprint"><code class="language-shell">% brew install go
</code></pre>
<h4>
2. coding
</h4>
<pre class="prettyprint"><code class="language-go">% cat go_work.go
package main
import "fmt"
func main() {
SayHello()
}
func SayHello() {
fmt.Println("Hello World for go lang")
}
</code></pre>
<h4>
3. execution
</h4>
run without build
<pre class="prettyprint"><code class="language-shell">% go run go_work.go
Hello World for go lang
</code></pre>
build and run
<pre class="prettyprint"><code class="language-shell">% go build go_work.go
% ./go_work
Hello World for go lang
</code></pre>
yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-60450863755987986912017-05-28T02:15:00.001+09:002017-05-28T02:32:42.243+09:00make sound with javascript javascript can make sound. I tried as a first javascript coding. the sound is from the famous Japanese movie :)</br>
</br>
push the button to play music. *check the system volume!!</br>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Audio API test</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" id="themesid">
<!-- Custom styles -->
<link href="https://getbootstrap.com/examples/theme/theme.css" rel="stylesheet">
<link href="https://getbootstrap.com/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/examples/offcanvas/offcanvas.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row row-offcanvas row-offcanvas-right">
<div class="col-xs-12 col-sm-9">
<div class="row">
<!-- button -->
<div class="container theme-showcase" role="main">
<p>
<button type="button" class="btn btn-lg btn-primary" id="PlayButton">Play</button>
</p>
</div>
</div>
</div>
</div>
</div>
<script>
function play() {
window.AudioContext = window.AudioContext || window.webkitAudioContext; // cross browser
var audioCtx = new AudioContext();
for (key = 0; key < music.length; key++) {
// define sound key
if(music[key] == "Do"){var hz = 262;}
if(music[key] == "re"){var hz = 294;}
if(music[key] == "mi"){var hz = 330;}
if(music[key] == "fa"){var hz = 349;}
if(music[key] == "so"){var hz = 392;}
if(music[key] == "la"){var hz = 440;}
if(music[key] == "si"){var hz = 494;}
if(music[key] == "Doo"){var hz = 523;}
if(music[key] == "ree"){var hz = 587;}
if(music[key] == "mii"){var hz = 659;}
if(music[key] == "faa"){var hz = 699;}
if(music[key] == "soo"){var hz = 784;}
if(music[key] == "laa"){var hz = 880;}
if(music[key] == "sii"){var hz = 988;}
// sound play
if(hz != "none"){
var osciillator = audioCtx.createOscillator(); // sound generate
osciillator.frequency.value = hz; // defined hertz
var audioDestination = audioCtx.destination; //defined sound output
osciillator.connect(audioDestination); // connect speaker
osciillator.start = osciillator.start || osciillator.noteOn; // cross browser
osciillator.start(); // start playing
osciillator.stop(audioCtx.currentTime + time[key]); // stop sound after time[key] sec
}
// sleep between each sound
Sleep(time[key]+0.1);
}
}
// sleep function
function Sleep(T){
var d1 = new Date().getTime();
var d2 = new Date().getTime();
while( d2 < d1+1000*T ){ // wait T sec
d2=new Date().getTime();
}
return;
}
// defined tone
var music = [];
music.push("soo");
music.push("mii");
music.push("Doo");
music.push("so");
music.push("so");
music.push("so");
music.push("la");
music.push("Doo");
music.push("faa");
music.push("laa");
music.push("soo");
// defined length of sound
var time = [];
time.push(0.7);
time.push(0.2);
time.push(0.7);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.7);
// execution
var Button1 = document.getElementsByClassName("btn btn-lg btn-primary");
Button1[0].addEventListener("click", play, false);
</script>
</body>
</html>
sample code is below.</br>
<pre class="prettyprint"><code class="language-html"><!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Audio API test</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" id="themesid">
<!-- Custom styles -->
<link href="https://getbootstrap.com/examples/theme/theme.css" rel="stylesheet">
<link href="https://getbootstrap.com/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/examples/offcanvas/offcanvas.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row row-offcanvas row-offcanvas-right">
<div class="col-xs-12 col-sm-9">
<div class="row">
<!-- button -->
<div class="container theme-showcase" role="main">
<p>
<button type="button" class="btn btn-lg btn-primary" id="PlayButton">Play</button>
</p>
</div>
</div>
</div>
</div>
</div>
<script>
function play() {
window.AudioContext = window.AudioContext || window.webkitAudioContext; // cross browser
var audioCtx = new AudioContext();
for (key = 0; key < music.length; key++) {
// define sound key
if(music[key] == "Do"){var hz = 262;}
if(music[key] == "re"){var hz = 294;}
if(music[key] == "mi"){var hz = 330;}
if(music[key] == "fa"){var hz = 349;}
if(music[key] == "so"){var hz = 392;}
if(music[key] == "la"){var hz = 440;}
if(music[key] == "si"){var hz = 494;}
if(music[key] == "Doo"){var hz = 523;}
if(music[key] == "ree"){var hz = 587;}
if(music[key] == "mii"){var hz = 659;}
if(music[key] == "faa"){var hz = 699;}
if(music[key] == "soo"){var hz = 784;}
if(music[key] == "laa"){var hz = 880;}
if(music[key] == "sii"){var hz = 988;}
// sound play
if(hz != "none"){
var osciillator = audioCtx.createOscillator(); // sound generate
osciillator.frequency.value = hz; // defined hertz
var audioDestination = audioCtx.destination; //defined sound output
osciillator.connect(audioDestination); // connect speaker
osciillator.start = osciillator.start || osciillator.noteOn; // cross browser
osciillator.start(); // start playing
osciillator.stop(audioCtx.currentTime + time[key]); // stop sound after time[key] sec
}
// sleep between each sound
Sleep(time[key]+0.1);
}
}
// sleep function
function Sleep(T){
var d1 = new Date().getTime();
var d2 = new Date().getTime();
while( d2 < d1+1000*T ){ // wait T sec
d2=new Date().getTime();
}
return;
}
// defined tone
var music = [];
music.push("soo");
music.push("mii");
music.push("Doo");
music.push("so");
music.push("so");
music.push("so");
music.push("la");
music.push("Doo");
music.push("faa");
music.push("laa");
music.push("soo");
// defined length of sound
var time = [];
time.push(0.7);
time.push(0.2);
time.push(0.7);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.2);
time.push(0.7);
// execution
var Button1 = document.getElementsByClassName("btn btn-lg btn-primary");
Button1[0].addEventListener("click", play, false);
</script>
</body>
</html>
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-91018022921005920412017-05-28T02:00:00.000+09:002017-05-28T02:00:19.289+09:00differences between "pyenv", "pyenv-virtualenv" and "virtualenv"differences between "pyenv", "pyenv-virtualenv" and "virtualenv" are very confusing. clearly defined the definition on this article.</br>
</br>
<h4>
1. pyenv
</h4>
"pyenv" globally manage python versions. each versions has one environment.
<pre class="prettyprint"><code class="language-shell">% pyenv versions
system
2.7.5
2.7.6
2.7.8
* 3.5.0
</code></pre>
</br>
<h4>
2. virtualenv
</h4>
"pyenv-virtualenv" is external function of pyenv. multiple environments can exist on same versions.
<pre class="prettyprint"><code class="language-shell">~/virtualenv1 % bash bin/activate # activate peen-virtualenv
(virtualenv1) ~/virtualenv1 % pyenv versions
system
2.7.5
2.7.6
2.7.8
* 3.5.0 (set by xxx/.python-version)
</code></pre>
<pre class="prettyprint"><code class="language-shell">(virtualenv1) ~/virtualenv1 % deactivate # deactivate peen-virtualenv
~/virtualenv1 %
</code></pre>
</br>
<h4>
3. pyenv-virtualenv
</h4>
"virtualenv" apply python versions to each directories. virtualenv automatically change environment when user move on the directories.
<pre class="prettyprint"><code class="language-shell">~/pyenv_test $ cd pyenv-virtualenv1/
(pyenv-virtualenv1) ~/pyenv_test/pyenv-virtualenv1 $
(pyenv-virtualenv1) ~/pyenv_test/pyenv-virtualenv1 $ cat .python-version
pyenv-virtualenv1
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-10566277110834430302017-05-28T01:35:00.000+09:002017-05-28T01:35:00.623+09:00generate random odd/even number with ansible<a href="http://docs.ansible.com/ansible/playbooks_filters.html#random-number-filter" target="_blank">ansible random module</a> can control start, end and steps when generate random number.</br>
</br>
<h4>
1. make odd and even random number
</h4>
code here.</br>
<pre class="prettyprint"><code class="language-yaml">% cat random_test.yml
- hosts: all
become: true
user: vagrant
tasks:
- set_fact:
var1: "{{ 100 |random(1,2) }}" # odd random number 1-100
var2: "{{ 100 |random(2,2) }}" # even random number 2-100
- debug:
msg:
- "odd number is {{ var1 }}"
- "even number is {{ var2 }}"
</code></pre>
generate numbers successfully.</br>
<pre class="prettyprint"><code class="language-python">% ansible-playbook -i hosts random_test.yml
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [192.168.111.223]
ok: [192.168.111.224]
TASK [set_fact] ****************************************************************
ok: [192.168.111.224]
ok: [192.168.111.223]
TASK [debug] *******************************************************************
ok: [192.168.111.224] => {
"msg": [
"odd number is 33",
"even number is 80"
]
}
ok: [192.168.111.223] => {
"msg": [
"odd number is 1",
"even number is 72"
]
}
PLAY RECAP *********************************************************************
192.168.111.223 : ok=3 changed=0 unreachable=0 failed=0
192.168.111.224 : ok=3 changed=0 unreachable=0 failed=0
</code></pre>
yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-31717874223514020452017-05-28T01:21:00.001+09:002017-05-28T01:24:45.175+09:00how to start ansible?<a href="https://www.ansible.com" target="_blank">Ansible</a> is a tool to automatically build and configure virtual machines. There are many ways to build directory tree to execute ansible codes. Today I will show you the easiest way to get start ansible. *on mac os environment</br>
</br>
<h4>
1. install ansible
</h4>
please check your computer has python. ansible works on python.
<pre class="prettyprint"><code class="language-shell">% python
...
>>>
</code></pre>
</br>
if you have not install yet, get it.</br>
*the command below is for mac os.</br>
<pre class="prettyprint"><code class="language-shell">% brew install python
</code></pre>
Then, get ansible.</br>
<pre class="prettyprint"><code class="language-shell">% pip install ansible
</code></pre>
</br>
<h4>
2. prepare directory and files
</h4>
create the files below under the same directory.</br>
<pre class="prettyprint"><code class="language-python">% ls
ansible.cfg # configuration file
hosts # hosts file
hello_ansible.yml # execution file
</code></pre>
</br>
include define hosts file path and ssh key file path on ansible.cfg file.</br>
<pre class="prettyprint"><code class="language-python">% cat ansible.cfg
[defaults]
hostfile = ./hosts
private_key_file=$HOME/.ssh/id_rsa
</code></pre>
include target hosts address, username and passwords on ansible.cfg file. I have two hosts "192.168.111.223" and "192.168.111.224".</br>
<pre class="prettyprint"><code class="language-python">% cat hosts
[all]
192.168.111.223
192.168.111.224
[server]
192.168.111.223
[client]
192.168.111.224
[all:vars]
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
</code></pre>
ansible script file is here.</br>
<pre class="prettyprint"><code class="language-python">% cat hello_ansible.yml
- hosts: all
become: true
user: vagrant
tasks:
- debug:
msg:
- "hello ansible"
</code></pre>
</br>
<h4>
3. execution
</h4>
<pre class="prettyprint"><code class="language-python">% ansible-playbook -i hosts hello_ansible.yml
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [192.168.111.223]
ok: [192.168.111.224]
TASK [debug] *******************************************************************
ok: [192.168.111.224] => {
"msg": [
"hello ansible"
]
}
ok: [192.168.111.223] => {
"msg": [
"hello ansible"
]
}
PLAY RECAP *********************************************************************
192.168.111.223 : ok=2 changed=0 unreachable=0 failed=0
192.168.111.224 : ok=2 changed=0 unreachable=0 failed=0
</code></pre>yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.comtag:blogger.com,1999:blog-3106903900750474751.post-40604158880702323942017-05-28T00:32:00.001+09:002017-05-28T00:32:38.983+09:00auto ssh login shell scriptautomatically ssh login script below.
</br>
<h4>
1. directory tree
</h4>
<pre class="prettyprint"><code class="language-shell">% tree
.
├── auto_login.sh # main file
├── login_client.sh # script to login client host
└── login_server.sh # script to login server host
</code></pre>
<pre class="prettyprint"><code class="language-shell">% cat auto_login.sh
#!/bin/sh
auto_ssh() {
host=$1
id=$2
pass=$3
expect -c "
set timeout 10
spawn ssh ${id}@${host}
#expect \"Are you sure you want to continue connecting (yes/no)?\"
#send \"yes\n\"
expect \"${id}@${host}'s password:\"
send \"$pass\n\"
expect \"# \"
send \"cd /opt/work/ ; ls\n\"
interact
"
}
</code></pre>
remove "#" if you have not exchange ssh key with target host yet.</br>
<pre class="prettyprint"><code class="language-shell">% cat login_server.sh
#!/bin/sh
# execute main script
. ./auto_login.sh
# auto login 'host address' 'username' 'password'
auto_ssh '192.168.111.223' 'vagrant' 'vagrant'
</code></pre>
<pre class="prettyprint"><code class="language-shell">% cat login_client.sh
#!/bin/sh
# execute main script
. ./auto_login.sh
# auto login 'host address' 'username' 'password'
auto_ssh '192.168.111.224' 'vagrant' 'vagrant'
</code></pre>
</br>
<h4>
2. execution
</h4>
<pre class="prettyprint"><code class="language-shell">% bash login_server.sh
spawn ssh vagrant@192.168.111.223
vagrant@192.168.111.223's password:
Last login: Sat May 27 17:19:45 2017 from 192.168.111.1
Welcome to your Vagrant-built virtual machine.
[vagrant@server ~]$
</code></pre>
yoshihttp://www.blogger.com/profile/16291957811502746219noreply@blogger.com