Ubuntu 16.04版本,顯卡:GeForce GTX 1070
1.系統安裝
- 參考:https://blog.csdn.net/gent__chen/article/details/48713991
- 硬盤500G分區方案:
根目錄:102400MB
交換空間:10240MB
/boot:10240MB(boot文件用于存放系統引導文件和內核,Linux內核更新后,可釋放磁盤空間)
/home: 389120MB
2.顯卡驅動
- 一種方法是通過ppa源安裝,但這種方法對我來說不管用,我使用了高版本和低版本驅動都不行??。
- 使用run方式安裝,成功,僅限跟我同版本的服務器。
(1)從NVIDIA官網下載驅動
手動搜索.png
這里我選擇了NVIDIA-Linux-x86_64-410.78.run
下載,可以嘗試更高版本。
(2)終端卸載已經存在的驅動
sudo apt-get purge nvidia*
這種方法卸載不了,可以使用一下語句卸載
sudo service lightdm stop
sh ./NVIDIA-Linux-x86_64-410.78.run --uninstall
sudo service lightdm start
參考:https://blog.csdn.net/WILLIAMMMS/article/details/80791756
(3)禁用第三方開源的驅動程序nouveau
打開
sudo gedit /etc/modprobe.d/blacklist.conf
在文件末端加入
blacklist nouveau
options nouveau modeset=0
更新系統,使禁用 nouveau 真正生效
sudo update-initramfs -u
最后重啟系統。
重啟系統后,在終端輸入命令lsmod | grep nouveau
查看是否被禁用(輸入命令后,沒有打印任何信息,即禁用成功)。
(4)關閉桌面服務
圖形化界面按住ctrl+alt+(F1~F6的其中一個)進入命令行模式輸入用戶名和密碼,然后在輸入sudo service lightdm stop
。
(5)安裝驅動run文件
賦予執行權限sudo chmod a+x NVIDIA-Linux-x86_64-410.78.run
安裝sudo ./NVIDIA-Linux-x86_64-410.78.run
安裝最好使用 sudo ./NVIDIA-Linux-x86_64-410.78.run -no-x-check -no-nouveau-check -no-opengl-files
(避免循環登錄)
在安裝過程中,出現的問題,參考:https://blog.csdn.net/lihe4151021/article/details/90083431。
(6)重啟后,nvidia-smi
命令檢查是否安裝成功,出現下圖,證明驅動安裝成功。
3.安裝cuda和cudnn(官網需注冊賬號)
參考教程:https://blog.csdn.net/j879159541/article/details/93590342
cuda就是下載的教程中的10.0版本,下載地址https://developer.nvidia.com/cuda-toolkit-archive
-
進入官方下載界面,選擇:
cuda - 安裝cuda_10.0.130_410.48_linux.run
sudo sh cuda_10.0.130_410.48_linux.run
安裝過程中出現下列選項:
- 剩余安裝步驟參考教程
- 最后需要重啟后,再輸入
nvcc -V
和nvcc --version
出現下列界面,安裝成功
安裝成功
對應cudnn下載的7.4.2版本,下載地址:https://developer.nvidia.com/rdp/cudnn-archive
4.更換清華鏡像源
- 首先備份原配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
-將sources.list中內容注釋掉,換成清華鏡像源
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
- 更新
sudo apt-get update
5.安裝anaconda3
- 教程:https://blog.csdn.net/huangjuegeek/article/details/73556763
- 在安裝anaconda3之后,默認鏡像還是國外的官方進行,這里換成國內鏡像速度會快很多。鏡像地址和命令:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
- 在jupyter notebook中添加conda環境 https://blog.csdn.net/qq_29936933/article/details/83089198
6.安裝搜狗輸入法
sudo apt-get upgrade 這個指令千萬別亂用啊,都是淚??
參考:
https://zhuanlan.zhihu.com/p/57868480
http://www.lxweimin.com/p/cafe12618293
https://blog.csdn.net/areigninhell/article/details/79696751
7. 安裝teamviewer
- 官方下載網址(https://www.teamviewer.cn/cn/download/linux/),找到相應版本下載,要下載最新版,不然之后總會讓你更新。
- 32位系統需要添加依賴包(64位不用添加)
sudo apt-get install libjpeg62:i386 libxinerama1:i386 libxrandr2:i386 libxtst6:i386 ca-certificates
- 安裝deb軟件包
sudo dpkg -i teamviewer_amd64.deb
安裝過程中出現下圖所示錯誤,缺少依賴關系。執行下面命令修復
sudo apt-get install -f
再執行sudo dpkg -i teamviewer_amd64.deb
,顯示如下即安裝成功。
- 停止teamviewer
sudo teamviewer --daemon stop
- 修改配置文件
vim /opt/teamviewer/config/global.conf
在配置文件末尾添加:
[int32] EulaAccepted = 1
[int32] EulaAcceptedRevision = 6
保存退出(wq)后,cat global.conf
查看是否修改成功。
- 啟動teamviewer
sudo teamviewer --daemon start
- 獲取Teamviewer ID
teamviewer --info print id
- 設置teamviewer 密碼
sudo teamviewer --passwd [PASSWORD]
8.安裝有道詞典
參考教程:https://www.cnblogs.com/TooyLee/p/7750002.html
Ubuntu18.04版本,顯卡:GeForce GTX 1080Ti
1. 安裝VNC遠程桌面
在學校局域網內,使用VNC速度快,使用流暢,但只能在同一局域網內使用。
對于Ubuntu18.04的安裝過程如下:
- 安裝xfce4遠程桌面
sudo apt-get install xfce4
- 安裝VNCServer
sudo apt-get install vnc4server
- 安裝成功后,設置登錄密碼
vncpasswd
- 運行vncserver,系統默認創建了VNC的xstartup配置文件
vncserver
- 通過
ps -ef | grep vnc
查看已用端口(剛剛開啟的端口),并殺死
vncserver -kill :2
- 修改~/.vnc/xstartup配置文件
vim ~/.vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
- 重新啟動
vncserver
- 修改分辨率(先要殺死相應端口
vncserver -kill :5
)
vncserver -geometry 1920x1080 :5
為避免重啟后失效,可以修改配置文件vi /usr/bin/vncserver
$geometry = "1920x1080"; #可以修改分辨率
$depth = 16;
2、雙網卡不能聯網問題
- 查看已有以太網端口
ifconfig
- 確定連接外網的端口,我的是eno1,執行
sudo dhclient eno1
出現RTNETLINK answers: File exist
- 更新
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install vim
- 在
sudo vim /etc/network/interfaces
中添加:
auto lo
iface lo inet loopback
- 接下來執行
sudo ifdown eno1 && sudo ifup eno1
最后用ifconfig
檢查新的網址是否工作。
Ubuntu 16.04版本,顯卡:Tesla k40c
1. 顯卡驅動
Tesla k40c 需要在NVIDIA官網下載驅動,網址:https://www.nvidia.cn/Download/index.aspx?lang=cn。下載具體信息:
這里下載了NVIDIA-Linux-x86_64-440.33.01.run,440的顯卡自帶CUDA,不需要再重新安裝。
裝機小tips
1. 裝機時輸入法設置成中文,改成英文。
Ctrl+Alt+T 進入終端
cd /etc/default
sudo vim locale
將
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
改為
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
- reboot
2. 本地打開服務器端Tensorboard
- 首先在服務器端
tensorboard --logdir=logs
一下,查看端口號(一般為6006
)。 - 本地終端輸入
ssh -L 16006:127.0.0.1:6006 user@XXX.XXX.XX.XX
即將遠程服務器端的6006端口轉發到本地的16006端口,在本地對16006端口的訪問即是對遠程6006端口的訪問。之后輸入
tensorboard --logdir=logs
- 本地訪問地址
http://127.0.0.1:16006/
3.使用阿里云(外網)服務器配置反向端口轉發
機器 | IP | 用戶名 |
---|---|---|
A(外網阿里云服務器) | remote-host | zhr |
B(內網實驗室服務器) | inner-host | ouc02 |
(1)ssh 參數
-f 后臺執行ssh指令
-C 允許壓縮數據
-N 不執行遠程指令
-R 將遠程主機(服務器)的某個端口轉發到本地端指定機器的指定端口
-L 將本地機(客戶機)的某個端口轉發到遠端指定機器的指定端口
-p 指定遠程主機的端口
反向代理ssh -fCNR
正向代理ssh -fCNL
(2)配置步驟
- 在阿里云端開啟幾個端口,這里綁定了7280,7281,7282三個。
- 在B上建立內網到外網的反向代理
在B(內網實驗室服務器)上輸入ssh -fCNR 7280:localhost:22 zhr@remote-host
,其中7280是阿里云服務器綁定端口號,22是實驗室服務器固定端口號。
在B上輸入ps aux | grep ssh
查看是否啟動。
在A阿里云端輸入netstat -tln
或者netstat -anltp |grep 7280
查看反向代理連接是否成功。
ouc02@ouc02-X10SRA:~$ ssh -fCNR 7280:localhost:22 zhr@remote-host
ouc02@ouc02-X10SRA:~$ ps aux | grep ssh
root 1206 0.0 0.0 65512 6184 ? Ss Mar27 0:00 /usr/sbin/sshd -D
root 10484 0.0 0.0 94928 6884 ? Ss 20:42 0:00 sshd: ouc02 [priv]
ouc02 10551 0.0 0.0 94928 3384 ? S 20:42 0:00 sshd: ouc02@pts/20
root 11169 0.0 0.0 95016 7124 ? Ss 20:58 0:00 sshd: ouc02 [priv]
ouc02 11263 0.0 0.0 95016 3324 ? S 20:58 0:00 sshd: ouc02@pts/27
root 11770 0.0 0.0 95016 7044 ? Ss 21:07 0:00 sshd: ouc02 [priv]
ouc02 11795 0.0 0.0 95016 3416 ? S 21:08 0:00 sshd: ouc02@pts/26
ouc02 2137 0.0 0.0 45340 3780 ? Ss Mar27 0:06 ssh -fCNR 7280:localhost:22 zhr@remote-host
root 14272 0.0 0.0 94928 6860 ? Ss Mar28 0:00 sshd: sqw [priv]
sqw 14341 0.0 0.0 94928 3180 ? S Mar28 0:00 sshd: sqw@pts/13
root 14697 0.0 0.0 94928 6924 ? Ss Mar28 0:00 sshd: sqw [priv]
sqw 14767 0.0 0.0 94928 3188 ? S Mar28 0:00 sshd: sqw@pts/17
root 17631 0.0 0.0 94904 6848 ? Ss Mar28 0:00 sshd: sqw [priv]
sqw 17662 0.0 0.0 94904 3996 ? S Mar28 0:00 sshd: sqw@pts/22
zhr@iZ2ze37:~$ netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:7280 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
zhr@iZ2ze37:~$ netstat -anltp |grep 7280
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:7280 0.0.0.0:* LISTEN -
- 在A上建立正向代理,用來做轉發
在A(阿里云服務器)上輸入ssh -fCNL *:7281:localhost:7280 localhost
,其中7281是A負責監聽外網的端口,即外網通過7281端口訪問;7280是A用以轉發請求的端口,內網的B服務器連接到該接口并接受A的轉發數據,實現從其他機器訪問。
zhr@iZ2ze37:~$ ssh -fCNL *:7281:localhost:7280
zhr@iZ2ze37:~$ ps aux | grep ssh
root 816 0.0 0.3 59432 6188 ? Ss Mar29 0:00 /usr/sbin/sshd -D
root 1058 0.0 0.3 96032 6752 ? Ss Mar29 0:00 sshd: zhr [priv]
zhr 1077 0.1 0.2 96488 5592 ? S Mar29 1:52 sshd: zhr
root 16004 0.0 0.3 96000 6800 ? Ss Mar29 0:00 sshd: zhr [priv]
zhr 16022 0.2 0.2 97080 6000 ? S Mar29 2:57 sshd: zhr
root 17792 0.0 0.3 96032 6792 ? Ss Mar29 0:00 sshd: zhr [priv]
zhr 17794 0.0 0.1 37640 3312 ? Ss Mar29 0:02 ssh -fCNL *:7281:localhost:7280 localhost
zhr 17811 0.0 0.2 96304 5476 ? S Mar29 0:02 sshd: zhr
root 17992 0.0 0.3 96004 6896 ? Ss Mar29 0:00 sshd: zhr [priv]
zhr 18010 0.0 0.2 96556 5536 ? S Mar29 0:02 sshd: zhr
root 18775 0.0 0.3 96032 6752 ? Ss 10:23 0:00 sshd: zhr [priv]
zhr 18793 0.0 0.1 96032 3324 ? S 10:23 0:00 sshd: zhr@pts/2
root 18824 0.0 0.3 96032 6968 ? Ss 10:49 0:00 sshd: zhr [priv]
zhr 18842 0.0 0.1 96032 3416 ? S 10:49 0:00 sshd: zhr@pts/3
zhr 18865 0.0 0.0 14196 936 pts/3 S+ 10:49 0:00 grep --color=auto ssh
- 連接
配置好A和B機器,就可以從任意一部外網電腦登陸到B(內網實驗室機器)了。這里我直接從A阿里云外網服務器連接到B。
zhr@iZ2ze37:~$ ssh -p7281 ouc02@remote-host
ouc02@remote-host's password:
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.15.0-91-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
171 packages can be updated.
0 updates are security updates.
Last login: Sun Mar 29 22:15:45 2020 from 127.0.0.1
(3)免密碼登錄到B
設置免密碼登錄到內網實驗室服務器
在B上設置ssh-copy-id zhr@remote-host
(4)建立穩定隧道
上述方法并不穩定,超時就會斷開。故通過autossh建立穩定隧道,防止超時斷開。
注意: ssh認第一個輸入指令,autossh前清掉之前的ssh命令(直到連接不上),否則連接會斷。
- 在B(內網實驗室服務器)安裝autossh(已安裝的略過)
sudo apt-get -y install autossh
- B終端輸入
autossh -M 7282 -fCNR 7280:localhost:22 -o ServerAliveInterval=60 -o TCPKeepAlive=yes zhr@remote-host
ouc02@ouc02-X10SRA:~$ autossh -M 7282 -fCNR 7280:localhost:22 -o ServerAliveInterval=60 -o TCPKeepAlive=yes zhr@remote-host
ouc02@ouc02-X10SRA:~$ ps aux | grep ssh
root 1206 0.0 0.0 65512 6184 ? Ss Mar27 0:00 /usr/sbin/sshd -D
root 5894 0.0 0.0 95016 6880 ? Ss 04:13 0:00 sshd: ouc02 [priv]
ouc02 5923 0.0 0.0 95016 3432 ? S 04:13 0:00 sshd: ouc02@pts/19
ouc02 6775 0.0 0.0 4372 84 ? Ss 05:32 0:00 /usr/lib/autossh/autossh -M 7282 -CNR 7280:localhost:22 -o ServerAliveInterval=60 -o TCPKeepAlive=yes zhr@remote-host
ouc02 6776 0.0 0.0 45556 6176 ? S 05:32 0:03 /usr/bin/ssh -L 7282:127.0.0.1:7282 -R 7282:127.0.0.1:7283 -CNR 7280:localhost:22 -o ServerAliveInterval=60 -o TCPKeepAlive=yes zhr@remote-host
root 8252 0.0 0.0 94928 6756 ? Ss 09:51 0:00 sshd: ouc02 [priv]
ouc02 8277 0.0 0.0 94928 3252 ? S 09:51 0:00 sshd: ouc02@pts/23
root 8684 0.0 0.0 94928 6816 ? Ss 09:56 0:00 sshd: ouc02 [priv]
ouc02 8709 0.0 0.0 94928 3388 ? S 09:56 0:00 sshd: ouc02@pts/24
root 8882 0.0 0.0 94928 6904 ? Ss 10:05 0:00 sshd: ouc02 [priv]
ouc02 8907 0.0 0.0 94928 3292 ? S 10:05 0:00 sshd: ouc02@pts/25
ouc02 11795 0.0 0.0 95016 3416 ? S 21:08 0:00 sshd: ouc02@pts/28
root 11971 0.0 0.0 94928 6892 ? Ss 21:22 0:00 sshd: ouc02 [priv]
ouc02 14054 0.0 0.0 94928 3312 ? S 23:31 0:00 sshd: ouc02@pts/34
root 14098 0.0 0.0 94928 6744 ? Ss 23:33 0:00 sshd: ouc02 [priv]
ouc02 14123 0.0 0.0 94928 3392 ? S 23:34 0:00 sshd: ouc02@pts/35
ouc02 14171 0.0 0.0 21264 968 pts/35 S+ 23:34 0:00 grep --color=auto ssh
(5)配置開機自啟
以下寫入 /etc/rc.local 的 exit 0 之前
su - lab-user -c autossh -M 7281 -fCNR 7280:localhost:22 -o ServerAliveInterval=60 -o TCPKeepAlive=yes zhr@remote-host
賦予可執行權限
sudo chmod +x /etc/rc.local
參考:http://www.lxweimin.com/p/abeb63711e37
http://www.fanyingjie.com/cn/2019/11/ssh_proxy/