2018年10月22日 星期一

TestLink setup on CentOS 7

#Install PostgreSQL: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-centos-7
# sudo yum install postgresql-server postgresql-contrib
# sudo postgresql-setup initdb
# sudo systemctl start postgresql
# sudo systemctl enable postgresql

https://dotblogs.com.tw/jovepaterlab/2017/04/17/222958
[root@localhost peter]# su - postgres
-bash-4.2$ psql -U postgres
psql (9.6.2)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'password'
postgres-# \q
-bash-4.2$ exit
logout

Edit /var/lib/pgsql/data/pg_hba.conf
local    all             all                                    md5
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

https://www.tecmint.com/install-php-7-in-centos-7/
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum-config-manager --enable remi-php72
# yum install php php-mcrypt php-cli php-gd php-curl php-pgsql php-ldap php-zip php-fileinfo
# php -v

Enable Apache2
# systemctl start httpd
# systemctl enable httpd

Edit /etc/php.ini
session.gc_maxlifetime = 2400
max_input_vars = 3000
memory_limit = 256M
upload_max_filesize = 20M
max_execution_time = 120


Set MySQL password
mysqladmin -u root password password

# Copy Testlink source code
# wget -e use_proxy=yes -e https_proxy=jack_lin3.compal.com:3128 https://github.com/TestLinkOpenSourceTRMS/testlink-code/archive/testlink_1_9.zip
   47  unzip
# unzip testlink_1_9.zip -d /var/www/html/
# cd /var/www/html/
# ls
# mv testlink-code-testlink_1_9/ testlink/
# ls
# chown -R apache:apache testlink
mkdir  /var/testlink
mkdir /var/testlink/logs
mkdir /var/testlink/upload_area
chown apache:apache /var/testlink/logs
chown apache:apache /var/testlink/upload_area


Check firewall setting
https://linuxhint.com/list_open_ports_firewalld/
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7

Add http service in firewall
# sudo firewall-cmd --zone=public --permanent --add-service=http

link1
link2
# sudo chcon -Rv --type httpd_sys_rw_content_t /var/www/html/testlink/gui/templates_c
##### chcon -Rv --type httpd_sys_rw_content_t /var/www/html/testlink
https://tripal.info/tutorials/v3.x/installation/server-setup/centos7
# setsebool -P httpd_can_network_connect_db on

Remove line 872~879
/install/sql/postgres/testlink_create_tables.sql
https://github.com/TestLinkOpenSourceTRMS/testlink-code/blob/testlink_1_9/install/sql/postgres/testlink_create_tables.sql


Open http:///testlink, Follow steps to install.

YOU NEED TO RUN MANUALLY Following Script on your DB CLIENT Application

/var/www/html/testlink/install/sql/postgres/testlink_create_udf0.sql


YOUR ATTENTION PLEASE:
To have a fully functional installation You need to configure mail server settings, following this steps

    copy from config.inc.php, [SMTP] Section into custom_config.inc.php.
    complete correct data regarding email addresses and mail server.


Installation was successful!
You can now log in to Testlink (using login name:admin / password:admin - Please Click Me!).

2018年10月18日 星期四

Deploying Flask App with mod_wsgi (Python3) in Ubuntu 1804

1. Install apache2
2. Install mod_wsgi
# sudo apt install libapache2-mod-wsgi-py3
3. Create a Python3 virtualenv with Flask installed
# mkvirtualenv -p $(which python3) flask
(flask)# pip install flask
4. Create a .wsgi file for project (put in project folder)
newsite.wsgi:

activate_this = '/home/jack/.virtualenvs/flask/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))
import sys
sys.path.insert(0, '/home/jack/Documents/Projects/newsite')
from app import app as application

5. Open Apache2 ports. Edit file /etc/apache2/ports.conf

Listen 4002

6. Create a file for new site in /etc/apache2/sites-available
newsite.conf:


    ServerName newsite

    WSGIDaemonProcess newsite user=jack group=jack threads=5
    WSGIScriptAlias / /home/jack/Documents/Projects/newsite/newsite.wsgi

   
        WSGIProcessGroup newsite
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
   


7. Enable the newsite
# sudo a2ensite newsite
(a2dissite for disable)

8. Reload the Apache2
# sudo systemctl reload apache2

9. Allow port 4002 by ufw
# sudo ufw allow 4002
(sudo ufw delete allow 4002) to disable

10. Open broswer to browse http://:4002

Note1. Apache2 error log is in /var/log/apache2/error.log

Note2. If you are using open() in app.py, need to instead to app.open_resource() to prevent FileNotFoundException

Reference:
http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/
http://flask.pocoo.org/docs/0.12/api/#flask.Flask.open_resource

2018年8月16日 星期四

iSCSI target setup (Ubuntu)

https://www.server-world.info/en/note?os=Ubuntu_18.04&p=iscsi&f=1
https://wiki.archlinux.org/index.php/ISCSI/LIO

# create a directory

root@dlp:~# 
mkdir /var/lib/iscsi_disks 
# enter the admin console

root@dlp:~# 
targetcli 

targetcli shell version 2.1.fb43
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> cd backstores/fileio 

# create a disk-image with the name "disk01" on /var/lib/iscsi_disks/disk01.img with 10G
/backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 10G 
Created fileio disk01 with size 10737418240
/backstores/fileio> cd /iscsi 

# create a target
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
/iscsi> create iqn.2018-05.world.srv:dlp.target01 
Created target iqn.2018-05.world.srv:dlp.target01.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2018-05.world.srv:dlp.target01/tpg1/luns 

# set LUN
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk01 
Created LUN 0.
/iscsi/iqn.20...t01/tpg1/luns> cd ../acls 

# set ACL (it's the IQN of an initiator you permit to connect)
/iscsi/iqn.20...t01/tpg1/acls> create iqn.2018-05.world.srv:www.initiator01 
Created Node ACL for iqn.2018-05.world.srv:www.initiator01
Created mapped LUN 0.
/iscsi/iqn.20...t01/tpg1/acls> cd iqn.2018-05.world.srv:www.initiator01 

# set UserID for authentication
/iscsi/iqn.20...w.initiator01> set auth userid=username 
Parameter userid is now 'username'.
/iscsi/iqn.20...w.initiator01> set auth password=password 
Parameter password is now 'password'.
/iscsi/iqn.20...w.initiator01> exit 
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/rtslib-fb-target/backup.
Configuration saved to /etc/rtslib-fb-target/saveconfig.json

# after configuration above, the target enters in listening like follows

root@dlp:~# 
ss -napt | grep 3260 

LISTEN   0         256                 0.0.0.0:3260             0.0.0.0:* 

Disable Authentication

Navigate targetcli to your target (i.e. /iscsi/iqn.../tpg1) and:
.../tpg1> set attribute authentication=0

2018年7月12日 星期四

Samba on Ubuntu

Ref

# apt install samba
# edit /etc/samba/smb.conf
create folder
# mkdir /var/samba
# chmod 777 /var/samba

Add this:
[public]
  comment = public anonymous access
  path = /var/samba/
  browsable =yes
  create mask = 0666
  directory mask = 0777
  writable = yes
  guest ok = yes

# systemctl restart smbd

2018年7月10日 星期二

HTTPS on Ubuntu 1804 (use default-ssl.conf)

# sudo -i
# apt install apache2
# a2enmod ssl
# a2ensite default-ssl.conf
# systemctl restart apache2

config files in /etc/apache2/sites-available
log files in /var/log/apache2/

use browser to browse https://

2018年6月28日 星期四

用Flask-SQLAlchemy把Model定義獨立到models.py

https://stackoverflow.com/questions/9692962/flask-sqlalchemy-import-context-issue/9695045#9695045

models.py
=====
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

db = SQLAlchemy()

class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)

def __repr__(self):
return '%r>' % self.username

class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(80), nullable=False)
body = db.Column(db.Text, nullable=False)
json = db.Column(db.JSON)
pub_date = db.Column(db.DateTime, nullable=False,
default=datetime.utcnow)

category_id = db.Column(db.Integer, db.ForeignKey('category.id'),
nullable=False)
category = db.relationship('Category',
backref=db.backref('posts', lazy=True))

def __repr__(self):
return '%r>' % self.title

class Category(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False)

def __repr__(self):
return '%r>' % self.name


app.py
======
from flask import Flask
# from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
from models import db, User, Post, Category

app = Flask(__name__)
#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///jack'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# db = SQLAlchemy(app)
db.init_app(app)
admin = Admin(app, name='flask-sql', template_mode='bootstrap3')

admin.add_view(ModelView(User, db.session))
admin.add_view(ModelView(Post, db.session))
admin.add_view(ModelView(Category, db.session))

2018年6月22日 星期五

Ubuntu install postgresql & flask-sqlalchemy

# sudo apt install postgresql
# sudo systemctl enable postgresql
# sudo -i -u postgres
# createuser --interactive
jack
y
Note. already have a user named jack
# createdb jack
Note. create a database named jack.
logout from postgres
#logout

Edit the Flask app.py
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///jack'

You can save JSON type now
json = db.Column(db.JSON)

2018年6月21日 星期四

遇到密碼對 可是登不進ssh

Check the log in /var/log/auth.log
$ grep sshd /var/log/auth.log | less
看到
sshd[2110]: User jack not allowed because shell /usr/bin/zsh does not exist

可能是之前有安裝過zsh但是沒有移乾淨
下env | grep SHELL看到的確是/usr/bin/zsh

用chsh指令改
$ sudo chsh -s /bin/bash jack
解決不能登入ssh問題

Robotframework 變數檔案

使用-V 參數

# robot -V vars.yaml a.robot

vars.yaml內容
BMC_IP: 172.16.1.16

For using "Library    Dialogs"
apt-get install python3-tk
pip intall tkinter

2018年5月18日 星期五

Setup Python3 develop environment on Ubuntu Server 1804

1. Install Ubuntu Server 1804
2. Install pip3 & python3-dev
# sudo apt install python3-pip python3-dev
3. update pip
# python3 -m pip install -U pip
4. logout and login
5. Install virtualenvwrapper
# python3 -m pip install --user virtualenvwrapper
6. add variable in .bashrc
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
7. include virtualenvwrapper in .bashrc
Add following in tail of .bashrc
# set ~/.local/bin in PATH
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

# virtualenvwrapper
source $(which virtualenvwrapper.sh)
8. logout & login again
9. create a virtualenv
# mkvirtualenv env1

for APT proxy setting: /etc/apt/apt.conf
Acquire::http::Proxy "http://yourproxyaddress:proxyport";

for pip proxy setting per-user: ~/.config/pip/pip.conf
[global]
proxy = http://127.0.0.1:3128

https://medium.com/@gitudaniel/installing-virtualenvwrapper-for-python3-ad3dfea7c717

2018年5月16日 星期三

Increase upload file size limit of TestLink

Edit /etc/php.ini file

upload_max_filesize = 100M
max_execution_time = 600

Edit
/var/html/www/testlink/config.inc.php
$tlCfg->import_file_max_size_bytes (config.inc.php): 8192000
$tlCfg->import_max_row (config.inc.php): 100000
$tlCfg->repository_max_filesize (config.inc.php): 8 // MB

restart Apache
service apache2 restart
or
service httpd restart

2018年3月29日 星期四

Use mkvirtualenv of virtualenvwrapper-win to create diffenrent Python version of env

應用Python的virtualenv和virtualenvwrapper可方便建立Python的virtual enviroment,方便在不同的environment切換,各env有獨立的pip list和Python版本

首先要安裝Python (Linux已有內建Python2)

  1. Windows安裝完後要將PATH設定包含到C:\Python27
  2. 安裝virtualenv, pip install virtualenv
  3. 安裝virtualenvwrapper或是virtualenvwrapper-win (Windows版)
  4. 建立virtualenv
    1. mkvirtualenv env01
  5. 查看pip list, pip list
  6. 跳出env01, deactivate
  7. 查看目前有多少virtualenv, workon
  8. 進入virtualenv env01, workon env01
  9. 若要建立Python3的virtualenv, 先安裝Python3
  10. 確認Pyhon3的python.exe位置 (C:\Users\Jack_Lin\AppData\Local\Programs\Python\Python35\python.exe), 若是Linux, 可用which python3指令查看
  11. 建立一Python3的virtualenv
    1. mkvirtualenv -p C:\Users\Jack_Lin\AppData\Local\Programs\Python\Python35\python.exe python35
    2. python -V

2018年2月8日 星期四

ipmitool ipmi-raw ipmiutil cmd (icmd) raw command format

ipmitool:
ipmitool -I lanplus -H 192.168.1.123 -U admin -P password raw 0x06 0x01

ipmi-raw:
ipmi-raw -D LAN_2_0 -h 192.168.1.123 -u admin -p password 0x00 0x06 0x01

icmd:
icmd -J 3 -N 192.168.1.123 -U admin -P password 00 20 18 01

redfishtool on ubuntu

1. apt-get update
2. apt-get install python python3 python-pip
3. make a file /etc/pip.conf if you need proxy setting for pip
[list]
format=columns
[global]
trusted-host = pypi.python.org
proxy = http://127.0.0.1:3128
4. pip install virtualenvwrapper
5. login with normal user (not root)
6. add one line in tail of .bashrc
source $(which virtualenvwrapper.sh)
7. re-login
8. create a virtualenv of python3
mkvirtualenv -p $(which python3) redfish
9. pip install redfishtool

redfishtool commands:

redfishtool -u admin -p password -r 192.168.1.123 -S Always System
redfishtool -u admin -p password -r 192.168.1.123 -S Always System -a
redfishtool -u admin -p password -r 192.168.1.123 -S Always raw /redfish/v1/xxxx/xxxx

======
For Ubuntu 17.10, before step5
Need to add ~/.local/bin to PATH, edit ~/.bashrc
# set PATH ~/.local/bin
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

2018年2月7日 星期三

Install freeipmi on ubuntu

1. Download source from https://www.gnu.org/software/freeipmi/
2. install libgcrypt-dev
# sudo apt-get install libgcrypt-dev
3. compiler
# tar zxvf freeipmi-1.6.1.tar.gz
# cd freeipmi-1.6.1
# ./configure
# make
# sudo make install
4. make the change permanent you can add /usr/local/lib to /etc/ld.so.conf (or something it includes) and run ldconfig as root.
https://unix.stackexchange.com/questions/67781/use-shared-libraries-in-usr-local-lib


2018年1月24日 星期三

docker named volume path

Located at host's /var/lib/docker/volumes/

https://stackoverflow.com/questions/36312699/chown-docker-volumes-on-host-possibly-through-docker-compose/36321403#36321403

https://github.com/CWSpear/local-persist

Python project scaffold

http://docs.python-guide.org/en/latest/writing/structure/
https://www.kennethreitz.org/essays/repository-structure-and-python
https://github.com/pypa/sampleproject
https://github.com/sroberts/python-starter

找到這個generator,感覺更方便,處理方式也比較先進。
https://pypi.python.org/pypi/PyScaffold
pip install pyscaffold
putup my_project

如果是Django project可加--django參數,不過應該只是單純的幫你多下一次
django-admin.py startproject my_project而已

如果想要把apps放到不是project的root,而是像src的資料夾
在startapp之前要先把資料夾建好
mkdir ./src/newapp
然後才startapp
python manage.py startapp newapp ./src/newapp

之後要在project的setting.py多加這兩行
import sys
sys.path.insert(0, os.path.join(BASE_DIR, "src"))
才能在runserver時找到newapp
參考這個的

2018年1月16日 星期二

用Bitbucket存放Source code (如果ssh port22被擋)


SSH的 git@bitbucket.org:farwill/testlink_converter.git
改成HTTPS的 https://farwill@bitbucket.org/farwill/testlink_converter.git

所以是
git remote add origin https://farwill@bitbucket.org/farwill/testlink_converter.git
git push -u origin master