安装部署图
- nginx负载应用
- 应用集群部署
- 应用访问数据库
- 应用访问缓存
- 数据库时间做备份
Docker安装配置
docker 卸载旧版本
(如果安装过旧版本的话)
sudo yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
Set up repository
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
docker 线上载镜像
设置yum源
#sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
sudo yum install docker-ce
docker 离线下载镜像
上传Docker离线下载的安装包
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
指定上传文件离线安装
yum install -y ${上传路径}/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
docker运行配置
vi /usr/lib/systemd/system/docker.service
--graph /home/go-nifty/docker
注:其中 /home/go-nifty/docker为数据盘相关路径
docker 启动
systemctl daemon-reload
systemctl start docker
systemctl enable docker
nginx 部署配置
nginx在线安装
docker pull nginx:latest
nginx离线安装
docker load < nginx.tar
nginx 创建相关系统目录
mkdir /home/go-nifty/volume
mkdir /home/go-nifty/volume/go-nifty-nginx
mkdir /home/go-nifty/volume/go-nifty-nginx/conf
mkdir /home/go-nifty/volume/go-nifty-nginx/html
nginx 配置
touch /home/go-nifty/volume/go-nifty-nginx/conf/nginx.conf
nginx.conf文件内容如下:
worker_processes 1;
error_log /var/log/nginx/error.log warn;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream go_nifty_lb {
server 192.168.0.1:81;
server 192.168.0.1:82;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://go_nifty_lb;
}
}
}
nginx 启动
docker run -d --restart=always --name=go-nifty-nginx \
--network=host \
-v /home/go-nifty/volume/go-nifty-nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/go-nifty/volume/go-nifty-nginx/html:/usr/share/nginx/html \
-v /home/go-nifty/volume/go-nifty-nginx/logs:/var/log/nginx \
-d nginx
应用安装部署
应用基础镜像下载
docker pull registry.cn-chengdu.aliyuncs.com/going100/tomcat-gonifty
应用基础镜像离线下载
先在本地使用下载指令将镜像拉到本地,再使用以下指令将镜像导出为一个压缩文件。
docker save registry.cn-chengdu.aliyuncs.com/going100/tomcat-gonifty > tomcat-gonifty.tar
再将文件通过移动介质复制到部署服务器中,再通过以下指令导入镜像。
docker load < tomcat-gonifty.tar
注:以上镜像只是基础tomcat镜像,没有应用包,还需要通过以下操作将应用到入tomcat基础镜像中。
具体操作如下:
在本地创建一个文件夹,如:tomcat-private,在目录中创建一个Dockerfile文件,并将最新的go-nifty.war包放在该目录下。如下图所示:
其中,Dockerfile文件内容如下:
FROM registry.cn-chengdu.aliyuncs.com/going100/tomcat-gonifty:latest
ADD go-nifty.war /usr/local/tomcat/webapps/
如果是windows系统下,使用命令行到该目录下执行构建镜像命令:
D:\worksapce-tmp\tomcat-private> docker build -t go-nifty-backend:latest .
最终将生成 后端应用镜像: go-nifty-backend:latest
启动应用
docker run --restart=always --name go-nifty-backend -d \
-p ${HTTP-PORT}:8080
-p ${HTTPS-PORT}:443
-v ${DOCUMENT-PATH}:/root/project/go-nifty/document
-v ${DOCUMENT-PATH}:/root/project/go-nifty/upload
-v ${LOG-PATH}:/usr/local/tomcat/logs
go-nifty-backend:latest
其中:
- HTTP-PORT 是http映射端口,如果应用在同一个宿主机做集群,端口不能冲突。
可映射为:8081,8082等 - HTTPS-PORT 是https映射端口,如果应用在同一个宿主机做集群,端口不能冲突。
可映射为:444,445等 - DOCUMENT-PATH 是附件存储路径
- LOG-PATH 是日志输出路径。
redis安装部署
redis下载镜像
docker pull redis:4.0.14
redis离线下载镜像
docker load < redis.tar
redis创建文件目录
mkdir /home/go-nifty/volume
mkdir /home/go-nifty/volume/go-nifty-redis
redis启动应用
docker run --restart=always --name go-nifty-redis -d \
--network=host \
-v /home/go-nifty/volume/go-nifty-redis:/redis-master-data \
redis:4.0.14
mysql安装部署
mysql下载镜像
docker pull mysql:5.7
mysql离线下载镜像
docker load < mysql.tar
mysql创建文件目录
mkdir /home/go-nifty/volume
mkdir /home/go-nifty/volume/go-nifty-mysql/
mkdir /home/go-nifty/volume/go-nifty-mysql/data
mkdir /home/go-nifty/volume/go-nifty-mysql/conf
mysql创建配置文件
touch /home/go-nifty/volume/go-nifty-myql/conf/mysqld.cnf
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
[mysqld]
log-bin=mysql-bin
binlog-ignore-db=mysql
server-id=1001
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
character_set_server = utf8
lower_case_table_names=1
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections = 500
max_allowed_packet = 16M
default-storage-engine=InnoDB
########innodb settings########
innodb_flush_log_at_trx_commit = 2
innodb_buffer_pool_size=128M
innodb_log_buffer_size=16M
innodb_log_file_size=256M
mysql 启动
docker run --restart=always --name go-nifty-mysql -d --network=host \
-e MYSQL_ROOT_PASSWORD=1qaz@WSX \
-e lower_case_table_names=1 \
-e TZ=Asia/shanghai \
-v /home/go-nifty/volume/go-nifty-mysql/data:/var/lib/mysql \
-v /home/go-nifty/volume/go-nifty-mysql/conf:/etc/mysql/mysql.conf.d \
mysql:5.7
基它
磁盘挂载
fdisk -u /dev/vdb
查看新分区情况
lsblk /dev/vdb1
通过该指令将看到新的分区/dev/vdb1.
使用
指令创建xfs文件系统:
mkfs.xfs /dev/vdb1
查看新分区的详情
blkid /dev/vdb1
设置开机自动挂载,打开自动挂载文件
vi /etc/fstab
加入如下图所示内容行:
UUID=uuid /home/go-nifty xfs defaults 0 0
reboot 重启系统