将商城项目放到docker-centos7中

1、docker pull centos:7 

2、docker run -d -it --privileged  仓库名称/shopcentos:1.1 /usr/sbin/init

 注意: /usr/sbin/init 必须加,否则没法使用systemctl启动mysql 

3、安装mysql教程
安装msyql教程:https://blog.csdn.net/davice_li/article/details/129294554
yum安装mysql8 秘钥问题执行命令: rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
修改密码:alter user 'root'@'localhost' identified by 'MySQL@666';

注意在启动数据库之前,必须要先把数据库配置文件搞好,否则没有办法大小写

my.cnf配置如下:
 

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
 
[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
 
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
 
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 
 
# 设置为 False, 在客户端字符集和服务端字符集不同的时候将拒绝连接到服务端执行任何操作
character-set-client-handshake=FALSE
# 声明服务端的字符编码
character-set-server=utf8mb4
# 声明服务端的字符集
collation-server=utf8mb4_general_ci
# 声明使用的是 utf8mb4 的字符编码
init_connect='SET NAMES utf8mb4'
 
# 表名忽略大小写
lower_case_table_names=1
 
# 永久关闭only_full_group_by模式
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
 
# 开启bin-log日志
server-id=1
log-bin=/var/lib/mysql/mysql-bin
binlog-format=ROW
 
# 开启慢查询日志
slow_query_log = 1
# 指定慢查询日志路径
slow_query_log_file = /var/lib/mysql/slow-query.log
# 表示查询时间>=1秒才记录日志
long_query_time = 5
# 表明记录没有使用索引的 SQL 语句
log_queries_not_using_indexes = 1

4、映射出来mysql端口:
docker run -p 4306:3306 -d -it --privileged  beginnerwj/shopcentos:1.1 /usr/sbin/init

5、导入数据库

6、配置jdk环境变量
 

#set java environment
JAVA_HOME=/opt/appserver/jdk1.8.0_161
JRE_HOME=/opt/appserver/jdk1.8.0_161/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

7、安装redis:
  教程:https://dgrt.cn/a/2241828.html?action=onClick

详解Centos7下配置Redis并开机自启动 - Python技术站
8、redis默认密码 foobared

9、配置nacos
     坑:No DataSource set 报错,一定要认真检查 数据库连接信息。ip端口用户名密码以及数据库名称----被自己无脑坑死
      配置nacos自启动:linux nacos自启动_liunx nacos 后台启动_Mr-Wanter的博客-CSDN博客

10、映射外部nacos端口启动方式:
docker run -p 4306:3306 -p 7480:6379 -p 8849:8848 -d -it --privileged  beginnerwj/shopcentos:1.4 /usr/sbin/init
11、容器启动时,会把/etc/hosts覆盖。所以写了一个脚本每次开机或者运行时,重置hosts
     

#!/bin/bash
cp /etc/hosts /etc/hosts.bak
#add ip
echo "127.0.0.1 nacos" >> /etc/hosts
echo "127.0.0.1 gateway" >> /etc/hosts
echo "127.0.0.1 redis" >> /etc/hosts
echo "127.0.0.1 mysql" >> /etc/hosts
source /etc/hosts

自启动执行脚本教程链接:CentOS7如何设置开机自启动程序、开机自启动脚本?_centos开机自启动脚本_Dontla的博客-CSDN博客

12、安装nginx-nginx下载地址:nginx: download

13、安装nginx教程地址:Nginx源码包安装详解_nginx 源码安装_pass99vs的博客-CSDN博客

14、设置nginx开机自启动:将nginx设置为开机自启动的配置_nginx设置开机自启动_健康平安的活着的博客-CSDN博客

15、启动jar
       同设置hosts一样。写一个脚本。但是要先把java环境变量先设置一下,并且进入到目录中才行
       source ~/.bashrc
       cd /opt/server && sh  startup.sh 

你可能感兴趣的:(docker,容器,运维)