1 环境信息
1 查看系统内核
[root@localhost /]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
2 文件准备
2.1 获取资源文件
2.1.1 手动下载
1 apache-tomcat-8.5.16.tar.gz
http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.16/bin/apache-tomcat-8.5.16.tar.gz
2 server-jre-8u131-linux-x64.tar.gz
https://download.csdn.net/download/qq_15769939/12115544
2.1.2 虚拟机下安装docker
1 联网机器安装 downloadonly
yum install yum-plugin-downloadonly
2 下载docker安装文件
yum install --downloadonly --downloaddir=/opt/module/software/docker docker
3 安装docker
cd /opt/module/software/docker
rpm -ivh *.rpm
4 启动docker
systemctl start docker
5 拉取mysql5.7
docker pull mysql:5.7
6 拉取oracle11g
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
7 拉取vsftpd
docker pull fauria/vsftpd
8 拉取nginx
docker pull nginx
9 查看获取到的镜像文件
docker images
10 导出镜像
docker save -o /opt/module/software/jingxiang/mysql57.tar mysql:5.7
docker save -o /opt/module/software/jingxiang/oracle11.tar registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
docker save -o /opt/module/software/jingxiang/vsftpd.tar fauria/vsftpd
docker save -o /opt/module/software/jingxiang/nginx.tar nginx:latest
2.2 上传到服务器
1 将提供的module文件夹上传到服务器的 /opt/ 目录下
[root@localhost /]# ll /opt/module/
总用量 0
drwxr-xr-x. 2 root root 6 12月 9 14:14 env
drwxr-xr-x. 4 root root 113 12月 9 14:19 software
[root@localhost /]# ll /opt/module/software
总用量 62640
-rw-r--r--. 1 root root 9417469 12月 9 14:19 apache-tomcat-8.5.16.tar.gz
drwxr-xr-x. 2 root root 4096 12月 9 14:12 docker
drwxr-xr-x. 2 root root 80 12月 9 14:22 jingxiang
-rw-r--r--. 1 root root 54714634 12月 9 14:19 server-jre-8u131-linux-x64.tar.gz
[root@localhost /]# ll /opt/module/software/jingxiang
总用量 7705556
-rw-r--r--. 1 root root 441716224 12月 9 14:13 mysql57.tar
-rw-------. 1 root root 130173440 12月 9 14:22 nginx.tar
-rw-r--r--. 1 root root 6913197568 12月 9 14:17 oracle11.tar
-rw-r--r--. 1 root root 405392896 12月 9 14:13 vsftpd.ta
3 JDK 部署
1 解压以及剪切到/opt/module/env/目录
[root@localhost /]# cd /opt/module/software/
[root@localhost software]# tar -zxvf server-jre-8u131-linux-x64.tar.gz -C /opt/module/env/
[root@localhost software]# ls /opt/module/env
jdk1.8.0_131
2 jre目录以及子目录授予root权限
[root@localhost /]# chown root:root -R /opt/module/env/jdk1.8.0_131/
3 配置环境变量
[root@localhost /]# vi /etc/profile
i 进入编辑模式,在文件末尾加入下面代码
#JAVA_HOME
export JAVA_HOME=/opt/module/env
export JRE_HOME=/opt/module/env/jdk1.8.0_131/
export CLASSPATH=$JRE_HOME/lib/rt.jar:$JRE_HOME/lib/ext
export PATH=$PATH:$JRE_HOME/bin
强制保存(wq!)退出
[root@localhost /]# source /etc/profile
4 测试
[root@localhost software]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
4 Tomcat 部署
1 解压以及剪切到/opt/module/env/目录
[root@localhost /]# cd /opt/module/software/
[root@localhost software]# [root@localhost software]# tar -zxvf apache-tomcat-8.5.16.tar.gz -C /opt/module/env
[root@localhost software]# ll /opt/module/env
总用量 0
drwxr-xr-x. 9 root root 160 12月 9 14:45 apache-tomcat-8.5.16
drwxr-xr-x. 7 10 143 166 3月 15 2017 jdk1.8.0_131
2 项目war包上传到 /opt/module/env/apache-tomcat-8.5.16/webapps/
[root@localhost software]# cd /opt/module/env/apache-tomcat-8.5.16/webapps/
[root@localhost webapps]# ll
总用量 75736
drwxr-x---. 14 root root 4096 12月 9 14:45 docs
drwxr-x---. 6 root root 83 12月 9 14:45 examples
-rw-r--r--. 1 root root 77541800 12月 9 14:47 G5S.war
drwxr-x---. 5 root root 87 12月 9 14:45 host-manager
drwxr-x---. 5 root root 103 12月 9 14:45 manager
drwxr-x---. 3 root root 4096 12月 9 14:45 ROOT
2 启动服务
[root@localhost webapps]# cd /opt/module/env/apache-tomcat-8.5.16/bin
[root@localhost bin]# ./startup.sh
3 查看实时日志
[root@localhost bin]# tail -f ../logs/catalina.out
4 停止服务
[root@localhost bin]# ./shutdown.sh
5 服务信息
服务 tomcat
版本 8.5.16
5 Docker 部署
5.1 docker
1 安装docker服务
[root@localhost bin]# cd /opt/module/software/docker
[root@localhost docker]# rpm -ivh *.rpm
2 启动docker服务
[root@localhost bin]# systemctl start docker
3 设置开机启动
[root@localhost bin]# systemctl enable docker
4 查看docker镜像和容器
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5.2 mysql
1 导入mysql镜像
[root@localhost docker]# docker load -i /opt/module/software/jingxiang/mysql57.tar
99b5261d397c: Loading layer [==================================================>] 58.51 MB/58.51 MB
5a8a245abd1c: Loading layer [==================================================>] 338.4 kB/338.4 kB
51734435c93c: Loading layer [==================================================>] 10.44 MB/10.44 MB
6599033b2ab2: Loading layer [==================================================>] 4.472 MB/4.472 MB
414373ffccb4: Loading layer [==================================================>] 1.536 kB/1.536 kB
2a9aab74013a: Loading layer [==================================================>] 46.15 MB/46.15 MB
7055b7f82e4c: Loading layer [==================================================>] 34.3 kB/34.3 kB
398ef8a407f7: Loading layer [==================================================>] 3.584 kB/3.584 kB
fc12e028de3b: Loading layer [==================================================>] 321.7 MB/321.7 MB
934de0c0816e: Loading layer [==================================================>] 15.87 kB/15.87 kB
94a471180601: Loading layer [==================================================>] 1.536 kB/1.536 kB
Loaded image: mysql:5.7
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 1e4405fe1ea9 2 weeks ago 437 MB
2 创建容器
[root@localhost docker]# docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
1fcf644fb24c4731f70ca66edc96847452e898de7612de05b4dd188b3965883c
run 运行一个docker容器
--name 后面这个是生成的容器的名字mysql
-p 3306:3306 表示这个容器中使用3306(第二个)映射到本机的端口号也为3306(第一个)
-e MYSQL_ROOT_PASSWORD=123456 初始化root用户的密码
-d 表示使用守护进程运行,即服务挂在后台
[root@localhost docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fcf644fb24c mysql:5.7 "docker-entrypoint..." 25 seconds ago Up 23 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
3 允许外部访问
# 进入容器
[root@localhost docker]# docker exec -it mysql /bin/bash
root@1fcf644fb24c:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
mysql> flush privileges;
mysql> exit;
Bye
root@1fcf644fb24c:/# exit;
exit
4 启动服务
[root@localhost docker]# docker start mysql
5 停止服务
[root@localhost docker]# docker stop mysql
6 服务信息
服务 mysql
版本 5.7
用户名 root
密码 123456
5.3 oracle
1 导入oracle镜像
[root@localhost docker]# docker load -i /opt/module/software/jingxiang/oralce11.tar
2 创建目录
[root@localhost docker]# mkdir /usr/local/data_temp
3 目录授权
[root@localhost docker]# chown -R 500.500 /usr/local/data_temp
4 创建容器
[root@localhost docker]# docker run -d --name oracle_11g -p 1521:1521 -v /usr/local/data_temp:/home/oracle/data_temp registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
5 进入容器
docker exec -it oracle_11g /bin/bash
6 进入oracle
sqlplus / as sysdba
7 创建表空间
SQL> create tablespace art datafile '/home/oracle/app/oracle/oradata/helowin/art.dbf' size 2G reuse autoextend on next 500M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
8 创建用户
SQL> create user art identified by art default tablespace art temporary tablespace TEMP;
9 用户授权
SQL> grant connect,dba,exp_full_database,imp_full_database to art with admin option;
10 启动服务
[root@localhost docker]# docker start mysql
11 停止服务
[root@localhost docker]# docker stop mysql
12 服务信息
服务 oralce
版本 11g
用户名 art
密码 art
SID helowin
5.4 vsftpd
1 导入vsftpd镜像
[root@localhost docker]# docker load -i /opt/module/software/jingxiang/vsftpd.tar
877b494a9f30: Loading layer [==================================================>] 209.6 MB/209.6 MB
a46f0c7ca3c8: Loading layer [==================================================>] 172.2 MB/172.2 MB
22f671826867: Loading layer [==================================================>] 23.49 MB/23.49 MB
6cc225f59894: Loading layer [==================================================>] 4.096 kB/4.096 kB
0052d9bc8a4f: Loading layer [==================================================>] 4.096 kB/4.096 kB
c7808a67a688: Loading layer [==================================================>] 3.072 kB/3.072 kB
50b94c50063d: Loading layer [==================================================>] 5.12 kB/5.12 kB
a47ee865a785: Loading layer [==================================================>] 5.12 kB/5.12 kB
a121039d5576: Loading layer [==================================================>] 2.048 kB/2.048 kB
fb3a6363e76e: Loading layer [==================================================>] 2.048 kB/2.048 kB
Loaded image: docker.io/fauria/vsftpd:latest
2 新建ftp文件存储目录/home/ftp
[root@localhost home]# cd /home && mkdir ftp
3 创建一个组,用于存放ftp用户
[root@localhost home] groupadd ftpgroups
4 创建ftp用户,并加入ftpgroups组
[root@localhost home] useradd -d /home/ftp/ftpuser -g ftpgroups ftpuser
5 设置密码
[root@localhost home] passwd ftpuser
ftpuser
6 设置不允许用于用户登录
[root@localhost home] usermod -s /sbin/nologin ftpuser
7 目录授权
[root@localhost home] chown ftpuser:ftpgroups -R /home/ftp
8 创建容器
[root@localhost home] docker run -d -v /home/ftp:/home/vsftpd -p 20:20 -p 21:21 -p 21100-21110:21100-21110 -e FTP_USER=ftpuser -e FTP_PASS=ftpuser --name vsftpd fauria/vsftpd
9 启动服务
[root@localhost docker]# docker start vsftpd
10 停止服务
[root@localhost docker]# docker stop vsftpd
11 服务信息
服务 vsftpd
用户名 ftpuser
密码 ftpuser
目录 /home/ftp
5.5 nginx
1 导入nginx镜像
[root@localhost home]# docker load -i /opt/module/software/jingxiang/nginx.tar
831c5620387f: Loading layer [==================================================>] 72.48 MB/72.48 MB
5fb987d2e54d: Loading layer [==================================================>] 57.67 MB/57.67 MB
4fc1aa8003a3: Loading layer [==================================================>] 3.584 kB/3.584 kB
Loaded image: docker.io/nginx:latest
2 创建容器
[root@localhost home]# docker run -p 80:80 --name nginx -d nginx
2 映射目录
[root@localhost home]# docker cp -a nginx:/etc/nginx/ /opt/module/env/nginx/conf
[root@localhost home]# docker stop nginx
[root@localhost home]# docker rm nginx
[root@localhost home]# docker run -p 80:80 --privileged=true --restart always --name nginx -v /opt/module/env/nginx/www:/www -v /opt/module/env/nginx/conf/:/etc/nginx/ -v /opt/module/env/nginx/logs:/var/log/nginx -v /opt/module/env/nginx/wwwlogs:/wwwlogs -d nginx
[root@localhost home]# docker restart nginx
3 配置nginx
[root@localhost ~]# vi /opt/module/env/nginx/conf/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
# root /usr/share/nginx/html;
root /home/ftp/;
index index.html index.htm;
}
...
4 启动服务
[root@localhost home]# docker start nginx
5 停止服务
[root@localhost home]# docker stop nginx
6 服务信息
服务 nginx
目录 /opt/module/env/nginx/conf/