1. 程式人生 > >深度學習(四)環境配置 Ubuntu Server 16.04.1 LTS 安裝步驟 tensorflow 安裝

深度學習(四)環境配置 Ubuntu Server 16.04.1 LTS 安裝步驟 tensorflow 安裝

Ubuntu Server 16.04.1 LTS 安裝步驟 

1.下載ISO光碟映象檔案 http://www.ubuntu.com/download/server 

2.點選下載後進入http://www.ubuntu.com/download/server/install-ubuntu-server頁面,有安裝教程  https://help.ubuntu.com/lts/serverguide/index.html?_ga=1.11920567.202013523.1472813693 這裡是服務指南,可以看很多資訊

3.u盤製作安裝盤http://jingyan.baidu.com/article/d3b74d64aa4a6a1f77e60932.html 

4.網路上的安裝教程http://www.upantool.com/sense/2014/4679_4.html 參考著安裝即可,很多選項都可以選擇自動的。

   有一個重要的地方是在分割槽步驟的時候,一定要確定好選擇哪個方式,選擇好了就一步到底就行。如果中途停止了,自己又不知道怎麼分割槽,就得重來了。

5.安裝的過程中可以選擇安裝一些軟體如postgres、mysql+php、open ssh,按空格選擇,回車確定。

6.安裝完成以後是網路設定,一般伺服器時靜態ip,因此ip設定形如如下即可:

=================================第一部分======================================

以下是對其中一個埠進行設定:  修改該檔案的命令如    sudo  vi /etc/network/interfaces      

auto eth0    第0個埠

iface etho inet static    設定靜態埠

address 172.16.22.91  //ip地址

gateway 172.16.0.2 閘道器

nameservers 172.16.0.2  //在虛擬機器中嘗試數次,某次成功後是這樣設定的,因此就保留了

注意:::::eth0或者ens1這些名字是系統裡定義好的,不能隨便起,但是可以通過命令知道這些名字都有哪些:對應命令為: ifconfig -a 。 不能完成跟網路上的教程一樣命名哦!

=================================第二部分==========================================

       以下設定dns,沒有設定dns不能解析域名

      修改檔案命令如下:sudo vi  /etc/resolv.conf               參考資料:http://jingyan.baidu.com/article/4d58d54137d2a19dd5e9c050.html

        nameserver 8.8.8.8  可以最多新增三個dns伺服器,形式都是這樣的

nameserver 9.9.9.9

以上便是相關的設定。

      ========================網路設定要有很多注意點,如下==========================================

     虛擬機器中:選擇物理橋接    http://www.cnblogs.com/gylei/archive/2011/12/10/2283484.html

     伺服器機器的話:伺服器有很多網線埠,確定網線埠選擇正確,dell伺服器有個IDRAC埠,我接錯了,導致很長時間都不知道為啥上不了網

    https://help.ubuntu.com/lts/serverguide/network-configuration.html 官方指南的網路配置,這裡選擇一些比較有趣的命令出來

sudo apt install ethtool  
sudo ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: d
        Current message level: 0x000000ff (255)
        Link detected: yes
安裝上面的命令執行,就能知道對應埠的狀態::Link detected: yes 才是能夠聯通的狀態,如果為no,請檢查網線,網路配置

哦:網路重啟的命令是 

 /etc/ini.d/network   restart  或者 stop 或者 start 多來幾次,就能重啟網絡卡了,如果還不行就exit退出,再進入,可能就好了。

7.完成以上步驟,可以選擇安裝桌面了

  sudo apt-get update 更新源

   安裝桌面的方法:http://blog.csdn.net/firenet1/article/details/52421396       本人安裝的是ubuntu-desktop

 安裝完成以後組合鍵 ctrl+alt + F7即可進入桌面環境,或者重啟即可  這個組合鍵從F1-F6執行有6個視窗進行操作哦。非常有趣的

tensorflow 安裝

https://github.com/jikexueyuanwiki/tensorflow-zh/blob/master/SOURCE/get_started/os_setup.md   tensorflow的安裝教程
由於安裝完ubuntu桌面,好多東西都有了,也就不知道是不是也裝了一些tensorflow需要依賴的東西。 但是這個版本的ubuntu已經自帶了python2.7,自己嘗試裝3.4失敗了。幸好虛擬機器有一個備份,於是直接採用2.7了 在安裝前需要安裝pip,使用命令 sudo apt-get install python-pip 這樣得到的版本可能是8.1.1,如果直接用教程的命令,會不行,有以下提示 You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
因此需要神級使用命令 pip install --upgrade pip 用pip --version 就能檢視pip的版本如果8.1.2就ok, 然後執行命令:
# Ubuntu/Linux 64-bit, CPU only, Python 2.7:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
最後跑一下測試程式碼:
$ python

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>

第一個tensorflow例子:

/usr/local/lib/python2.7/dist-packages/tensorflow   這是預設的tensorflow的安裝目錄
如果不對可以用以下命令找到對應的目錄: sudo find / -name tensorflow  ======也有可能必須使用root許可權才行。用 su root 進入root賬戶 然後安裝安裝教程走即可

訓練你的第一個 TensorFlow 神經網路模型

從原始碼樹的根路徑執行:

$ cd tensorflow/models/image/mnist
$ python convolutional.py
Succesfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Succesfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Succesfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Succesfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
Initialized!
Epoch 0.00
Minibatch loss: 12.054, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
Epoch 0.12
Minibatch loss: 3.285, learning rate: 0.010000
Minibatch error: 6.2%
Validation error: 7.0%
...
...

===補充linux讓使用者有權使用sudo su root 啟動root 賬號

http://bbs.csdn.net/topics/370199343 visudo按鍵操作
http://www.cnblogs.com/howDo/archive/2013/04/07/sudo-su.html  加入許可權
首先使用root賬號,使用visudo /etc/sudoers編輯

/etc/sudoers檔案:

使用visodu命令後,開啟的視窗與vi介面一致,如果想要為賬號增加使用sudo命令的話,可以在 root ALL=(ALL) ALL這行後面加上如下內容:

# 使用者賬號 登入的主機 = (可以變換的身份) 可以執行的命令
username ALL=(ALL) ALL

剛才介紹的是使用者身份的宣告,下面還有一個特殊的使用者組說明——wheel有如下內容:

## Allows people in group wheel to run all commands
 %wheel ALL=(ALL)       ALL     

## Same thing without a password
## 使用者在使用sudo命令時不用輸入密碼,後面的ALL可以換為具體的shell命令
# %wheel        ALL=(ALL)       NOPASSWD: ALL 選擇以上一種方式修改檔案、在檔案的最後面 使用control+O寫入 使用control+X退出