2019年2月23日 星期六

手動安裝 Python 相關套件及設定 cx_Oracle

下載 Python 2.7.15
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar -zxvf Python-2.7.15.tgz -C /tmp/
cd /tmp/Python-2.7.15

自定安裝路徑: /usr/local/python2.7
./configure --prefix=/usr/local/python2.7 --enable-shared --enable-optimizations
執行 # /usr/local/python2.7/bin/python -V 時,會出現下列錯誤
# /usr/local/python2.7/bin/python -V
/usr/local/python2.7/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
會發生這錯誤,主要是因為 libpython2.7.so.1.0 這支 library 沒找到,因為我們使用了自定義安裝,所以要解決這個問題很簡單,先找看看目前系統有沒有這檔案,這邊我使用 find 這個指令
# find / -name libpython2.7.so.1.0 -type f
/tmp/Python-2.7.15/libpython2.7.so.1.0
/usr/local/python2.7/lib/libpython2.7.so.1.0
接著我們確認一下  LD_LIBRARY_PATH 的相關路徑有哪些,並且把我們剛剛找到的路徑也給加進去就行了。
# echo $LD_LIBRARY_PATH
會發現是空值,再來我們就加入到自已的 ~/.bashrc or ~/.bash_profile,這邊我自已的習慣是加入到 ~/.bashrc
# echo 'export LD_LIBRARY_PATH=/usr/local/python2.7/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
# source ~/.bashrc
加入後,再次執行 /usr/local/python2.7/bin/python -V
# /usr/local/python2.7/bin/python -V
Python 2.7.15
  • 手動安裝 setuptools  pip  wheel  cx_Oracle
因為要用 Python 去連 Oracle DB,需要使用 cx_Oracle,測試一下目前的 python 有沒有這個 cx_Oracle 模組
# /usr/local/python2.7/bin/python -c "import cx_Oracle"
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named cx_Oracle
先下載這四個 Tarball 檔,請連至 PYPI 搜尋並下載
解壓縮,並請依序安裝
# unzip /tmp/setuptools-40.8.0.zip
# cd /tmp/setuptools-40.8.0
# /usr/local/python2.7/bin/python setup.py install

# tar -zxvf /tmp/pip-19.0.2.tar.gz
# cd /tmp/pip-19.0.2
# /usr/local/python2.7/bin/python setup.py install

# tar -zxvf /tmp/wheel-0.33.1.tar.gz
# cd /tmp/wheel-0.33.1
# /usr/local/python2.7/bin/python setup.py install

# tar -zxvf /tmp/cx_Oracle-7.1.1.tar.gz
# cd /tmp/cx_Oracle-7.1.1/
# /usr/local/python2.7/bin/python setup.py install
  • 設定安裝 Oracle Client
參考 cx_Oracle 7 Installation 這官方文件來做安裝
由於我的伺服器沒有對外的連線,所以只好使用 Oracle Instant Client Zip Files 的安裝方法,請至 Oracle Instant Client 去下載 Instant Client for Linux x86-64,這邊案例我是下載這個檔 instantclient-basic-linux.x64-18.3.0.0.0dbru.zip,版本為 18.3.0.0.0
  • 解壓縮,並放到指定路徑下
# cd /tmp
# unzip instantclient-basic-linux.x64-18.3.0.0.0dbru.zip
# cp -r /tmp/instantclient_18_3 /usr/local/
  • 安裝套件
# yum install libaio
  •  instantclient_18_3 加入到自已的 ~/.bashrc
# sed '/LD_LIBRARY_PATH/d' -i ~/.bashrc
# echo 'export LD_LIBRARY_PATH=/usr/local/python2.7/lib:/usr/local/instantclient_18_3:$LD_LIBRARY_PATH' >> ~/.bashrc
# source ~/.bashrc
  • 再次執行
# /usr/local/python2.7/bin/python -c "import cx_Oracle"
完成上述步驟後,執行連接 Oracle 的程式,會出現下面的錯誤
Traceback (most recent call last):
  File "/tmp/Connect_Oracle.py", line 1, in 
    con = cx_Oracle.connect('Account/OraclePassWord')
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "/lib64/libc.so.6: version `GLIBC_2.9' not found (required by /usr/local/instantclient_18_3/libipc1.so)". See https://oracle.github.io/odpi/doc/installation.html#linux for help
上面這錯誤訊息是說,找不到 Oracle Client Library /lib64/libc.so.6 找不到版本 GLIBC_2.9
請執行 strings /lib64/libc.so.6 確認版本是否有支援
# strings /lib64/libc.so.6 | grep 'GLIBC_'
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_PRIVATE
觀察上面資訊後,確認沒有 `GLIBC_2.9 的版本,那就要去下載 Tarball 來安裝了。
找到自已所需要的版本
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
確認 glibc 版本
# strings /lib64/libc.so.6 | grep 'GLIBC_'
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_PRIVATE
這裡要注意一下,要編譯前,請先執行 ls -la /lib64/libc.so.6
# ls -la /lib64/libc.so.6
lrwxrwxrwx 1 root root 11 Apr 21  2015 /lib64/libc.so.6 -> libc-2.5.so
先前不知道,就直接編輯下去了,結果重新要做軟連結時,會導致無法連進去伺服器,也不能執行任何指令,千萬不要重開機,如果真的不小心,執行指令有問題時,沒關係,請執行下面這個執行就可以了
# LD_PRELOAD=/lib64/libc-2.5.so ls
這樣就可以了,最後提醒一下,從這裡開始就要小心了~~~!!!!
先解壓縮
# cd /tmp/
# tar -zxvf /tmp/glibc-2.9.tar.gz
# cd glibc-2.9
# ./configure  --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
configure: error: you must configure in a separate build directory
這裡會出錯,請先在當前目錄中,建立一個 build 的目錄
# mkdir -p /tmp/glibc-2.9/build
# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
...(省略)
checking LD_LIBRARY_PATH variable... contains current directory
configure: error:
*** LD_LIBRARY_PATH shouldn't contain the current directory when
*** building glibc. Please change the environment variable
*** and run configure again.
這邊又出一個錯誤,解法很簡單,執行 unset LD_LIBRARY_PATH,解法我是參考這篇 编译glibc(gcc)以及过程中遇到的一些错误
# unset LD_LIBRARY_PATH
再次編譯
# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
# make
# make install
# ls -la /lib64/libc.so.6
lrwxrwxrwx 1 root root 11 Feb 23 15:52 /lib64/libc.so.6 -> libc-2.9.so
再次檢查 glibc 版本
# strings  /lib64/libc.so.6  | grep 'GLIBC_'
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_PRIVATE
再次執行連接 Oracle DB 的程式
# /usr/local/python2.7/bin/python /tmp/Connect_Oracle.py
/usr/local/python2.7/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
會出現這錯誤,主要是我們剛剛在編譯時,有 unset LD_LIBRARY_PATH,導致 python 無法讀取到 libpython2.7.so.1.0,所以我們只要把 export LD_LIBRARY_PATH=/usr/local/python2.7/lib:/usr/local/instantclient_18_3:$LD_LIBRARY_PATH 執行一次就行了,或是直接執行 source ~/.bashrc 即可,先前有加進去了。
以上就是踩雷的過程,完工。

2019年2月20日 星期三

SunOS 5.9 指令小記

  • 確認目前安裝資訊
# pkginfo -l SUNWsneep
請找 NAME 這個關鍵字,此時你會看到 NAME: Serial Number in EEPROM
再執行 eeprom,請找 nvramrc 關鍵字,就有可能可以找到機器序號,若是看不到序號就請試下面底下的執令。
  • 報修用的 report 指令
# /opt/SUNWexplo/bin/explorer
產生出來的 report 會放在 /opt/SUNWexplo/output/
  • 查詢主機序號
1. /opt/SUNWsneep/bin/sneep or sneep -T
2. /opt/SUNWsneep/bin/showplatform or showplatform
3. hostid
  • 修改主機序號
# sneep -t "ChassisSerialNumber" -s serial_number

2019年2月14日 星期四

設定 SSH Key 給多個 Github 帳號

  • 先在自已的本機電腦產生 SSH Key
先建立第一個 github 帳號的 ssh key
# ssh-keygen -t rsa -b 4096 -f github_account_1
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (若是沒有要使用密碼,直接按Enter即可)
Enter same passphrase again: (若是沒有要使用密碼,直接按Enter即可)
Your identification has been saved in github_account_1.
Your public key has been saved in github_account_1.pub.
The key fingerprint is:
SHA256:lqJlY/txd9Ad8gka8GRk9/bJi8sKaASrxhKx5wONHBQ Nobody@Ubuntu.local
The key's randomart image is:
+---[RSA 4096]----+
|       o*.+ o .  |
Host github_account_1.github.com
|       o o + = o |
|    E     . = +  |
|    ..   . o + . |
|    .o* S   . =  |
|   .+= * o . o . |
|   ooo. * . . .  |

|   .++oo = . .   |
|   .++o.o ..o    |
+----[SHA256]-----+
再建立第二個 github 帳號的 ssh key
# ssh-keygen -t rsa -b 4096 -f github_account_2
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (若是沒有要使用密碼,直接按Enter即可)
Enter same passphrase again: (若是沒有要使用密碼,直接按Enter即可)
Your identification has been saved in github_account_2.
Your public key has been saved in github_account_2.pub.
The key fingerprint is:
SHA256:lqJlY/zkd9Ad89ka7GRk9/bJi8sKaASrxhKx5wOPWDBS Nobody@Ubuntu.local
The key's randomart image is:
+---[RSA 4096]----+
|       o*.+ o .  |
Host github_account_2.github.com
|       o o + = o |
|    E     . = +  |
|    ..   . o + . |
|    .o* S   . =  |
|   .+= * o . o . |
|   ooo. * . . .  |

|   .++oo = . .   |
|   .++o.o ..o    |
+----[SHA256]-----+
  • 請將自已的 SSH Public Key 分別上傳到自已不同 Github 帳號
  1. 請登入自已的 Github 後,請點選瀏覽器右上角會有一個自已的 Avatar,會出現一個下拉式的選單
  2. 點選『 Settings 』
  3. 點選『 SSH and GPG Keys 』 
  4. 點選『 New SSH Key 』,會出現一個畫面,分別有二個地方要填寫,一個是叫  Title & Key 
    • Title 的部份,我都習慣輸入自已自定的檔名,
    • Key 的部分,則是請把自已的 SSH Public Key 給貼上來即可
  5. 點選 『 Add SSH Key 』,這樣就算設定完成了
  • 設定 SSH Config 連結自已的 Github
請到 ~/.ssh 目錄下,建立檔案叫 『 config 』,並直接編輯它
Host github_account_1.github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_account_1
  IdentitiesOnly yes

Host github_account_2.github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_account_2
  IdentitiesOnly yes
將上面設定完成後,請記得存檔後離開,這邊就完成設定。
  • Clone 自已的 Github Project
  1. 請到自已的 Github Project 的頁面後
  2. 點選『 clone or download 』 會出現一個小小畫面
  3. 點選小小畫面的右上角的『 Use SSH 』
  4. 再點選小小畫面中 URL 旁的『 複製鈕 』,即可將自已的連結給複製起來了
  5. 再回到 Terminal 上,輸入 git clone git@github_account_1.github.com:nobody/ProjectName.git ,這樣就完成下載了
  • 設定 Github Upstream
請先到自已的專案底下,執行 git remote -v
# git remote -v
origin  git@github_account_1.github.com:nobody/ProjectName.git (fetch)
origin  git@github_account_1.github.com:nobody/ProjectName.git (push)
由於之前有先 git clone 下來自已的專案的 repository,預設就會是用 origin,因為我專案是從別人的專案 fork 過來的,所以我們為了要跟原本 fork 過來的專案要同步,必須要在自已目前的專案下,建立 upstream
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
接著我們再執行一次 git remote -v
# git remote -v
origin  git@github_account_1.github.com:nobody/ProjectName.git (fetch)
origin  git@github_account_1.github.com:nobody/ProjectName.git (push)
upstream    https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream    https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
  • 同步 Fork 回來的專案
    1. 將 upstream 抓下來
      # git fetch upstream
      remote: Counting objects: 75, done.
      remote: Compressing objects: 100% (53/53), done.
      remote: Total 62 (delta 27), reused 44 (delta 9)
      Unpacking objects: 100% (62/62), done.
      From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
      * [new branch]      master     -> upstream/master
    2. 切換到 master branch
      # git checkout master
      Switched to branch 'master'
    3.  upstream/master 上有改變的檔案,通通都 Merge 回到自已的 local master branch
      # git merge upstream/master
      Updating a422352..5fdff0f
      Fast-forward
      README                    |    9 -------
      README.md                 |    7 ++++++
      2 files changed, 7 insertions(+), 9 deletions(-)
      delete mode 100644 README
      create mode 100644 README.md
    4. 同步完成後,還需要把剛更新的資料,推回去到自已的 Github
      # git push
      Enumerating objects: 1, done.
      Counting objects: 100% (1/1), done.
      Writing objects: 100% (1/1), 657 bytes | 657.00 KiB/s, done.
      Total 1 (delta 0), reused 0 (delta 0)
      To git@github_account_1.github.com:nobody/ProjectName.git
      76c826c..89f8a8a  master -> master
Reference: