星期日, 5月 15, 2016

PyCharm 安裝 with openSUSE Leap 42.1

PyCharm 安裝 with openSUSE Leap 42.1

今年想要投入多點時間在 python 上面, 所以建立一個讀書會
在讀書會中, 我們商議的開發環境為 Pycharm 這個軟體, 他的好處是 Mac / Windows / Linux 都有, 今天來寫 Linux 上面的安裝

OS: openSUSE Leap 42.1


下載頁面


下載之後解壓縮,  我之前是用一般使用者, 後來決定用 root 解壓縮到 /opt 方便後面管理
#  tar   zxvf   pycharm-community-2016.1.3.tar.gz  -C  /opt

用一般使用者身份進行安裝, 執行 pycharm.sh

> /opt/pycharm-community-2016.1.3/bin/pycharm.sh

首先是安裝的詢問, 如果沒有裝過之前的版本就選 I do not have a previous version of PyCharm or I do not want to import my settings

2016-05-15 12-51-33 的螢幕擷圖.png

接受授權
點選 Accept

2016-05-15 12-52-58 的螢幕擷圖.png

出現初始化設定, 他會在 /usr/local/bin/ 下建立 charm
我這邊是預設值 點選 OK

2016-05-15 12-54-42 的螢幕擷圖.png


進行相關安裝要取得管理者授權
輸入系統管理者密碼
2016-05-15 12-55-34 的螢幕擷圖.png


歡迎畫面
這邊我先選 Create New Project
2016-05-15 12-57-59 的螢幕擷圖.png

接下來會進入設定畫面
預設是在家目錄的 PycharmProject/ 下

這邊 Interpreter 可以選 2.x 或是 3.x python, 我是選 python3.4
點選 Create

2016-05-15 12-59-56 的螢幕擷圖.png


程式介面
2016-05-15 13-03-56 的螢幕擷圖.png


安裝完成之後, 相關設定是儲存在家目錄的 .PyCharm2016.1
> ls  -ald    ~/.P*
drwxr-xr-x 4 sakana users 4096  5月 15 13:24 /home/sakana/.PyCharm2016.1

順便觀察一下 /usr/local/bin
> ls   -l   /usr/local/bin/
總計 4
-rwxr-xr-x 1 root root 3062  5月 15 13:24 charm
接下來進行個人化的部份

點選 File -- >  Settings

開啟行號
在 Editor -- >  General  勾選 Show line Numbers  -- > 點選 OK

2016-05-15 13-55-12 的螢幕擷圖.png


接下來解決中文亂碼的問題
點選 File -- >  Settings
在 Editor -- >  File and Code Templates
點選 Python Script , 輸入 # -*- coding: utf-8 -*-
點選 OK

2016-05-15 14-01-15 的螢幕擷圖.png


接下來設定 Github 的部份

點選  VCS  -- > Checkout from Version Control  -- >  Github

Login: 輸入自己的 email
Password: 輸入密碼
點選 Login

2016-05-15 14-08-53 的螢幕擷圖.png

接下來選取要匯入的專案
點選 Clone

2016-05-15 14-11-11 的螢幕擷圖.png

接下來會貼心的問要不要開啟專案

2016-05-15 14-12-20 的螢幕擷圖.png

開啟時有提醒 Markdown 可以安裝 plugin
按照提醒安裝即可

2016-05-15 14-13-57 的螢幕擷圖.png
2016-05-15 14-14-07 的螢幕擷圖.png

另外有提醒 還沒有設定 Python interpreter ( 因為同時有 2.x 以及 3.x )

2016-05-15 14-17-29 的螢幕擷圖.png

會自動跳到設定視窗

2016-05-15 14-18-32 的螢幕擷圖.png

這邊我自己是用 python 3.4

2016-05-15 14-20-09 的螢幕擷圖.png

重新啟動 PyCharm 就可以看到剛剛 Markdown 支援的效果

2016-05-15 14-22-48 的螢幕擷圖.png



icon 的部份, 如果不想用 command line 啟動 smartgit 可以試試看 alacarte 建立


設定參考

先寫到這邊

~ enjoy it

星期五, 5月 13, 2016

以 ansible 安裝 consul in openSUSE Leap 42.1

Consul with ansible

因為之後 docker swarm 需要用到 consul , 所以就建立 consul

OS: openSUSE Leap 42.1

一般建立 consul 的作法

建立使用者 consul ( 不一定要建立這個使用者, 這個是工作上協調的結果 )
#useradd  -m  consul

建立相關目錄
#mkdir  -p  /opt/consul/bin   /opt/consul/data   /opt/consul/config

設定權限以及更改擁有人為使用者 consul
#chown  -R  consul   /opt/consul/

#chmod  -R  700  /opt/consul/

從網路取得 consul 並解壓縮 zip ( 這邊以 0.6.4 為例 )


#unzip  consul_0.6.4_linux_amd64.zip

將 consul 複製到指定的目錄
#cp  consul   /opt/consul/bin

切換使用者 consul
#su  -  consul

編寫設定檔 ( 這邊我們是先試用官方的服務 https://atlas.hashicorp.com/consul )
>vi   /opt/consul/config/atlas_consul.json


{
 "bind_addr": "請填入機器IP",
 "atlas_infrastructure": "請填入帳號/請填入名稱",
 "atlas_join": true,
 "atlas_token": "請填入自己的token",
 "bootstrap_expect": 3,
 "datacenter": "Hsinchu-NCHC",
 "data_dir": "/opt/consul/data",
 "log_level": "INFO",
 "node_name": "請填入主機名稱",
 "encrypt": "請填入加密的資訊",
 "server": true
}


啟動 consul agent
> /opt/consul/bin/consul   agent   -config-dir   /opt/consul/config/

目前是用 nohup 方式在背景執行, 然後離開
> nohup /opt/consul/bin/consul agent -config-dir /opt/consul/config/ &

停止 consul 的方式( 這樣不會產生 error )
/opt/consul/bin/consul  leave

------- Ansible 方式 ----------

接下來自己寫了一個 ansible 的playbook 來安裝 consul

檔案名稱 Consul_install.yml

---
#########################################################  
# Install consul and setup boot
- name: use when conditionals and setup module (facts)
 hosts: all
 tasks:
# 使用 setup moudule 列出 OS 種類
   - name: use setup module to list os distribution
# setup moudle 可以使用 filter 過濾相關內容
     setup: filter=ansible_distribution


#########################################################  

- name: Install consul , add user and setting up env
# use group
 hosts: ConsulHost
 sudo: True
 tasks:
   - name: Add user consul
     user: name=consul

   - name: Create folder for consul
     file: path=/opt/consul/{{ item }} state=directory owner=consul mode=700
     with_items:
       - bin
       - data
       - config

   - name: Install wget with openSUSE Leap
     zypper: name={{ item }}
     with_items:
       - wget
     when: ansible_distribution == "openSUSE Leap"

   - name: Install wget with CentOS
     yum: name={{ item }}
     with_items:
       - wget
     when: ansible_distribution == "CentOS"

   - name: Install wget with Ubuntu
     apt: name={{ item }} update_cache=yes
     with_items:
       - wget
     when: ansible_distribution == "Ubuntu"

#-------------------------------------------------------  

   - name: Get consul 0.6.4 zip
     shell: wget   https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip

#-------------------------------------------------------  

   - name: Unzip consul 0.6.4 zip file
     shell: unzip consul_0.6.4_linux_amd64.zip

#-------------------------------------------------------  

   - name: Copy consul to path
     shell: cp consul /opt/consul/bin

#########################################################  
# Copy config files with user consul
- name: copy config files with user consul
 hosts: ConsulHost
 tasks:
   - name: use setup module to list os distribution
     become_user: consul
     become: yes
     template: src=templates/atlas_consul.json dest=/opt/consul/config/atlas_consul.json

# 這個部份有待討論如何在背景執行 可能要寫成服務的方式, 目前會斷
#    - name: running consul at backgroud
#      become_user: consul
#      become: yes
#      shell: nohup /opt/consul/bin/consul agent -config-dir /opt/consul/config &


檔案 templates/atlas_consul.json

{% for host in groups['ConsulHost'] %}
{
 "bind_addr": "{{ hostvars[host].ansible_default_ipv4.address }}",
 "atlas_infrastructure": "請填入帳號/請填入名稱",
 "atlas_join": true,
 "atlas_token": "請填入自己的token",
 "bootstrap_expect": 3,
 "datacenter": "Hsinchu-NCHC",
 "data_dir": "/opt/consul/data",
 "log_level": "INFO",
 "node_name": "{{ hostvars[host].ansible_hostname }}",
 "encrypt": "請填入加密的資訊",
 "server": true
}
{% endfor %}


星期三, 5月 11, 2016

VMware Workstation on linux khugepage 佔用CPU 小記

最近在 VMware workstation 12 Pro 都有執行 VM 系統反應非常慢的現象

VMware: Workstation Pro 12.1.1 build-3770994
Host OS: openSUSE Leap 42.1

看了一下 top 的輸出, 當初有懷疑是不是 SSD 的關係
後來將 VM 移動到 SAS 硬碟還是有一樣的狀況, 所以再找其他的解決方式.
中間升級過一次 VMware workstation, 但是還是沒有解決.

目前找到一個暫時的解決方式

發生 khugepage 吃 100% cpu 的情況
觀察
# cat    /sys/kernel/mm/transparent_hugepage/enabled
[always]  madvise never

以及
# cat    /sys/kernel/mm/transparent_hugepage/defrag
[always]  madvise never

看國外的作法就是, 將 transparent 停用

# echo never  >  /sys/kernel/mm/transparent_hugepage/enabled

# echo never  >  /sys/kernel/mm/transparent_hugepage/defrag

# cat    /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

# cat   /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]

暫時可以解決佔用 CPU 問題
^^ 先記下來

參考

~ enjoy it