首頁>技術>

接下來開始體驗吧;

環境準備本次實戰,需要您準備一臺Linux電腦,物理機、虛擬機器都可以,Ubuntu或者CentOS都可以,版本沒有特殊要求,我這裡用的是CentOS-7.9;本文所有操作用的都是root賬號;接下來是環境準備的幾步操作;關閉防火牆並禁止開機啟動:
systemctl stop firewalld && systemctl disable firewalld
執行以下命令安裝wget和docker:
yum install -y wget yum-utils device-mapper-persistent-data lvm2 \&& yum-config-manager \    --add-repo \    https://download.docker.com/linux/centos/docker-ce.repo \&& yum install  -y docker-ce docker-ce-cli containerd.io \&& systemctl start docker
執行docker version,如果看到以下資訊表示docker安裝和啟動成功:
[root@centos7 ~]# docker versionClient: Docker Engine - Community Version:           20.10.2 API version:       1.41 Go version:        go1.13.15 Git commit:        2291f61 Built:             Mon Dec 28 16:17:48 2020 OS/Arch:           linux/amd64 Context:           default Experimental:      trueServer: Docker Engine - Community Engine:  Version:          20.10.2  API version:      1.41 (minimum version 1.12)  Go version:       go1.13.15  Git commit:       8891c58  Built:            Mon Dec 28 16:16:13 2020  OS/Arch:          linux/amd64  Experimental:     false containerd:  Version:          1.4.3  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b runc:  Version:          1.0.0-rc92  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff docker-init:  Version:          0.19.0  GitCommit:        de40ad0
設定映象加速,否則下載映象慢並且時常超時,執行以下命令完成映象加速設定並使其生效:
mkdir -p /etc/dockertee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": ["https://registry.docker-cn.com"]}EOFsystemctl daemon-reloadsystemctl restart docker

環境準備完成,接下來安裝KMS;

demo執行環境準備由於demo是java版本,所以要安裝JDK和Maven,下面是安裝步驟;請下載Linxu版本的JDK安裝包,我這裡用的是jdk-8u191-linux-x64.tar.gz,請自行前往Oracle官方下載;將jdk-8u191-linux-x64.tar.gz上傳到CentOS電腦上,再執行以下命令,將JDK包解壓到合適的位置:
mkdir -p /usr/lib/jvmtar -C /usr/lib/jvm/ -xzf jdk-8u191-linux-x64.tar.gz
在環境變數中寫入JDK相關的資訊,並使之生效:
echo 'export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_191' >> ~/.bashrcecho 'export JRE_HOME=${JAVA_HOME}/jre' >> ~/.bashrcecho 'export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib' >> ~/.bashrcecho 'export PATH=${JAVA_HOME}/bin:$PATH' >> ~/.bashrcsource ~/.bashrc
執行java -version看看設定是否已經生效:
[root@centos7 ~]# java -versionjava version "1.8.0_191"Java(TM) SE Runtime Environment (build 1.8.0_191-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
接下來是maven,執行以下命令,即可完成下載、解壓、環境變數設定等所有工作:
wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gztar -C /usr/local/ -xzf apache-maven-3.6.3-bin.tar.gzecho 'export MAVEN_HOME=/usr/local/apache-maven-3.6.3' >> ~/.bashrcecho 'export PATH=$MAVEN_HOME/bin:$PATH' >> ~/.bashrcsource ~/.bashrc
執行mvn -version看看設定是否已經生效:
[root@centos7 ~]# mvn -versionApache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)Maven home: /usr/local/apache-maven-3.6.3Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk1.8.0_191/jreDefault locale: zh_CN, platform encoding: UTF-8OS name: "linux", version: "3.10.0-1160.11.1.el7.x86_64", arch: "amd64", family: "unix"
為了提高二方庫的下載速度,建議配置阿里雲倉庫,開啟檔案/usr/local/apache-maven-3.6.3/conf/settings.xml,找到mirrors節點,在裡面增加以下內容:
 <mirror>          <id>nexus-aliyun</id>          <mirrorOf>central</mirrorOf>          <name>Nexus aliyun</name>          <url>http://maven.aliyun.com/nexus/content/groups/public</url>       </mirror>
儲存退出,環境設定已經完成,接下來可以下載demo原始碼了;下載官方demo現在咱們把官方demo下載下來,用於稍後的體驗;為了確保demo的穩定,就不下載最新程式碼了,而是已經歸檔的6.15.0版本,執行以下命令完成下載和解壓:
wget https://github.com/Kurento/kurento-tutorial-java/archive/6.15.0.tar.gztar -xzf 6.15.0.tar.gz
解壓後是個名為的資料夾,裡面是前面截圖中的那些demo:
[root@centos7 ~]# tree -L 1 kurento-tutorial-java-6.15.0/kurento-tutorial-java-6.15.0/├── kurento-chroma├── kurento-crowddetector├── kurento-group-call├── kurento-hello-world├── kurento-hello-world-recording├── kurento-hello-world-repository├── kurento-magic-mirror├── kurento-metadata-example├── kurento-one2many-call├── kurento-one2one-call├── kurento-one2one-call-advanced├── kurento-one2one-call-recording├── kurento-platedetector├── kurento-player├── kurento-pointerdetector├── kurento-rtp-receiver├── kurento-send-data-channel├── kurento-show-data-channel├── LICENSE├── NOTICE├── pom.xml└── README.md18 directories, 4 files
至此,執行官方demo前的準備工作已經完成,開始體驗精彩的官方demo吧!執行官方demo前,先梳理一下資料流簡單看看當前情況,現在的情況如下圖所示,CentoOS電腦上執行著KMS:一旦咱們執行一個demo,就會變成下圖的樣子:然後,咱們會在另一臺電腦上用瀏覽器訪問demo應用的網頁,以kurento-hello-world這個demo為例,基本流程如下(省略了WebRTC的複雜流程):上面就是一個最基本的demo所涉及的資料流向,當然了,每個demo都有其特殊性,例如直播的demo是多個瀏覽器連線到KMS,不過整體上與上面的流程圖類似;做了這麼多準備工作還沒開始執行demo,可能您已經很憤怒了,好吧我不繼續逼逼了,咱們立即開始執行demo;再多說一句:執行瀏覽器的電腦上請備好攝像頭和麥克風,不然很多demo功能無法體驗;demo之一:本人本地預覽+實時播放進入demo原始碼的子目錄kurento-hello-world,執行以下命令即可啟動demo應用,並且,將控制檯資訊轉存到~/kurento-hello-world.log:
nohup mvn -U clean spring-boot:run \-Dspring-boot.run.jvmArguments="-Dkms.url=ws://localhost:8888/kurento" \>> ~/kurento-hello-world.log \2>&1 &
此時開始編譯專案kurento-hello-world,會消耗一定時間,可以執行命令tail -f ~/kurento-hello-world.log檢視當前進展,如下所示,我這裡還在下載二方庫:
...Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/com/jcraft/jsch.agentproxy.jsch/0.0.9/jsch.agentproxy.jsch-0.0.9.jar (0 B at 0 B/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jarDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-6/plexus-interactivity-api-1.0-alpha-6.jar (0 B at 0 B/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/wagon/wagon-ssh-common/3.3.2/wagon-ssh-common-3.3.2.jarProgress (1): 1.9 kB...
漫長等待後輸入以下資訊,標誌著demo啟動成功:
[INFO] --- spring-boot-maven-plugin:2.2.4.RELEASE:run (default-cli) @ kurento-hello-world ---[INFO] Attaching agents: []   .------------------------------------.   |                                    |   |   | |/ /  _ _ _ ___ _ _| |_ ___    |   |   | ' < || | '_/ -_) ' \  _/ _ \   |   |   |_|\_\_,_|_| \___|_||_\__\___/   |   |                                    |   '------------------------------------'       Kurento Java Tutorial - Hello World       Version 6.15.02021-01-09 15:56:15.348  WARN 35812 --- [           main] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 10012 milliseconds to respond. Please verify your network configuration.2021-01-09 15:56:25.366  INFO 35812 --- [           main] o.k.tutorial.helloworld.Application      : Starting Application on centos7 with PID 35812 (/root/kurento-tutorial-java-6.15.0/kurento-hello-world/target/classes started by root in /root/kurento-tutorial-java-6.15.0/kurento-hello-world)2021-01-09 15:56:25.367  INFO 35812 --- [           main] o.k.tutorial.helloworld.Application      : No active profile set, falling back to default profiles: default2021-01-09 15:56:25.984  INFO 35812 --- [rbeatExec-e1-t0] o.k.j.c.JsonRpcClientNettyWebSocket      : [KurentoClient]  Connecting native client2021-01-09 15:56:25.985  INFO 35812 --- [rbeatExec-e1-t0] o.k.j.c.JsonRpcClientNettyWebSocket      : [KurentoClient]  Creating new NioEventLoopGroup2021-01-09 15:56:41.079  INFO 35812 --- [ntLoopGroup-2-1] o.k.j.c.JsonRpcClientNettyWebSocket      : [KurentoClient]  Initiating new Netty channel. Will create new handler too!2021-01-09 15:56:41.140  WARN 35812 --- [           main] org.kurento.client.KurentoClient         : Connected to KMS in 15142 millis (> 5000 millis)2021-01-09 15:56:41.704  INFO 35812 --- [           main] o.k.tutorial.helloworld.Application      : Started Application in 51.601 seconds (JVM running for 51.817)
我這裡CentOS電腦的IP是192.168.133.208,因此用瀏覽器訪問demo的地址是:https://192.168.133.208:8443/ ,即可體驗demo的功能,如下圖:這個服務就讓它一直執行吧,接下來咱們繼續體驗下一個demo;demo之二:本人本地預覽+實時播放(帶filter特效)馬上要體驗的demo,其功能和前面的差不多,也是從KMS取得本地的影片資料用來展示,不同的是KMS會對影片做處理,給影片中的人加上一頂帽子;進入demo原始碼的子目錄kurento-magic-mirror,在啟動此應用之前有個問題要處理:前一個demo已經佔用了8443埠,這裡就不能再用了,要改;開啟kurento-magic-mirror目錄下的pom.xml檔案,找到下圖紅框位置,這裡就是應用埠的值,請改成一個還未佔用的值(我這裡改成了8444):執行以下命令即可啟動demo應用,並且將控制檯資訊轉存到~/kurento-magic-mirror.log:
nohup mvn -U clean spring-boot:run \-Dspring-boot.run.jvmArguments="-Dkms.url=ws://localhost:8888/kurento" \>> ~/kurento-magic-mirror.log \2>&1 &
啟動成功後,瀏覽器訪問https://192.168.133.208:8444/,執行起來的效果如下圖所示,影片中的人帶上了一頂帽子:

7
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 以太坊原始碼解析(一)