2015年5月6日 星期三

ubuntu mongoDB 3.0 install

  1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  2. echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
  3. sudo apt-get update
  4. 安裝特定版本mongoDB

    sudo apt-get install -y mongodb-org=3.0.2 mongodb-org-server=3.0.2 mongodb-org-shell=3.0.2 mongodb-org-mongos=3.0.2 mongodb-org-tools=3.0.2
  5. 防止mongodb被 apt-get 升級。

    echo "mongodb-org hold" | sudo dpkg --set-selections
    echo "mongodb-org-server hold" | sudo dpkg --set-selections
    echo "mongodb-org-shell hold" | sudo dpkg --set-selections
    echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
    echo "mongodb-org-tools hold" | sudo dpkg --set-selections

  6. edit mongodb config

    sudo vim /etc/mongod.conf

    #這行是控管mongodb可以來訪的 IP,如果在aws上因為控管可由aws設定,所以可以註解掉,或是也可以用逗號區隔加入允許的ip,例如如 127.0.0.1,10.0.122.10
    bind_ip = 127.0.0.1

  7.  start mongo

    sudo mongod --fork --config /etc/mongod.conf
    # --fork 背景執行  --config 載入設定檔
  8. 進入mongo shell
    mongo

  9. 離開 mongo shell
    exit
  10. 查看mongodb 運行

    ps aux | grep mongo
  11. stop mongo
    進入mongodb shell

    a. mongo
    b. use admin
    c. db.shutdownServer()
    d. exit
參考:
  • http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

VirtualBox NAT + Host-only (Ubuntu)

virtualBox

設定 ->  網路 ->
  • 界面卡1 選 NAT
  • 界面卡2 選 僅限主機界面卡
兩界面卡用預設值即可


linux 中
  • sudo vim /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.56.1
netmask 255.255.255.0
#network 192.168.56.0
#broadcast 192.168.56.255
gateway 192.168.56.254
#dns-search cloudspace.local
#dns-nameservers 8.8.8.8 8.8.4.4
 
or 
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp
 
 
ps. 在virtualBox linux 中可利用 route查詢 default Gateway 來填入 
 
  • sudo /etc/init.d/networking restart 
 
資料來源:
  • http://askubuntu.com/questions/446183/how-to-set-up-nat-and-host-only-networking-with-static-ip-address-in-virtualbox 
 


Ubuntu 網卡設定DHCP


  1. sudo  vim /etc/network/interfaces
  2. iface eth0 inet static 改成 iface eth0 inetdhcp
  3. sudo /etc/init.d/networking restart
VirtualBox就重開機一下吧。
PS. 如果你有第二張網卡 





auto eth1
iface eth1 inetdhcp


PS. 如果想用固定IP
#Class C 設法
iface eth0 inet static 
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1


資料來源:
  • http://askubuntu.com/questions/446183/how-to-set-up-nat-and-host-only-networking-with-static-ip-address-in-virtualbox

2015年5月5日 星期二

Ubuntu SSH install

SSH Server目的:

  讓linux系統可以利用SSH機制被遠端操作 (使用公私鑰機制驗證)。

  備註1:以下命令已經切換至 root, 若沒有切換至root,記得在命令前面加sudo。


1. 查詢套件安裝狀況
  • dpkg -l | grep ssh
      如果只有看到 openssh-client,就是還沒安裝 SSH server。


2. 查詢 ssh 是否有在運作的指令
  • netstat -a | grep ssh
如果看到
tcp    0  0  *:ssh     *:*     LISTEN
tcp6  0  0  [::]:ssh  [::]:*   LISTEN

表示ssh有在運作


3. 關閉 ssh
  • service ssh stop
4.啟動 ssh
  • service ssh start
5.重啟 ssh
  • service ssh restart

6. 安裝 ssh
  • apt-get upudate    //更新套件清單
  • apt-get install ssh

7.用戶端SSH金鑰
  •  key會在家目錄的.ssh 
  • .ssh可看到  id_ras 、 id_ras.pub。  
  • id_ras 是私鑰,這個不可以給別人。
  • id_ras.pub 是公鑰,這是要給ssh服務的伺服器用的。
8. 上傳公鑰到目標伺服器
  • ssh-copy-id -i id_ras.pub  [登入帳號]@[位置]  // 記得 -i  不加會找錯key
      在mac中如果沒有ssh-copy-id指令,有兩種選擇:
    
         a. brew install ssh-copy-id 安裝命令
     
         b. 用scp 上傳 public key

             1. 在serve端  ~/ 建立 .ssh資料夾。
                  cd ~/
                  mkdir .ssh

             2. 在client電腦將公開金鑰上傳
                 scp id_ras.pub [登入帳號]@[位置]:/home/[帳號名稱]/.ssh/authorized_keys

9. 更改 authorized_keys 權限
  • chmod go-w ~/
  • chmod 700 ~/.ssh
  • chmod 600 ~/.ssh/authorized_keys

10.關閉帳號密碼登入
  •  sudo vim /etc/ssh/sshd_config
  • 將 PermitRootLogin without-password 改成 PermitRootLogin no
  • 取消註解 AuthorizedKeysFile      %h/.ssh/authorized_keys
  • PasswordAuthentication yes 改 PasswordAuthentication no  //關閉遠端帳號密碼登入



11.  ssh連線
  • ssh [登入帳號]@[位置



參考資料:
  • https://help.ubuntu.com/14.04/serverguide/openssh-server.html
  • https://help.ubuntu.com/community/SSH/OpenSSH/Configuring
  • https://help.ubuntu.com/community/SSH/OpenSSH/Keys
  • http://blog.crboy.net/2012/05/ssh-security-note.html

history

功能:查詢下過的命令

範例:
  • history
  • history | grep wget    //在history中過濾出所有的 wget指令

linux ps aux

功能:查詢 Linux 系統上服務是否有在運行

範例:
  • ps aux | grep tomcat
  • ps aux | grep ssh

linux locale

1. 查詢機器上已經安裝的語系
  •  locale -a
2.編輯 local文件
  • sudo vim /var/lib/locales/supported.d/local
  • 文件中加入 zh_TW.UTF-8 UTF-8
  • 離開vim
3.加入語系
  • sudo locale-gen

後記:
      為什麼要設定local,因為當你 tomcat utf-8 設定都設了,程式也沒問題,html宣告也對了,DB設定也對了,但寫入db的中文不對勁,那就是最底層的linux語系缺少zh_TW.UTF-8造成的。


參考資料:
  • http://tutul.logdown.com/posts/2014/08/13/ubuntu-server-12-04-lts-change-language
  • http://www.arthurtoday.com/2009/11/ubuntu-locale.html