2016年8月18日 星期四

ubuntu 14.04 TLS install VNC server with gnome desketop (遠端桌面)

ubuntu 14.04 TLS   install  VNC server  with gnome desketop (遠端桌面)

1.安裝 gnome 相關套件

# sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal # apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal vnc4server 

2.啟動一次 再家目錄建立預設資料夾

user@ubuntu:~$ vncserver

You will require a password to access your desktops.

Password:
Verify:
xauth:  file /home/user/.Xauthority does not exist

New 'ubuntu:1 (user)' desktop is ubuntu:1

Creating default startup script /home/user/.vnc/xstartup
Starting applications specified in /home/user/.vnc/xstartup
Log file is /home/user/.vnc/ubuntu:1.log


3.編輯 /home/user/.vnc/xstartup 檔套用以下設定

#!/bin/sh

export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

4.再次啟動
user@ubuntu:~$ vncserver -kill :1
Killing Xvnc4 process ID 45058
user@ubuntu:~$ vncserver 

New 'ubuntu:1 (user)' desktop is ubuntu:1

Starting applications specified in /home/user/.vnc/xstartup
Log file is /home/user/.vnc/ubuntu:1.log


5.在別台機器啟動 Remmina 遠端桌面客戶端




6.新增並輸入 IP:Port 帳號 密碼




7.連線成功!!



參考來源:http://askubuntu.com/questions/475023/how-to-make-vnc-server-work-with-ubuntu-desktop-without-xfce

參考:https://docs.microsoft.com/zh-tw/azure/virtual-machines/linux/classic/remote-desktop


https://www.digitalocean.com/community/tutorials/how-to-set-up-vnc-server-on-debian-8

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-14-04


/etc/vnc.conf

vi /etc/alternatives/vncserver  -localhost



在localhost 監聽

vncserver  -localhost

ssh forward
ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address

移除ssh forward
If you are using Linux you can kill the process by:
ps aux | grep ssh
and then use
kill <id>
To kill the process.
If the kill command is not successfull you can try
kill -9 <id>

來源:https://superuser.com/questions/87014/how-do-i-remove-an-ssh-forwarded-port


移除 監聽

 vncserver -kill :2

2016年7月19日 星期二

scala compiler -classpath with multiple JAR files

scala compiler  -classpath  with  multiple JAR files


1. To compile a scala file and include a Jar file, enter the following command line:

scala  -classpath  /home/user/jarFile.jar   scalaFile.scala


2. To compile a scala file and include multiple Jar file, enter the following command line:

In Linux OS:
scala  -classpath  "/absolute/path/jarFile1.jar:/absolute/path/jarFile2.jar"   scalaFile.scala

In Winsows OS:
scala  -classpath  "C:\absolute/path/jarFile1.jar;C:/absolute/path/jarFile2.jar"   scalaFile.scala






scala 多個jar包編譯 

1.scala 編譯時僅有引用一個jar包:

scala  -classpath  /home/user/jarFile.jar   scalaFile.scala

2. scala 編譯時僅有引用一個jar包:
在Windows底下是分號要注意,Linux則是冒號,也要注意分號跟冒號分隔前後不可以有空白,也要使用絕對路徑,例如:~/xxx/yyy/filejar.jar 是不可以的。

In Linux OS:
scala  -classpath  "/absolute/path/jarFile1.jar:/absolute/path/jarFile2.jar"   scalaFile.scala

In Winsows OS:
scala  -classpath  "C:\absolute/path/jarFile1.jar;C:/absolute/path/jarFile2.jar"   scalaFile.scala

2016年6月4日 星期六

Scala 錯誤: java.nio.charset.MalformedInputException: Input length = 1

Scala ERROR  java.nio.charset.MalformedInputException: Input length = 1



import scala.io.Source

object Test{
def main(args: Array[String] ){
val filename = "test.txt"
Source.fromFile("test.txt", "UTF-8").foreach{ 
               print 
               }
}
}


在執行上段程式碼的時候,遇到了 java.nio.charset.MalformedInputException: Input length = 1 的錯誤,官方解釋這個錯誤為:

MalformedInputException thrown when an input byte sequence is not legal for given charset, or an input character sequence is not a legal sixteen-bit Unicode sequence.


代表輸入時遇到不合法的字元,所以只要把輸入的字元編碼就可以了。
fromFile 方法有提供編碼的參數:

fromFile (name : java.lang.String, enc : java.lang.String) : Source
creates Source from file with given name, using given encoding, setting its description to filename.

所以改成:

object Test{
def main(args: Array[String] ){
val filename = "test.txt"
Source.fromFile("test.txt", "UTF-8").foreach{ 
               print 
             }
}
}


2016年5月31日 星期二

Scala 學習筆記:function literal

Scala 學習筆記:function literal 


   function literal直接拿去翻譯通常會翻做"功能字面",這個翻譯真的讓人無法理解,所以爬了許多文章後,function literal應該翻做這個"方法的名稱"。
例子1:
scala>  (a:Int, b:Int) => a + b

 這個function literal 就是  anonymous。也就是這個方法的名稱就是匿名方法。

例子2:

scala>  var factor = 3
scala>  val multiplier = (i:Int) => i * factor

這個function literal 就是 Closures。也就是這個方法的名稱就是閉包方法。這邊的閉包只是我看到最常見的講法,不是官方確定說法。

參考:
http://stackoverflow.com/questions/12615091/why-is-the-following-scala-function-called-a-closure
http://www.tutorialspoint.com/scala/scala_closures.htm

2016年4月29日 星期五

RDMA 範例程式

RDMA 範例程式 


此程式是由 Writing RDMA applications on Linux Example programs  Roland Dreier 這位工程師撰寫的,但是由2007年撰寫的所以在複製程式碼有許多的問題,內部也有一點小bug應該是不小心打錯的,花了一下下午的時間將他補足跟測式執行,為一個由C撰寫兩個數字相加並使用RDMA 傳送的小範例程式。

順便一提,這裡的cc在linux 中就是gcc的意思,可以檢查一下/usr/bin底下的link就可以了。

user @ /usr/bin $ ls -l /usr/bin/cc

lrwxrwxrwx. 1 root root 3 2015-12-08 04:46 /usr/bin/cc -> gcc


編譯前請確認是否有安裝 rdma 跟libibverbs 兩個類別庫,也請確認你的server網卡有支援RDMA。

編譯

client :

$ cc -o client client.c -lrdmacm -libverbs

server :

$ cc -o server server.c -lrdmacm 


執行
server :

$ ./server

client : (格式為  client <servername> <val1> <val2>)

$./client  192.168.1.2  123 567 

123 + 567 = 690



程式碼:

https://github.com/linzion/RDMA-example-application


參考:
http://www.digitalvampire.org/rdma-tutorial-2007/notes.pdf



ibv_wc defined in <infiniband/verbs.h>.
struct ibv_wc {
        uint64_t                wr_id;          /* ID of the completed Work Request (WR) */
        enum ibv_wc_status      status;         /* Status of the operation */
        enum ibv_wc_opcode      opcode;         /* Operation type specified in the completed WR */
        uint32_t                vendor_err;     /* Vendor error syndrome */
        uint32_t                byte_len;       /* Number of bytes transferred */
        uint32_t                imm_data;       /* Immediate data (in network byte order) */
        uint32_t                qp_num;         /* Local QP number of completed WR */
        uint32_t                src_qp;         /* Source QP number (remote QP number) of completed WR (valid only for UD QPs) */
        int                     wc_flags;       /* Flags of the completed WR */
        uint16_t                pkey_index;     /* P_Key index (valid only for GSI QPs) */
        uint16_t                slid;           /* Source LID */
        uint8_t                 sl;             /* Service Level */
        uint8_t                 dlid_path_bits; /* DLID path bits (not applicable for multicast messages) */
};

c compiler error : 程式中有游離的 「 」

c compiler error :  程式中有游離的 「    」


錯誤:程式中有游離的 「\342」
錯誤:程式中有游離的 「\210」
錯誤:程式中有游離的 「\222」

c compiler 時有時會出現這種錯誤,原因是因為程式碼中含有 全形符號  並非只有特殊的符號爾以,以上例來說是 「-」這個全形dash ,只要換成半形就可以了。

檢查出現在哪裡的方法是:

od -c code.c > log.txt

對照一下就很容易發現是什麼全形符號 在作怪了。


參考:
http://blog.csdn.net/sdustliyang/article/details/6851464

2016年4月27日 星期三

Linux Nvidia Driver Install

Linux Nvidia Driver Install

在安裝前請確定電腦是否是有獨立顯卡,或者你的電腦是擁有內顯與雙顯卡的筆電,這邊的安裝僅適用於電腦僅有一張獨立顯卡電腦使用,否則會遇到安裝完重登入後會黑畫面也無法進入桌面,但是可以切到其他tty的情況,非單張獨立顯卡請參考此。


1.先去官方網站選擇屬於你的顯卡型號,下載run檔。

     wget http://......                      

2.安裝.run 檔前要先關掉X server,依照不同桌面環境去關掉對應的服務。

  • GNOME:  (Cent OS 通常是這個與 ubuntu 舊版 )
          sudo service  gdm stop   
  • KDE :
          sudo service  kdm stop    
  • UNITY:  (Ubuntu 14.04 以後 )
          sudo service  lightdm stop
  • 特殊 :  (重開使用 sudo start prefdm)
         sudo stop prefdm              

3.執行.run 檔,按照步驟即可。

     sudo  sh  NVIDIA-Linux-x86_64-XXX.XX.run