Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Wednesday, January 3, 2018

csv update app with spyre python

now I created csv update app with spyre. full code is here.

Preparation

set python vision and install dataspyre.
% python -V
Python 3.5.0
 
% pip install dataspyre

set directory tree as below. "test_data.csv" is the csv file to edit. number of columns have to be 5.

% tree
.
├── csv_update.py
├── data
│   ├── test_data.csv


% 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

Execution


% python csv_update.py

Then, access to "http://127.0.0.1:9093"
input file name and push "get data" button.



input data and push "add data" button.




push "get data" button again to check added data.
backup data added under "data" directory in case.




% tree
.
├── csv_update.py
├── data
│   ├── test_data.csv
│   ├── test_data.csv_20180103173523
│   └── test_data.csv_20180103174330

% 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

Saturday, December 2, 2017

Where is the gateway IP address with NAT on VMware Fusion?

(1) check NAT network assigned by ifcofig


% ifconfig
......
vmnet1: flags=8863 mtu 1500
ether xxxxx
inet 192.168.167.1 netmask 0xffffff00 broadcast 192.168.167.255
vmnet8: flags=8863 mtu 1500
ether xxxxx
inet 192.168.154.1 netmask 0xffffff00 broadcast 192.168.154.255
......

vmnet1 is for host-only network. now, I use vmne8 (NAT) network to fix geteway IP of the VM.




(2) check vmnet8 config file


find gateway address on /Library/Preferences/VMware Fusion/vmnet8

/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

.......

Saturday, July 8, 2017

deploy proxy server with nginx

the proxy server is built on nginx. environment is shown below. two ubuntu virtual machines deployed by vagrant and each virtual machine has nginx.


one(192.168.33.10) is for webserver and the other(192.168.33.11) is for proxy.



# install virtualbox

http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html?ssSourceSiteId=otnus


# install vagrant

https://www.vagrantup.com/downloads.html

check version which installed
% vagrant --version
Vagrant 1.9.6


# deploy virtual machines

## 192.168.33.11(Proxy Server)

% 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


## 192.168.33.10(Web Server)

% 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

## check point

two virtual machines are running on virtualbox.



# set IP address

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work

edit file.
% 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

restart virtual machine.
% vagrant halt
==> default: Attempting graceful shutdown of VM...
% vagrant up

check ping echo.
 % ping -c 3 192.168.33.11


## 192.168.33.10(Web Server)

move to directory.
% cd
% cd vagrant_work2

edit file.
% 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

restart virtual machine.
% vagrant halt
==> default: Attempting graceful shutdown of VM...
% vagrant up

check ping echo.
 % ping -c 3 192.168.33.10


# install nginx

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work
% vagrant ssh

install nginx on virtual machine.
# apt-get install nginx
# cp /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.backup

edit index.html like this.
# vi /usr/share/nginx/html/index.html
# cat /usr/share/nginx/html/index.html
192.168.33.11


## 192.168.33.10(Web Server)

move to directory.
% cd
% cd vagrant_work2
% vagrant ssh

install nginx on virtual machine.
# apt-get install nginx
# cp /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.backup

edit index.html like this.
# vi /usr/share/nginx/html/index.html
# cat /usr/share/nginx/html/index.html
192.168.33.10


## check point

then, check if http access available.
http://192.168.33.11


http://192.168.33.10



# proxy config (no ssl)

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work
% vagrant ssh

edit file like this.
# 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 ]



## check point

then check again. it shows 192.168.33.10 page. it means proxy server pass to webserver.
http://192.168.33.11



# proxy config (ssl)

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work
% vagrant ssh

ssl settings
# 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



## check point

# ls
server.crt  server.csr  server.key  server.key.org
# pwd
/usr/local/tmp

edit file.
# 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/;
  }
}

nginx service restart.
# service nginx restart
 * Restarting nginx nginx                                               [ OK ]


## check point

then, access to https page.
https://192.168.33.11