今天开始录一些docker布署的视频,每个程序员都应该会这些先准备虚拟机,
我这里准备的是ubuntu18,配置是2核4G
第一个视频先准备好docker和docker-compose环境
先来docker的安装
习惯将docker放在这个目录/usr/local/docker
安装docker
curl -fsSL get.docker.com -o get-docker.sh这一步是下载docker官方的安装脚本
sudo sh get-docker.sh --mirror Aliyun执行安装脚本,指定镜像为阿里云,这样安装快些
再提前从官网下载好docker-compose,我这已经下载好了,通过ftp软件,上传到虚拟机上
docker已经安装好了,先把docker的镜像源配置一下
我这台虚拟机之前配置过docker,我先把daemon.json清空了
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}
把上面的配置粘贴到/etc/docker/daemon.json里
service docker restart重启一次docker服务
到这里docker就配置好了
现在来配置docker-compose,刚才已经通过ftp上传到了虚拟机。
只需要移动到/usr/local/bin/下,将设置u+x权限,让当前用户可以执行即可docker-compose也好了
docker环境已经准备完毕
======================================================================
先在/usr/local/docker目录下创建nginx目录,用于存储nginx容器的配置和nginx的日志等
cd /usr/local/docker
mkdir nginx
cd nginx/
docker本身的命令很长,不利于管理,这里采用docker-compose方式来管理容器
先在/usr/local/docker/nginx下创建docker-compose.yml文件,用来编写nginx容器的配置
从nginx官网下载nginx的安装包,上传到虚拟机上
再复制准备好的docker-compose.yml内容
echo > docker-compose.yml <<EOF
version: '3.1' #指定docker-compose版本
services: #定义服务
nginx: #服务名
restart: always #重启
build: build #指定构建容器的目录
container_name: nginx #指定容器名
ports: #宿主机端口
- 80:80
volumes: #宿主机目录映射到容器中
- ./nginx.conf:/usr/local/nginx/conf/nginx.conf #将宿主机上当前目录下的nginx.conf文件映射到容器中/usr/local/nginx/conf/nginx.conf
- ./1og:/var/log/nginx/
- ./wwwroot:/usr/share/nginx/html
EOF
cd /usr/local/docker/nginx
mkdir build
vi build/Dockerfile
#当前镜像基于
FROM ubuntu:xenial
#设置工作目录
WORKDIR /etc/apt
RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse' > sources.list
RUN echo 'deb http://mirrors . aliyun. com/ ubuntu/ xenial-security main restricted universe multiverse' 》> sources.list
RUN echo 'deb http: //mirrors . aliyun. com/ubuntu/ xenial-updates main restricted universe multiverse' >> sources.list
RUN echo 'deb http: //mirrors . aliyun . com/ubuntu/ xenial-backports main restricted universe multiverse' >> sources .list
RUN apt -get update
#安装依赖
RUN apt-get install unzip make gcc libpcre3-dev zlib1g-dev --assume-yes
#复制工具包
# ADD命令会将.tar.gz文件复制到指定目录,井自动解压
ADD nginx-1.17.7.tar.gz /ust/1ocal/src
#设置工作目录
WORKDIR /usr/1oca1/src/nginx-1.17.7
#编译nginx
RUN rm -rf ./Makefile
RUN ./configure
RUN make && make install
WORKDIR /
#最后运行脚本,启动nginx
CMD ["/usr/1ocal/nginx/sbin/nginx", "-C", "/usr/local/nginx/conf/nginx.conf", "-g", "daemon off;"]
现在将nginx安装包移到build目录下
再复制nginx配置文件
mv /root/nginx-1.17.7.tar.gz ./build/
user root ;
worker_processes auto;
worker_rlimit nofile 65535;
events {
worker connections 102400;
use epoll;
}
http {
server_tokens off;
include mime .types ;
default_type application/octet-stream;
access_ log /var/log/nginx/access . log;
access_log off;
error_log /var/log/nginx/error.log;
keepalive_timeout 65;
client_max_body_size 20m;
gzip on;
gzip_disable "msie6";
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml applicat ion/javascript text/css application/x-javascript;
server {
listen 80;
server_name test;
root /usr/share/nginx/html/;
}
}
mkdir log
mkdir wwwroot
build/
docker-compose.yml
log/
nginx.conf
wwwroot/
docker-compose up
docker-compose up -d
docker ps
今天开始录一些docker布署的视频,每个程序员都应该会这些先准备虚拟机,
我这里准备的是ubuntu18,配置是2核4G
第一个视频先准备好docker和docker-compose环境
先来docker的安装
习惯将docker放在这个目录/usr/local/docker
安装docker
curl -fsSL get.docker.com -o get-docker.sh这一步是下载docker官方的安装脚本
sudo sh get-docker.sh --mirror Aliyun执行安装脚本,指定镜像为阿里云,这样安装快些
再提前从官网下载好docker-compose,我这已经下载好了,通过ftp软件,上传到虚拟机上
docker已经安装好了,先把docker的镜像源配置一下
我这台虚拟机之前配置过docker,我先把daemon.json清空了
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}
把上面的配置粘贴到/etc/docker/daemon.json里
service docker restart重启一次docker服务
到这里docker就配置好了
现在来配置docker-compose,刚才已经通过ftp上传到了虚拟机。
只需要移动到/usr/local/bin/下,将设置u+x权限,让当前用户可以执行即可docker-compose也好了
docker环境已经准备完毕
======================================================================
先在/usr/local/docker目录下创建nginx目录,用于存储nginx容器的配置和nginx的日志等
cd /usr/local/docker
mkdir nginx
cd nginx/
docker本身的命令很长,不利于管理,这里采用docker-compose方式来管理容器
先在/usr/local/docker/nginx下创建docker-compose.yml文件,用来编写nginx容器的配置
从nginx官网下载nginx的安装包,上传到虚拟机上
再复制准备好的docker-compose.yml内容
echo > docker-compose.yml <<EOF
version: '3.1' #指定docker-compose版本
services: #定义服务
nginx: #服务名
restart: always #重启
build: build #指定构建容器的目录
container_name: nginx #指定容器名
ports: #宿主机端口
- 80:80
volumes: #宿主机目录映射到容器中
- ./nginx.conf:/usr/local/nginx/conf/nginx.conf #将宿主机上当前目录下的nginx.conf文件映射到容器中/usr/local/nginx/conf/nginx.conf
- ./1og:/var/log/nginx/
- ./wwwroot:/usr/share/nginx/html
EOF
cd /usr/local/docker/nginx
mkdir build
vi build/Dockerfile
当前镜像基于
FROM ubuntu:xenial
设置工作目录
WORKDIR /etc/apt
RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse' > sources.list
RUN echo 'deb http://mirrors . aliyun. com/ ubuntu/ xenial-security main restricted universe multiverse' 》> sources.list
RUN echo 'deb http: //mirrors . aliyun. com/ubuntu/ xenial-updates main restricted universe multiverse' >> sources.list
RUN echo 'deb http: //mirrors . aliyun . com/ubuntu/ xenial-backports main restricted universe multiverse' >> sources .list
RUN apt -get update
安装依赖
RUN apt-get install unzip make gcc libpcre3-dev zlib1g-dev --assume-yes
复制工具包
ADD命令会将.tar.gz文件复制到指定目录,井自动解压
ADD nginx-1.17.7.tar.gz /ust/1ocal/src
设置工作目录
WORKDIR /usr/1oca1/src/nginx-1.17.7
编译nginx
RUN rm -rf ./Makefile
RUN ./configure
RUN make && make install
WORKDIR /
最后运行脚本,启动nginx
CMD ["/usr/1ocal/nginx/sbin/nginx", "-C", "/usr/local/nginx/conf/nginx.conf", "-g", "daemon off;"]
现在将nginx安装包移到build目录下
再复制nginx配置文件
mv /root/nginx-1.17.7.tar.gz ./build/
user root ;
worker_processes auto;
worker_rlimit nofile 65535;
events {
worker connections 102400;
use epoll;
}
http {
server_tokens off;
include mime .types ;
default_type application/octet-stream;
access_ log /var/log/nginx/access . log;
access_log off;
error_log /var/log/nginx/error.log;
keepalive_timeout 65;
client_max_body_size 20m;
gzip on;
gzip_disable "msie6";
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml applicat ion/javascript text/css application/x-javascript;
server {
listen 80;
server_name test;
root /usr/share/nginx/html/;
}
}
mkdir log
mkdir wwwroot
build/
docker-compose.yml
log/
nginx.conf
wwwroot/
docker-compose up
docker-compose up -d
docker ps
docker logs -f nginx
docker-compose logs -f nginx
prometheus+grafana监控服务器CPU、内存、硬盘、IOPS
cd /usr/local/docker/
minio/
mysql8/
nginx/
nginx-lua/
ngingx-vts/
prometheus+grafana/
rabbitmq/
redis/
node-exporter/
cd node-exporter/
vi docker-compose.yml
version: '3.1'
services:
node-exporter:
container_name: node-exporter
image: prom/node-exporter
ports:
- 9100:9100
---
docker-compose up -d
#在prometheus上配置采集
ssh root@192.168.3.7
cd /usr/local/docker/prometheus+grafana/
ll
docker-compose.yml
grafana/
prometheus.yml
docker ps
vi prometheus.yml
global:
scrape_interval: 5s #取数间隔,默认15s
evaluation_interval: 5s
scrape_configs:
- job_name: nginx
static_configs:
- targets: ['192.168.3.7:9133']
- job_name: node
static_configs:
- targets: ['192.168.3.7:9100']
- targets: ['192.168.3.7:9100','192.168.3.8:9100']
docker-compose up -d
docker ps
grafana 面版id 8919
网友评论