---
# System prepended metadata

title: IPCamera installation environment
tags: [ipcamera]

---

# IPCamera installation environment
###### tags: `ipcamera`


## Installation Environment
- GPU
    1. install nvidia-driver & cuda
        - cuda(11.2.2)
            ```script
            wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda_11.2.2_460.32.03_linux.run
            sudo sh cuda_11.2.2_460.32.03_linux.run
            ```

    2. install cuDNN 
        - cuDNN(8.1.1)
        https://developer.nvidia.com/rdp/cudnn-download
        ![](https://i.imgur.com/dvR2V38.png)
            - 解壓縮
                ```
                tar xvzf cudnn-11.2-linux-x64-v8.1.1.33.tgz
                ```
            - 將文件copy到cuda目錄：
                ```
                sudo cp cuda/include/cudnn.h /usr/local/cuda/include
                sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
                sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
                ```
            - 編輯環境變數
                ```script
                sudo vi ~/.bashrc
                ```
                ```script
                export CUDA_HOME=/usr/local/cuda-11.2
                export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH
                export PATH=${CUDA_HOME}/bin:${PATH}
                ```
            - 更新環境變數
                ```script
                source ~/.bashrc
                ```
            - 確認環境變數更改完成
                ```script
                echo $CUDA_HOME
                ```
        - check nvidia driver version
            ```script
            nvidia-smi
            ```
            ![](https://i.imgur.com/sUHcSZb.png)



- Java 
    - install openjava 1.8
        ```
        sudo apt-get install openjdk-8-jdk
        ```
- Docker
    1. install docker(20.07 above)
        ```script
        curl https://get.docker.com | sh \
         && sudo systemctl --now enable docker
        ```
    2. install nvidia-docker2
        - 下載gpgkey
        ```script
        distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
           && curl -s -L     https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
           && curl -s -L     https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list |     sudo tee /etc/apt/sources.list.d/nvidia-docker.list
        ```
        - apt-get update
        ```script
        sudo apt-get update
        ```
        - install nvidia-docker2
        ```script
        sudo apt-get install -y nvidia-docker2
        ```
        - restart docker
        ```script
        sudo systemctl restart docker
        ```
        - 確認nvidia-docker2安裝成功
        ```script
        sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi
        ```
    3. install docker-compose
        ```script
        sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
        ```

- 掛載硬碟
    1. 硬碟識別
        ```script
        sudo fdisk -l
        ```
    2. 格式化新硬碟
        ```script
        sudo mkfs.ext4 /dev/sdb1
        ```
    3. 掛載到指定目錄
        ```script
        sudo mount /dev/sda1 /mnt/hdd1
        ```
    4. 檢視磁碟分割槽的UUID
        ```script
        sudo blkid
        ```
    5. 設定重開機後，自動掛載
        ```script
        sudo vi /etc/fstab 
        ```
        ![](https://i.imgur.com/sIWeD3o.png)
        - 編輯自動掛載檔案
        ```script
        sudo vi /etc/fstab
        ```
        - 加入/dev/sda1 到自動掛載檔案
        ```script
        UUID="d1ed1ad7-b601-4ac9-b657-43f3188cc281"
        ```
        ![](https://i.imgur.com/5KDkq1E.png)

## Deploy Project(from 10.142.3.61 to 10.142.3.62-64)
    
1. Python Project(Inference Model)
    ```
    cd /mnt/hdd/IP_Camera_Installation
    scp -r ipcamera-env/ elf@10.142.3.62:/mnt/hdd/IP_Camera_Installation
    scp -r EfficientDet/ elf@10.142.3.62:/mnt/hdd/IP_Camera_Installation
    source /mnt/hdd/IP_Camera_Installation/ipcamera-env/bin/activate
    ```
    - install opencv套件
        ```script
        sudo apt-get install libopencv-highgui-dev
        ```
    - install ocr套件
        ```script
        sudo apt-get install -y tesseract-ocr
        ```
        - 搬移ocr model
        ```script
        sudo chmod 777 /usr/share/tesseract-ocr/4.00 
        sudo scp -r /usr/share/tesseract-ocr/4.00/tessdata elf@10.142.3.62:/usr/share/tesseract-ocr/4.00/
        ```
    
2. API Project
    ```
    scp elf@10.142.3.60:/mnt/hdd/IP_Camera_API/ipcamera-0.0.1-SNAPSHOT.jar
    java -jar ipcamera-0.0.1-SNAPSHOT.jar
    ```
    - Setting service
        1. emi
        2. hikvision
 https://hackmd.io/OKrGHsmxQButjf4vuB8xag
    - Deployment folder: /mnt/hdd/IP_Camera_API
    - Logs: /mnt/hdd/IP_Camera_API/logs
    

4. MySQL
    ```script
    curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.17-1_all.deb
    sudo dpkg -i mysql-apt-config*
    sudo apt-get update
    sudo apt-get install mysql-server
    ```
    - 確認服務正常
        ```script
        service mysql status
        ```
    
    - 允許遠端連線設定
        - 建立使用者(root)
        ```script
        CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
        ```
        - 給予權限(root擁有最大權限)
        ```script
        GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
        ```

5. Metabase
    ```
        docker run -d -p 3000:3000 --name metabase metabase/metabase
    ```
    ```
        scp elf@10.142.3.60:/mnt/hdd/Metabase/metabase.jar
        java -jar metabase.jar
    ```


## Port listen
- 內網
    1. jupyter notebook: 7777/8888/9999
    2. api: 
        - hikvision: 8081
        - emi: 33000
    3. redis: 6379
    5. mysql: 3306
    6. metabase: 3000
- 外網
    1. git : 22、443
    2. pip install : 3128


## IPQC Account

1. 下載影片
    - 主機: sftp://10.142.3.60
    - 使用者名稱: ipqc
    - 密碼: ipqc
    - 影片路徑: /mnt/hdd/IP_Camera
    - 測試Url軟體路徑: /mnt/hdd/IP_Camera_Test_Url

2. labeling data
    - 主機: sftp://10.142.3.60
    - 使用者名稱: ipqc
    - 密碼: ipqc
    - 影片路徑: /mnt/hdd/QA_Labeling

3. 測試海康威視的品質
    - 主機: sftp://10.142.3.61
    - 使用者名稱: ipqc
    - 密碼: ipqc
    - 圖片路徑: /mnt/hdd/IP_Camera_Installation/EfficientDet/output/


## 6S

- 上傳照片
    - 網址: http://10.109.6.13:11111
    - 密碼: aa1234


## 安裝檔案
![](https://i.imgur.com/QCaDNYH.png)
