1 基础知识
正式安装前,我们建议你先熟悉以下章节,
2 最佳实践
2.1 部署前的准备
2.1.1 部署Docker环境
本章使用如下Docker环境部署,参阅本章建议你先搭建以下Docker集群环境并熟悉,
2.1.2 准备系统镜像
In docker01
cd /data/docker/images/ docker load -i debian:10.10.tar docker tag debian:10.10 docker01.cmdschool.org:5000/debian:10.10 docker push docker01.cmdschool.org:5000/debian:10.10 docker image rm debian:10.10
另外,安装包的离线下载请在能上网的docker环境的机器上使用如下命令,
docker pull debian:10.10 docker save debian:10.10 -o debian:10.10.tar
另外,其他版本请从以下链接下载,
https://hub.docker.com/_/debian
2.2 创建新镜像
2.2.1 创建镜像项目文件夹
mkdir ~/imageProject-Unifi-WiFi
2.2.2 创建Dockerfile
vim ~/imageProject-Unifi-WiFi/Dockerfile
加入如下配置,
#FROM docker01.cmdschool.org:5000/debian:10.10 FROM debian:10.10 MAINTAINER will@cmdschool.org # Config apt source RUN echo 'deb http://mirrors.163.com/debian buster main\n \ deb-src http://mirrors.163.com/debian buster main\n \ deb http://mirrors.163.com/debian-security buster/updates main\n \ deb-src http://mirrors.163.com/debian-security buster/updates main\n \ deb http://mirrors.163.com/debian buster-updates main\n \ deb-src http://mirrors.163.com/debian buster-updates main\n' \ > /etc/apt/sources.list RUN cat /etc/apt/sources.list RUN apt update # Base config RUN apt install -y wget vim curl net-tools systemd procps # install mongodb RUN apt install -y gnupg ca-certificates apt-transport-https RUN wget -qO - https://www.mongodb.org/static/pgp/server-3.4.asc | apt-key add - RUN echo "deb http://mirrors.163.com/mongodb/apt/debian jessie/mongodb-org/3.4 main" > /etc/apt/sources.list.d/mongodb-org-3.4.list RUN echo "deb http://mirrors.163.com/debian-security jessie/updates main" >> /etc/apt/sources.list.d/debian.list RUN apt update RUN apt install -y mongodb-org-server RUN systemctl enable mongod.service # install openjdk RUN apt install -y openjdk-11-jdk-headless binutils jsvc logrotate COPY jdk-8u151-linux-x64.tar.gz /root/ WORKDIR /root/ RUN tar -xf jdk-8u151-linux-x64.tar.gz RUN mkdir /usr/java RUN mv jdk1.8.0_151 /usr/java/ RUN echo 'export JAVA_HOME=/usr/java/jdk1.8.0_151' > /etc/profile.d/jdk.sh RUN echo 'export JRE_HOME=${JAVA_HOME}/jre' >> /etc/profile.d/jdk.sh RUN echo 'export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib' >> /etc/profile.d/jdk.sh RUN echo 'export PATH=${JAVA_HOME}/bin:$PATH' >> /etc/profile.d/jdk.sh RUN echo "JAVA_HOME=/usr/java/jdk1.8.0_151" | tee -a /etc/default/unifi # install unifi WORKDIR /root/ ENV DEBIAN_FRONTEND noninteractive RUN wget https://dl.ui.com/unifi/5.12.72/unifi_sysvinit_all.deb RUN dpkg -i unifi_sysvinit_all.deb; apt-get install -f; apt-get clean RUN systemctl enable unifi.service # config start EXPOSE 8443 6789 8843 8880 8080 3478/udp 10001/udp CMD ["/sbin/init"]
需要注意的是,
– “FROM”指令声明基于“debian:10.10”镜像打包
– “RUN”指令声明容器环境执行的命令
– “COPY”指令声明复制当前目录的具体文件到打包的镜像
– “EXPOSE ”指令声明容器使用的端口
– “WORKDIR”指令声明切换容器内部的某个目录
– “CMD”指令声明启动容器执行的启动服务命令
根据打包文件的需要,我们需要使用如下命令准备java安装包,
cd ~/imageProject-Unifi-WiFi wget http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u65-linux-x64.tar.gz?AuthParam=1479977626_06aed8a715c8fbbc10f72c89ee38910b -O jdk-8u65-linux-x64.tar.gz
以上只是演示,如果不能下载请从JDK历史版本下载,
https://www.oracle.com/technetwork/java/javase/archive-139210.html
更新版本的JDK下载页面请参阅,
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.2.3 执行打包操作
cd ~/imageProject-Unifi-WiFi docker build -t build/unifi-wifi:5.12.72 .
以上“.”指当前目录为编译目录,编译程序会自动加载“Dockerfile”文件定义,可见如下显示,
[...] Removing intermediate container a4dadbf9cd87 ---> e0bc3cb56791 Successfully built e0bc3cb56791 Successfully tagged build/unifi-wifi:5.12.72
完成后,可使用如下命令查看镜像,
docker images
可见如下显示,
REPOSITORY TAG IMAGE ID CREATED SIZE build/Unifi-WiFi 5.12.72 e0bc3cb56791 25 seconds ago 2.14GB [...]
2.2.4 测试软件运行
docker run -d --privileged=true --name Unifi-WiFi build/unifi-wifi:5.12.72
以上运行容器环境后,我们使用以下命令登录容器虚拟机,
docker exec -it `docker container ls | grep 'Unifi-WiFi' | cut -d" " -f1 ` /bin/bash
可通过如下命令查看倾听的端口,
netstat -anp | grep java
可见如下显示,
tcp 0 0 0.0.0.0:8880 0.0.0.0:* LISTEN 360/java tcp 1 0 0.0.0.0:8080 0.0.0.0:* LISTEN 360/java tcp 0 0 127.0.0.1:44778 127.0.0.1:27117 ESTABLISHED 360/java tcp 0 0 127.0.0.1:44780 127.0.0.1:27117 ESTABLISHED 360/java unix 2 [ ] STREAM CONNECTED 1718985 360/java
测试完成后可使用如下命令退出容器虚拟机,
exit
另外,你可以使用如下命令查询当前运行的container,
docker ps -a
可见如下显示,
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6fff47b49759 build/unifi-wifi:5.12.72 "/sbin/init" 31 seconds ago Up 29 seconds 8080/tcp, 8880/tcp Unifi-WiFi [...]
然后可以使用如下命令停止并删除,
docker container stop 6fff47b49759 docker container rm 6fff47b49759
2.3 部署服务
本章重点是打包镜像,部署请参阅以下章节,
参阅文档
===============
下载链接
————
https://www.ui.com/download/unifi/
没有评论