先更新apt源

> vim /etc/apt/source.list
> 
> deb http://mirrors.aliyun.com/ubuntu bionic main multiverse restricted universe
> deb http://mirrors.aliyun.com/ubuntu bionic-updates main multiverse restricted universe
> deb http://mirrors.aliyun.com/ubuntu bionic-security main multiverse restricted universe
> deb http://mirrors.aliyun.com/ubuntu bionic-proposed main multiverse restricted universe
> deb http://mirrors.aliyun.com/ubuntu bionic-backports main multiverse restricted universe
> ```

## 1、安装Mysql

##### 1.1 安装

```shell
apt update
apt install mysql-server
service mysql start
1.2 设置连接
  1. 进入mysql容器:docker exec -it 容器id /bin/bash (退出:extc)

  2. mysql -uroot -p,回车输入密码进入mysql操作

  3. 看当前所有数据库:show databases;

  4. 进入mysql数据库:use mysql;

  5. 查看mysql数据库中所有的表:show tables;

  6. 查看user表中的数据:select Host, User from user;

  7. 修改user表中的Host: update user set Host='%' where User='root'; 说明: % 代表任意的客户端,可替换成具体IP地址。

  8. 注意:一定要记得在写sql的时候要在语句完成后加上” ; “

  9. 修改密码:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'PcAiPass@2021!';

注意: 如果遇到报错信息:mysql> alter user 'root'@'%' identified with mysql_native_password by 'your password'; ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'

请执行:flush privileges;

  1. 最后刷新一下:flush privileges;

  2. 修改针对于orderby的报错问题

    vim /etc/mysql/mysql.conf.d/mysqld.cnf
    
    
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    
  3. 设置大小写

    vim /etc/mysql/mysql.conf.d/mysqld.cnf
    #在【mysqld】下面增加一行:
    lower_case_table_names = 1
    
  4. 重启mysql

    service mysql restart
    

### mysql启动报错【No directory, logging in with HOME=/】

 usermod -d /var/lib/mysql/ mysql#第一步
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock#第二步
chown -R mysql:mysql /var/lib/mysql#第三步
#之后重启mysql即可

2、安装Redis(5.0版本以上)

帮助连接

2.1 安装
cd /usr/local/server
wget https://download.redis.io/releases/redis-7.0.3.tar.gz
tar -zxvf redis-7.0.3.tar.gz
cd redis-7.0.3
make && install 
2.2 修改配置
cd /usr/local/server/redis-7.0.3
vim redis.conf

###########################################
# daemonize  由 no 修改为 yes   设置为后台执行
###########################################
daemonize yes

###########################################
#bind  由 bind 127.0.0.1 -::1 修改为 bind 0.0.0.0
###########################################
bind 0.0.0.0
2.3 设置远程连接
cd /usr/local/server/redis-7.0.3
vim redis.conf
#####################################################
#protected-mode yes 修改为 no
#这个对Ubuntu有影响,会在远程访问的时候要求必须有密码,redis默认不用密码,所以记得先设置下密码,或者把它设置成no。
#####################################################
protected-mode no

解决linux下redis数据库overcommit_memory问题 以及

vim /etc/sysctl.conf

####
#新增以下内容
####
#内核参数overcommit_memory
#可选值:0、1、2。
#0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
#1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
#2, 表示内核允许分配超过所有物理内存和交换空间总和的内存
vm.overcommit_memory = 1

#Deal with : WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn
net.core.somaxconn= 1024

解决 : WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled

vim /etc/rc.local
#关闭 redis THP
echo never > /sys/kernel/mm/transparent_hugepage/enabled

3、部署SRS服务

1、下载源码
git clone -b 4.0release https://gitee.com/ossrs/srs.git
2、编译

注意需要切换到srs/trunk目录

cd srs/trunk
./configure
make
3、修改端口号
3.1 修改配置文件
vim /usr/local/server/srs/trunk/conf/srs.conf

修改http_server配置项的listen端口号为:9090

#main config for srs.
#@see full.conf for detail config.

listen              1935;
max_connections     1000;
#srs_log_tank        file;
#srs_log_file        ./objs/srs.log;
daemon              on;
http_api {
    enabled         on;
    listen          1985;
}
http_server {
    enabled         on;
    listen          9090;
    dir             ./objs/nginx/html;
}
rtc_server {
    enabled on;
    listen 8000; # UDP port
    # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#config-candidate
    candidate $CANDIDATE;
}
vhost __defaultVhost__ {
    hls {
        enabled         on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    rtc {
        enabled     on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc
        rtmp_to_rtc off;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
        rtc_to_rtmp off;
    }
}

3.2 修改页面端口号

修改http的端口号为9090

vim /usr/local/server/srs/trunk/objs/nginx/html/console/js/srs.console.js
 ############################################################################################## 
 614 // the sc server is the server we connected to.
 615 scApp.provider("$sc_server", [function(){
 616     this.$get = function(){
 617         var self = {
 618             schema: "http",
 619             host: null,
 620             port: 1985,
 621             rtmp: [1935],
 622             http: [8081],
 623             baseurl: function(){
 624                 return self.schema + "://" + self.host + (self.port === 80? "": ":" + self.port);
 625             },
 626             jsonp: function(url){
3.3 修改主页跳转js
 vim /usr/local/server/srs/trunk/objs/nginx/html/index.html
###################
#将 parseInt(window.location.port) 
###################
 50         // Build console url.
 51         if (true) {
 52             // The prefix for default website.
 53             const prefix = `${window.location.protocol}//${window.location.host}`;
 54             // If not 8080, user should proxy to the default port.
 55             const query = parseInt(window.location.port) === 8081 ? `?port=1985` : '';
 56             const enUrl = `${prefix}/console/en_index.html#/summaries${query}`;
 57             const cnUrl = `${prefix}/console/ng_index.html#/summaries${query}`;
 58             document.getElementById("enConsole").setAttribute('href', enUrl);
 59             document.getElementById("cnConsole").setAttribute('href', cnUrl);
 60         }
 61 
 62         // The player url.
 63         if (true) {
 64             const prefix = `players/?schema=${window.location.protocol.replace(':', '')}`;
 65             const httpPort = window.location.port || (window.location.protocol === 'http:' ? 80 : 443);
 66             // If not 8080, user should proxy both stream and API to the default port.
 67             const query = parseInt(window.location.port) === 8081 ? '' : `&port=${httpPort}&api=${httpPort}`;
 68             document.getElementById("enPlayer").setAttribute('href', `${prefix}${query}`);
 69             document.getElementById("cnPlayer").setAttribute('href', `${prefix}${query}`);
 70        }

4、启动服务器:
nohup ./objs/srs -c conf/srs.conf >/dev/null 2>&1 &
5、检查SRS启动情况
http://localhost:9090/ ,或者执行命令
#查看SRS的状态
./etc/init.d/srs status
MB0:trunk $ ./etc/init.d/srs status
SRS(pid 90408) is running.                                 [  OK  ]
#如果异常   查看日志排查

#或者看SRS的日志
tail -n 30 -f ./objs/srs.log




查看状态

./etc/init.d/srs status
停止

./etc/init.d/srs stop
查看srs版本

./objs -v

4、安装JAVA

 apt-get install openjdk-8-jre-headless git wget curl -y

5、部署大屏项目

1、上传安装包到服务器到/usr/local/server目录下

apache-tomcat-8.5.43.tar.gz

或者从备份服务器下载安装包

 cd /usr/local/server
 wget http://58.220.24.92:8091/aicsp/profile/file/apache-tomcat-8.5.43.tar.gz
2、解压并更改tomcat名称
 tar -zxvf apache-tomcat-8.5.43.tar.gz
 mv apache-tomcat-8.5.43 apache-tomcat
3、修改端口为8888和修改配置文件setclasspath.sh
 vim /usr/local/server/apache-tomcat/conf/server.xml
 修改端口8080 -> 8888
 cd /usr/local/server/apache-tomcat/bin
 vim setclasspath.sh
 增加JAVA_HOME和JRE_HOME两个环境变量,环境变量路径即为jdk安装路径
#-----------------------------------------------------------------------------
#Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
#are valid and consistent with the selected start-up options and set up the
#endorsed directory.
export JAVA_HOME=/usr/local/java
export JAVA_HOME=/usr/local/java/jre
#-----------------------------------------------------------------------------
4、清除tomcat下的其他部署包
 cd /usr/local/server/apache-tomcat/webapps/
 rm -rf /usr/local/server/apache-tomcat/webapps/*  (谨慎删除,判断是否在webapps目录下)
5、上传安装包到服务器到/usr/local/server/apache-tomcat/webapps/目录

dist.zip

或者从备份服务器下载安装包

 cd /usr/local/server/apache-tomcat/webapps/
 wget http://58.220.24.92:8091/aicsp/profile/file/dist.zip
6、解压大屏项目并删除dist.zip
 unzip dist.zip
 rm -rf dist.zip
7、启动大屏项目
 /usr/local/server/apache-tomcat/bin/startup.sh

6、部署AI音视频融合平台

6.1 新增字体
cd /usr/share/fonts/ 
mkdir chinese 
cd chinese
wget http://58.220.24.92:8091/aicsp/profile/file/SIMSUN.TTC 

#安装字体
#如没有这个命令  请执行下面的步骤
mkfontscale 
mkfontdir 
#刷新系统字体缓存即刻生效 
fc-cache -fv 
#检查字体是否添加成功
fc-list | grep 宋体

bash: mkfontscale: 未找到命令

#使mkfontscale和mkfontdir命令正常运行
sudo apt-get install ttf-mscorefonts-installer
#使fc-cache命令正常运行
sudo apt-get install fontconfig

7、迁移算法

8、打包docker镜像

8.1 编写一键启动脚本

cd /
mkdir aibox
vim /aibox/service_start.sh
############################service_start.sh##############################
#!/bin/bash
sleep 1

FILEPATH=/var/run/redis_6379.pid
MYSQLFILEPATH=/var/run/mysqld/mysqld.sock.lock

if [[ -f "$FILEPATH" ]]; then
        echo "正在清理异常退出所占用的PID文件...";
        rm -f "$FILEPATH";
        echo "清理完成...";
fi;

#启动redis服务
echo "启动redis服务..."
service redis start

#启动mysql服务
#清理mysql程序异常退出导致的lock文件占用
if [[ -f "$MYSQLFILEPATH" ]]; then
        echo "存在mysql.sock.lock文件";
        echo "正在清理mysql.sock.lock文件"
        rm -f "$MYSQLFILEPATH";
        echo "清理完成...";
fi;

echo "修改Mysql目录权限...."
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld

echo "修改mysql用户信息...."
#No directory, logging in with HOME=/
usermod -d /var/lib/mysql/ mysql
echo "启动mysql服务..."
service mysql start
#启动SRS服务
echo "启动SRS服务..."
cd /usr/local/server/srs/trunk/


nohup ./objs/srs -c ./conf/srs.conf >/dev/null 2>&1 &
#启动大屏服务
echo "启动大屏服务..."
/usr/local/server/apache-tomcat/bin/startup.sh
#启动AI平台
echo "启动AI平台...."
/usr/local/server/aicsp/ai-ipc.sh start

sleep 1


#如何关闭透明巨页(THP)?
echo never > /sys/kernel/mm/transparent_hugepage/enabled

exit 0

8.2 打包镜像

#停掉镜像
docker stop 
#根据镜像打包
docker commit  -m '' 616fcc88d716 aibix:1.0.0
#根据Dockrfile打包镜像

###############################################
#编写Dockerfile
cd aibox
vim Dockerfile

############################Dockerfile###########################

FROM aibox:1.0.0

#定义时区参数
ENV TZ=Asia/Shanghai
#设置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone
#设置编码
ENV LANG C.UTF-8

COPY ./code/data_process1.0 /ai_server/code/data_process1.0   # 复制的是算法的内容
RUN chmod +x /ai_server/code/data_process1.0/video_app.py

#拷贝执行脚本
COPY ./service_start.sh /usr/local/server/service_start.sh
RUN chmod +x /usr/local/server/service_start.sh

#启动脚本
RUN chmod +x /usr/local/server/aicsp/ai-ipc.sh
ENTRYPOINT /usr/local/server/service_start.sh && tail -f /usr/local/server/aicsp/logs/sys-info.log


##################################执行打包命令##################################
docker build -t aibox:1.0.1 .

9、编辑监听docker服务的操作

9.1 设置docker服务检测

cd /ai_server/dockerPackage/  #目录可以随意设置
vim check-docker-service.sh
########################################check-docker-service.sh#####################################
#!/bin/sh
#Filename: check-docker-service.sh

PROC_NAME=dockerd
ProcNumber=`ps -ef |grep -w $PROC_NAME|grep -v grep|wc -l`
time1=$(date)
if [ $ProcNumber -le 0 ];then
   echo "$time1 :Docker service is not run" >> /root/check-docker-service.log
   systemctl start docker
   echo "$time1 :command:{ systemctl start docker } is execute" >> /root/check-docker-service.log
   
else
   echo "$time1 :Docker service is running.."  >> /root/check-docker-service.log
fi

9.2 设置定时任务执行上面的脚本

sudo su #切换root用户添加crontab   否则添加的任务会没有权限

crontab -e
#添加下面的命令   每5分钟执行一次
*/5  * * * * sh /ai_server/dockerPackage/check-docker-service.sh

9.3 每天重启docker容器

30 2 * * * docker restart aibox
#关闭docker服务
systemctl stop docker 
systemctl stop docker.socket
#启动dockerfuwu
systemctl start docker

下方为案例:

image-20220906164119668

image-20220906164143130

文档更新时间: 2023-12-18 03:25   作者:JeffreyCheung