网站首页 > 技术教程 正文
环境要求
1, 配置nfs存储卷
1,在docker swarm集群中所有节点都确认安装nfs客户端软件
# yum install nfs-utils rpcbind -y
2, 在192.168.122.1 上搭建nfs,共享目录给docker swarm集群中所有节点挂载
[root@nfs ~]# mkdir /opt/dockervolume
[root@nfs ~]# vim /etc/exports
/opt/dockervolume *(rw,no_root_squash,sync)
[root@nfs ~]# systemctl restart rpcbind nfs-server [root@nfs ~]# systemctl enble rpcbind nfs-server
3, 在docker swarm集群中所有节点创建存储卷,并验证
# docker volume inspect nginx_volume [
{
"CreatedAt": "2019-06-12T13:24:09+08:00",
"Driver": "local",
"Labels": {}, "Mountpoint":
"/var/lib/docker/volumes/nginx_volume/_data", "Name": "nginx_volume",
"Options": {
"device": ":/opt/dockervolume", "o": "addr=192.168.122.1,rw",
注意这里的挂载参数要有
"type": "nfs"
},
"Scope": "local"
}
# docker volume ls |grep nginx_volume
local nginx_volume
# docker volume create --driver local --opt type=nfs --opt o=addr=192.168.122.1,rw --opt device=:/opt/dockervolume
nginx_volume
2, 下载镜像
在任意能上外网的机器上操作
[root@nfs ~]# docker pull richarvey/nginx-php-fpm
3, 准备是相关配置文件
[root@nfs ~]# mkdir /root/discuz/dockerfile -p
[root@nfs ~]# cd /root/discuz/dockerfile
准备nginx主配置文件
[root@nfs dockerfile]# vim nginx.conf user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll; worker_connections 65535;
}
http {
include /etc/nginx/mime.types; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent
"$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log
sendfile #tcp_nopush
/var/log/nginx/access.log on;
on;
main;
keepalive_timeout 65; #gzip on;
include /etc/nginx/conf.d/*.conf;
}
准备nginx子配置文件
[root@nfs dockerfile]# vim web.conf server {
listen 80; server_name _;
index index.php index.html; root /var/www/html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name; include fastcgi_params;
}
}
准备时区文件
[root@nfs dockerfile]# cp /etc/localtime .
准备php-fpm子配置文件
[root@nfs dockerfile]# vim php-fpm-www.conf [www]
user = nginx group = nginx
listen = 127.0.0.1:9000
pm = dynamic pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
4, 准备镜像
编写Docker?le
[root@nfs dockerfile]# vim dockerfile FROM richarvey/nginx-php-fpm
MAINTAINER daniel@itcast.cn
RUN echo 'Asia/Shanghai' > /etc/timezone && rm -f
/etc/nginx/nginx.conf && rm -f /usr/local/etc/php- fpm.d/www.conf
COPY localtime /etc/localtime
COPY nginx.conf /etc/nginx/nginx.conf COPY web.conf /etc/nginx/conf.d/web.conf
COPY php-fpm-www.conf /usr/local/etc/php-fpm.d/www.conf
CMD /usr/sbin/nginx -c /etc/nginx/nginx.conf &&
/usr/local/sbin/php-fpm -c /usr/local/etc/php-fpm.conf
构建镜像
[root@nfs dockerfile]# docker build -f dockerfile -t 192.168.122.18/library/nginx-php-fpm:v1 .
上传镜像到harbor
[root@nfs dockerfile]# docker login 192.168.122.18
[root@nfs dockerfile]# docker push 192.168.122.18/library/nginx-php-fpm:v1
5, 编排docker stack
编写YMAL文件
在docker swarm集群中的管理节点进行操作
[root@manager ~]# cat discuz.yml version: '3'
services: db:
image: 192.168.122.18/library/mysql:5.7 environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_DATABASE: discuz MYSQL_USER: discuz_user MYSQL_PASSWORD: 123
deploy:
replicas: 1
nginx-php:
image: 192.168.122.18/library/nginx-php-fpm:v1 depends_on:
- db ports:
- "8011:80"
volumes:
- "nginx_volume:/var/www/html" deploy:
replicas: 1
volumes:
nginx_volume: driver: local driver_opts:
type: "nfs"
o: "addr=192.168.122.1,rw"
device: ":/opt/dockervolume"
一键发布stack
[root@manager ~]# docker stack deploy -c discuz2.yml discuz
Creating network discuz_default
Creating service discuz_db
Creating service discuz_nginx-php
6, 拷贝discuz代码到nfs共享
在nfs服务器上操作
[root@nfs dockerfile]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
[root@nfs dockerfile]# cp DiscuzX/upload/* /opt/dockervolume/
-rf
cp: overwrite ‘/opt/dockervolume/index.php’? y
7, 通过浏览器安装
[root@nfs dockerfile]# chmod o+w -R /opt/dockervolume/
上图少了-R参数,请加上
猜你喜欢
- 2024-09-21 Nginx的信号控制(nginx 426)
- 2024-09-21 Nginx报Too Many Open Files总结(nginx报错)
- 2024-09-21 Linux下如何用nginx+ffmpeg搭建流媒体服务器
- 2024-09-21 强大,Nginx配置一键生成(nginx配置cgi)
- 2024-09-21 如何使用Nginx实现MySQL数据库的负载均衡?看完我懂了
- 2024-09-21 nginx配置(nginx负载均衡配置详解)
- 2024-09-21 企业十大应用-Nginx-配置详解(nginx公司)
- 2024-09-21 Nginx正向代理、反向代理、负载均衡及性能优化
- 2024-09-21 c/c++ nginx配置详解(nginx c compiler)
- 2024-09-21 说说Mac下nginx.pid 报错 和端口的事情
你 发表评论:
欢迎- 最近发表
-
- Linux新手必看:几种方法帮你查看CPU核心数量
- linux基础命令之lscpu命令(linux中ls命令的用法)
- Linux lscpu 命令使用详解(linux常用ls命令)
- 如何查询 Linux 中 CPU 的数量?这几个命令要知道!
- 在linux上怎么查看cpu信息(linux如何查看cpu信息)
- 查看 CPU 的命令和磁盘 IO 的命令
- 如何在CentOS7上改变网卡名(centos怎么改网卡名字)
- 网工必备Linux网络管理命令(网工必备linux网络管理命令是什么)
- Linux 网络命令知多少(linux 网络 命令)
- Linux通过命令行连接wifi的方式(linux命令行连接无线网)
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)