docker单节点搭建在线商城

news2024/11/19 17:28:45

本文档使用到的软件包以上传到资源中

目录

1.  创建容器并配置基础内容

1.1  将gpmall-repo上传到容器中

1.2  添加yum源

2.  安装基础服务

2.1  安装JAVA环境

2.2  安装Redis缓存服务

2.3  安装Elasticsearch服务

2.4  安装Nginx服务

2.5  安装MariaDB数据库

2.6  安装zookeeper服务

2.7  安装kafka服务

3.  开启服务

3.1  启动MariaDB数据库

3.2  启动redis服务

3.3  启动Elasticsearch

3.4  启动nginx

4.  部署

4.1  部署前端

4.2  部署后端

登录验证


1.  创建容器并配置基础内容

可以直接docker pull centos:7

我这里用的是自己做的镜像,放资源中了,可前往查看

[root@wq images_docker]# docker load -i CentOS7_1804.tar
4826cdadf1ef: Loading layer [==================================================>]  207.8MB/207.8MB
14373f3a403e: Loading layer [==================================================>]  173.8MB/173.8MB
5ac0fc2030b4: Loading layer [==================================================>]  6.656kB/6.656kB
d4ce7d7d577a: Loading layer [==================================================>]  6.144kB/6.144kB
ee747055941b: Loading layer [==================================================>]  6.656kB/6.656kB
d0d06aa60ad3: Loading layer [==================================================>]   5.12kB/5.12kB
b3f3bc1666f9: Loading layer [==================================================>]  5.632kB/5.632kB
9692fa18f16b: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: centos7:1804

[root@wq ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
centos7           1804      8c1f6d23d72e   4 years ago    370MB

[root@wq ~]# docker run -d --name mall -p 8045:80 centos7:1804
b2581295b40b15eb117f07fc221e91ed02ed91d7f1d145a69841c52e469ea82c

[root@wq ~]# docker ps
CONTAINER ID   IMAGE          COMMAND               CREATED         STATUS        PORTS                                           NAMES
b2581295b40b   centos7:1804   "/usr/sbin/sshd -D"   3 seconds ago   Up 1 second   22/tcp, 0.0.0.0:8045->80/tcp, :::8045->80/tcp   mall

1.1  将gpmall-repo上传到容器中

 先将gpmall上传到服务器或者虚拟中

[root@wq ~]# docker ps
CONTAINER ID   IMAGE          COMMAND               CREATED         STATUS        PORTS                                           NAMES
b2581295b40b   centos7:1804   "/usr/sbin/sshd -D"   3 seconds ago   Up 1 second   22/tcp, 0.0.0.0:8045->80/tcp, :::8045->80/tcp   mall
[root@wq ~]# docker cp /root/gpmall-repo b2581295b40b:/root
Successfully copied 323MB to b2581295b40b:/root

/etc/hosts配置文件如下

1.2  添加yum源

[root@b2581295b40b ~]# cd /etc/yum.repos.d/
[root@b2581295b40b yum.repos.d]# ll
total 32
-rw-r--r-- 1 root root 1664 May 17  2018 CentOS-Base.repo
-rw-r--r-- 1 root root 1309 May 17  2018 CentOS-CR.repo
-rw-r--r-- 1 root root  649 May 17  2018 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  630 May 17  2018 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 May 17  2018 CentOS-Sources.repo
-rw-r--r-- 1 root root 4768 May 17  2018 CentOS-Vault.repo
-rw-r--r-- 1 root root  314 May 17  2018 CentOS-fasttrack.repo
[root@b2581295b40b yum.repos.d]# vi local.repo
[root@b2581295b40b yum.repos.d]# yum clean all && yum repolist
Loaded plugins: fastestmirror, ovl
Cleaning repos: base extras mall updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                            | 3.6 kB  00:00:00
extras                                                                          | 2.9 kB  00:00:00
mall                                                                            | 2.9 kB  00:00:00
updates                                                                         | 2.9 kB  00:00:00
(1/5): mall/primary_db                                                          | 144 kB  00:00:00
(2/5): extras/7/x86_64/primary_db                                               | 250 kB  00:00:00
(3/5): base/7/x86_64/group_gz                                                   | 153 kB  00:00:00
(4/5): base/7/x86_64/primary_db                                                 | 6.1 MB  00:00:01
(5/5): updates/7/x86_64/primary_db                                              |  25 MB  00:00:05
repo id                                        repo name                                         status
base/7/x86_64                                  CentOS-7 - Base                                   10072
extras/7/x86_64                                CentOS-7 - Extras                                   519
mall                                           mall                                                165
updates/7/x86_64                               CentOS-7 - Updates                                 5766
repolist: 16522

2.  安装基础服务

2.1  安装JAVA环境

[root@b2581295b40b yum.repos.d]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@b2581295b40b yum.repos.d]# java -version
openjdk version "1.8.0_402"
OpenJDK Runtime Environment (build 1.8.0_402-b06)
OpenJDK 64-Bit Server VM (build 25.402-b06, mixed mode)

2.2  安装Redis缓存服务

[root@b2581295b40b yum.repos.d]#yum install -y redis

2.3  安装Elasticsearch服务

[root@b2581295b40b yum.repos.d]# yum install -y elasticsearch

2.4  安装Nginx服务

[root@b2581295b40b yum.repos.d]# yum install -y nginx

2.5  安装MariaDB数据库

[root@b2581295b40b yum.repos.d]# yum install -y mariadb mariadb-server

2.6  安装zookeeper服务

上传zookeeper包到服务器或者虚拟机中

[root@wq ~]# ll
total 1113272
drwxr-xr-x 5 root root       4096 Mar  5 19:46 gpmall-repo
-rw-r--r-- 1 root root   37676320 Mar  5 20:12 zookeeper-3.4.14.tar.gz

[root@wq ~]# docker cp zookeeper-3.4.14.tar.gz b2581295b40b:/root/
Successfully copied 37.7MB to b2581295b40b:/root/


# 容器内查看
[root@b2581295b40b yum.repos.d]# ll /root
total 36804
-rw------- 1 root root     3302 May 31  2018 anaconda-ks.cfg
drwxr-xr-x 5 root root     4096 Mar  5 11:46 gpmall-repo
-rw-r--r-- 1 root root 37676320 Mar  5 12:12 zookeeper-3.4.14.tar.gz

解压

[root@b2581295b40b yum.repos.d]# tar -zxvf /root/zookeeper-3.4.14.tar.gz
zookeeper-3.4.14/
zookeeper-3.4.14/bin/
zookeeper-3.4.14/bin/README.txt
zookeeper-3.4.14/bin/zkCleanup.sh
zookeeper-3.4.14/bin/zkCli.cmd
zookeeper-3.4.14/bin/zkCli.sh
zookeeper-3.4.14/bin/zkEnv.cmd
zookeeper-3.4.14/bin/zkEnv.sh

[root@b2581295b40b yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo  zookeeper-3.4.14
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo    local.repo

# 放到/opt目录下
[root@b2581295b40b yum.repos.d]# mv zookeeper-3.4.14 /opt
[root@b2581295b40b yum.repos.d]# cd /opt
[root@b2581295b40b opt]# ll
total 4
drwxr-xr-x 14 2002 2002 4096 Mar  6  2019 zookeeper-3.4.14

[root@b2581295b40b opt]# cd zookeeper-3.4.14/conf/
[root@b2581295b40b conf]# pwd
/opt/zookeeper-3.4.14/conf
[root@b2581295b40b conf]# mv zoo_sample.cfg zoo.cfg
[root@b2581295b40b conf]# ll
total 12
-rw-rw-r-- 1 2002 2002  535 Mar  6  2019 configuration.xsl
-rw-rw-r-- 1 2002 2002 2161 Mar  6  2019 log4j.properties
-rw-rw-r-- 1 2002 2002  922 Mar  6  2019 zoo.cfg

启动服务

[root@b2581295b40b conf]# cd ../bin/
[root@b2581295b40b bin]# pwd
/opt/zookeeper-3.4.14/bin
[root@b2581295b40b bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@b2581295b40b bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone

2.7  安装kafka服务

上传kafka包到服务器或者虚拟机中,并上传到容器中

[root@wq ~]# ll
total 1169400
drwxr-xr-x 5 root root       4096 Mar  5 19:46 gpmall-repo
-rw-r--r-- 1 root root   57471165 Mar  5 20:20 kafka_2.11-1.1.1.tgz
-rw-r--r-- 1 root root   37676320 Mar  5 20:12 zookeeper-3.4.14.tar.gz

# 上传到容器中
[root@wq ~]# docker cp kafka_2.11-1.1.1.tgz b2581295b40b:/root
Successfully copied 57.5MB to b2581295b40b:/root

解压

[root@b2581295b40b bin]# cd /opt
[root@b2581295b40b opt]# pwd
/opt
[root@b2581295b40b opt]#
[root@b2581295b40b opt]# tar -zxvf /root/kafka_2.11-1.1.1.tgz
kafka_2.11-1.1.1/
kafka_2.11-1.1.1/LICENSE
kafka_2.11-1.1.1/NOTICE
kafka_2.11-1.1.1/bin/
kafka_2.11-1.1.1/bin/kafka-preferred-replica-election.sh
kafka_2.11-1.1.1/bin/connect-standalone.sh
kafka_2.11-1.1.1/bin/kafka-server-start.sh

开启服务中查看

[root@b2581295b40b opt]# cd kafka_2.11-1.1.1/bin/
[root@b2581295b40b bin]# pwd
/opt/kafka_2.11-1.1.1/bin

[root@b2581295b40b bin]# ./kafka-server-start.sh -daemon ../config/server.properties
[root@b2581295b40b bin]# jps
501 QuorumPeerMain
815 Kafka
879 Jps

# 下载工具
[root@b2581295b40b bin]# yum install -y net-tools
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.24.20131004git.el7 will be updated
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================
 Package                    Arch                    Version                                     Repository             Size
============================================================================================================================
Updating:
 net-tools                  x86_64                  2.0-0.25.20131004git.el7                    base                  306 k

Transaction Summary
============================================================================================================================
Upgrade  1 Package

Total download size: 306 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                        | 306 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                1/2
  Cleanup    : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                2/2
  Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                1/2
  Verifying  : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                2/2

Updated:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7

Complete!

[root@b2581295b40b bin]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:9092            0.0.0.0:*               LISTEN      815/java
tcp        0      0 0.0.0.0:2181            0.0.0.0:*               LISTEN      501/java
tcp        0      0 0.0.0.0:46029           0.0.0.0:*               LISTEN      501/java
tcp        0      0 0.0.0.0:34929           0.0.0.0:*               LISTEN      815/java
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1/sshd

3.  开启服务

3.1  启动MariaDB数据库

[root@b2581295b40b ~]# /etc/init.d/mysql start
Starting MariaDB.240305 12:29:48 mysqld_safe Logging to '/var/lib/mysql/b2581295b40b.err'.
240305 12:29:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
 SUCCESS!

进行初始化,并设置密码

[root@b2581295b40b ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

登录数据库设置权限

[root@b2581295b40b ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.18-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.000 sec)

上传gpmall.sql文件到服务器或者虚拟机,再cp到容器中

[root@wq ~]# ll
total 1169460
drwxr-xr-x 5 root root       4096 Mar  5 19:46 gpmall-repo
-rw-r--r-- 1 root root      59239 Mar  5 20:33 gpmall.sql
-rw-r--r-- 1 root root      35095 Dec 19 16:03 install.sh
-rw-r--r-- 1 root root   57471165 Mar  5 20:20 kafka_2.11-1.1.1.tgz
-rw------- 1 root root 1102262784 Feb 27 14:49 mysql.tar
-rw-r--r-- 1 root root   37676320 Mar  5 20:12 zookeeper-3.4.14.tar.gz
[root@wq ~]# docker cp gpmall.sql b2581295b40b:/root
Successfully copied 60.9kB to b2581295b40b:/root

导入数据

MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> use gpmall;
Database changed
MariaDB [gpmall]> source /root/gpmall.sql
Query OK, 0 rows affected (0.000 sec)

Query OK, 0 rows affected (0.000 sec)

Query OK, 0 rows affected, 1 warning (0.002 sec)

Query OK, 0 rows affected (0.010 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.010 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.041 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.004 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.010 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.015 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.019 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.018 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.018 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.015 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.014 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.013 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.003 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.067 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 0 rows affected, 1 warning (0.001 sec)

Query OK, 0 rows affected (0.013 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.010 sec)

Query OK, 0 rows affected, 1 warning (0.000 sec)

Query OK, 0 rows affected (0.011 sec)

Query OK, 1 row affected (0.002 sec)

Query OK, 0 rows affected (0.000 sec)

MariaDB [gpmall]> Ctrl-C -- exit!
Aborted

3.2  启动redis服务

[root@b2581295b40b ~]# redis-server
1446:C 05 Mar 12:39:50.357 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.12 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1446
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1446:M 05 Mar 12:39:50.359 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1446:M 05 Mar 12:39:50.359 # Server started, Redis version 3.2.12
1446:M 05 Mar 12:39:50.359 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1446:M 05 Mar 12:39:50.359 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1446:M 05 Mar 12:39:50.359 * DB loaded from disk: 0.000 seconds
1446:M 05 Mar 12:39:50.359 * The server is now ready to accept connections on port 6379

查看是否成功启动:新建终端进入容器,查看端口

[root@wq ~]# docker exec -it b2581295b40b /bin/bash
[root@b2581295b40b /]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:9092            0.0.0.0:*               LISTEN      815/java
tcp        0      0 0.0.0.0:2181            0.0.0.0:*               LISTEN      501/java
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      1446/redis-server *
tcp        0      0 0.0.0.0:46029           0.0.0.0:*               LISTEN      501/java
tcp        0      0 0.0.0.0:34929           0.0.0.0:*               LISTEN      815/java
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1/sshd
tcp6       0      0 :::3306                 :::*                    LISTEN      -
tcp6       0      0 :::6379                 :::*                    LISTEN      1446/redis-server *
tcp6       0      0 :::22                   :::*                    LISTEN      1/sshd

3.3  启动Elasticsearch

添加三行内容到最上面

[root@b2581295b40b /]# vi /etc/elasticsearch/elasticsearch.yml
[root@b2581295b40b /]# head -n 3 /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true

找到以下内容,去掉注释,并将network.host写自己主机的ip地址

cluster.name: my-application
node.name: node-1
network.host: 172.16.51.29
http.port: 920
[root@b2581295b40b /]# adduser elasticsearch
adduser: user 'elasticsearch' already exists

[root@b2581295b40b /]# mkdir /home/elasticsearch
[root@b2581295b40b /]# chown elasticsearch:elasticsearch /home/elasticsearch
[root@b2581295b40b /]# sudo chown -R elasticsearch:elasticsearch /var/log/elasticsearch/
[root@b2581295b40b /]# su - elasticsearch -s /bin/bash -c '/usr/share/elasticsearch/bin/elasticsearch'

3.4  启动nginx

[root@b2581295b40b opt]# /usr/sbin/nginx

4.  部署

将五个文件上传到服务器或虚拟机中,然后docker cp到容器中

[root@wq ~]# ll
total 1368780
drwxr-xr-x 5 root root       4096 Mar  5 19:46 gpmall-repo
-rw-r--r-- 1 root root   47765224 Mar  5 21:01 gpmall-shopping-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root      59239 Mar  5 20:33 gpmall.sql
-rw-r--r-- 1 root root   39005468 Mar  5 21:01 gpmall-user-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root   57471165 Mar  5 20:20 kafka_2.11-1.1.1.tgz
-rw-r--r-- 1 root root   54936064 Mar  5 21:01 shopping-provider-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root   62386947 Mar  5 21:01 user-provider-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root   37676320 Mar  5 20:12 zookeeper-3.4.14.tar.gz

[root@wq ~]# docker cp shopping-provider-0.0.1-SNAPSHOT.jar b2581295b40b:/root
Successfully copied 54.9MB to b2581295b40b:/root

[root@wq ~]# docker cp user-provider-0.0.1-SNAPSHOT.jar b2581295b40b:/root
Successfully copied 62.4MB to b2581295b40b:/root

[root@wq ~]# docker cp gpmall-user-0.0.1-SNAPSHOT.jar b2581295b40b:/root
Successfully copied 39MB to b2581295b40b:/root

[root@wq ~]# docker cp gpmall-shopping-0.0.1-SNAPSHOT.jar b2581295b40b:/root
Successfully copied 47.8MB to b2581295b40b:/root

[root@wq ~]# docker cp  dist  b2581295b40b:/root
Successfully copied 11.5MB to b2581295b40b:/root

容器中查看

[root@b2581295b40b opt]# ll /root/
total 292324
-rw------- 1 root root     3302 May 31  2018 anaconda-ks.cfg
drwxr-xr-x 3 root root     4096 Mar  5 13:03 dist
-rw-r--r-- 1 root root       77 Mar  5 12:39 dump.rdb
drwxr-xr-x 5 root root     4096 Mar  5 11:46 gpmall-repo
-rw-r--r-- 1 root root 47765224 Mar  5 13:01 gpmall-shopping-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root 39005468 Mar  5 13:01 gpmall-user-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root    59239 Mar  5 12:33 gpmall.sql
-rw-r--r-- 1 root root 57471165 Mar  5 12:20 kafka_2.11-1.1.1.tgz
-rw-r--r-- 1 root root 54936064 Mar  5 13:01 shopping-provider-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root 62386947 Mar  5 13:01 user-provider-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root 37676320 Mar  5 12:12 zookeeper-3.4.14.tar.gz

添加hosts

[root@b2581295b40b ~]# cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      b2581295b40b
172.17.0.2      kafka.b2581295b40b
172.17.0.2      mysql.b2581295b40b
172.17.0.2      redis.b2581295b40b
172.17.0.2      zookeeper.b2581295b40b

4.1  部署前端

[root@b2581295b40b ~]# rm -rf /usr/share/nginx/html/*
[root@b2581295b40b ~]# cp -rvf dist/* /usr/share/nginx/html/
'dist/index.html' -> '/usr/share/nginx/html/index.html'
'dist/static' -> '/usr/share/nginx/html/static'
'dist/static/fonts' -> '/usr/share/nginx/html/static/fonts'
'dist/static/fonts/element-icons.b02bdc1.ttf' -> '/usr/share/nginx/html/static/fonts/element-icons.b02bdc1.ttf'
'dist/static/svg' -> '/usr/share/nginx/html/static/svg'
'dist/static/svg/search.svg' -> '/usr/share/nginx/html/static/svg/search.svg'
'dist/static/svg/shop.svg' -> '/usr/share/nginx/html/static/svg/shop.svg'
'dist/static/svg/arrow.svg' -> '/usr/share/nginx/html/static/svg/arrow.svg'

编辑配置文件

[root@b2581295b40b ~]# vi /etc/nginx/conf.d/default.conf
[root@b2581295b40b ~]# cat /etc/nginx/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;
        index  index.html index.htm;
    }
    location /user {
        proxy_pass http://127.0.0.1:8082;
    }
    location /shopping {
        proxy_pass http://127.0.0.1:8081;
    }


    #error_page  404              /404.html;

重启nginx服务

[root@b2581295b40b ~]# ps aux |grep nginx
root      1704  0.0  0.0  46432   976 ?        Ss   12:55   0:00 nginx: master process /usr/sbin/nginx
nginx     1705  0.0  0.1  46844  1932 ?        S    12:55   0:00 nginx: worker process
root      1719  0.0  0.0   9088   664 pts/2    S+   13:15   0:00 grep --color=auto nginx
[root@b2581295b40b ~]#
[root@b2581295b40b ~]# kill -HUP 1704
[root@b2581295b40b ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:9092            0.0.0.0:*               LISTEN      815/java
tcp        0      0 0.0.0.0:2181            0.0.0.0:*               LISTEN      501/java
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      1446/redis-server *
tcp        0      0 0.0.0.0:46029           0.0.0.0:*               LISTEN      501/java
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1704/nginx: master
tcp        0      0 0.0.0.0:34929           0.0.0.0:*               LISTEN      815/java
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1/sshd
tcp6       0      0 :::3306                 :::*                    LISTEN      -
tcp6       0      0 :::6379                 :::*                    LISTEN      1446/redis-server *
tcp6       0      0 :::22                   :::*                    LISTEN      1/sshd

4.2  部署后端

[root@b2581295b40b ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[1] 1724
[root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'

[root@b2581295b40b ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 1773
[1]   Exit 1                  nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar
[root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'

[root@b2581295b40b ~]#
[root@b2581295b40b ~]#
[root@b2581295b40b ~]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[3] 1821
[2]   Exit 1                  nohup java -jar user-provider-0.0.1-SNAPSHOT.jar
[root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'

[root@b2581295b40b ~]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4] 1842
[root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'

登录验证

浏览器进行访问   ip地址:端口号

 单击右上角“头像”,进行登录操作,使 用用户名/密码为test/test进行登录

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1491872.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

积分商城管理系统的设计与实现(含源文件)

项目源码:https://gitee.com/oklongmm/biye2 系统介绍: 积分商城管理系统,包括用户模块、商品模块、积分模块和后台管理模块。 一、用户模块: 用户注册与登录:用户可以创建账户并登录系统。 个人信息管理&#xff1…

android开发教程视频,android组件化和插件化

第一阶段:Android 基础知识回顾: 回顾Android 开发编程,深入理解Android系统原理和层次结构,深入分析Handler源码和原理;回顾Java,C/C,Kotlin、dart 在Android开发中必用的语言,熟悉…

四平方和 刷题笔记

/* 四平方和 直接暴力搜索 可能会超时 使用二分辅助搜索 先枚举出 c*cd*d并存入数组 用式子算出 a*ab*b还剩下多少查找sum数组里面是否存在符合条件的数 查找方式使用二分搜索 当逼近答案后 检查一下是否为所需的数 如果是 直接输出 */ #include <cstring> #includ…

分布式数字身份:通往Web3.0世界的个人钥匙

数字化时代&#xff0c;个人身份已不再仅仅局限于传统形式&#xff0c;分布式数字身份&#xff08;Decentralized Identity&#xff0c;简称DID&#xff09;正崭露头角&#xff0c;它允许个人通过数字签名等加密技术&#xff0c;完全掌握和控制自己的身份信息。研究报告显示&am…

展台模型设计过程中会遇到那些问题?---模大狮模型网

在展台模型设计过程中&#xff0c;可能会遇到一些常见问题&#xff0c;包括但不限于&#xff1a; 一&#xff1a;空间规划问题 设计师需要确保展台布局合理&#xff0c;能够满足参展方的需求&#xff0c;同时还要考虑观众流线和空间利用效率。解决方法包括对空间进行良好的规划…

如何选择程序员职业赛道

目录 前言1 个人技能分析1.1 技术栈评估1.2 经验积累1.3 数据科学能力 2 兴趣与价值观2.1 用户交互与界面设计2.2 复杂问题解决与系统优化 3 长期目标规划4 市场需求分析4.1 人工智能和云计算4.2 前沿技术趋势 5 就业前景5.1 前端在创意性公司中的应用5.2 后端在大型企业中的广…

pytest 教程

1. 安装pytest 目前我使用的python版本是3.10.8 pip install pytest命令会安装下面的包&#xff1a; exceptiongroup-1.2.0-py3-none-any.whl iniconfig-2.0.0-py3-none-any.whl packaging-23.2-py3-none-any.whl pluggy-1.4.0-py3-none-any.whl pytest-8.0.2-py3-none-any.…

总线要点笔记

1. AXI/AHB/APB差异 AMBA (Advanced Microcontroller Bus Architecture) 高级处理器总线架构 AHB (Advanced High-performance Bus) 高级高性能总线 ASB (Advanced System Bus) 高级系统总线 APB (Advanced Peripheral Bus) 高级外围总线 AXI (Advanced eXtensible Interface) …

无名管道数据交换

#include<stdio.h> #include <sys/types.h> #include <sys/stat.h> #include<errno.h> #include <unistd.h> #include<fcntl.h> #include<string.h>int main(int argc, const char *argv[]) {//开辟写入管道1if(mkfifo("./AAA&…

【C语言】指针超级无敌金刚霹雳进阶(但不难,还是基础)

点击这里访问我的博客主页~~ 对指针概念还不太清楚的点击这里访问上一篇指针初阶2.0 上上篇指针初阶1.0 谢谢各位大佬的支持咯 今天我们一起来学习指针进阶内容 指针进阶 一、指针变量1、字符指针变量2、数组指针变量①数组指针变量的定义②数组指针变量的初始化 3、函数指…

数字化转型导师坚鹏:成为数字化转型顾问 引领数字化美好未来

成为数字化转型顾问 引领数字化美好未来 ——数字化人才与企业的共赢之路 数字经济新时代&#xff0c;中国企业向数字化转型要效益&#xff1b; 转型顾问创未来&#xff0c;职场精英借数字化转型成良师。 我们中国政府特别重视数字经济发展及数字化人才培养。早在2020年8月2…

c++ primer学习笔记(二)

目录 第三章 一、命名空间的using声明 二、标准库的string类型 1、string对象的定义和初始化 2、string对象的读写 3、string对象的操作 4、string对象中字符的处理 三、标准库的vector类型 1、vector对象的定义和初始化 2、vector对象的操作 四、迭代器简介 1、简…

android开发框架mvp,Android面试心得必备技能储备详解

面试复习路线图 我之前复习&#xff0c;大多都在20点以后&#xff0c;因为晚上比较能集中注意力&#xff0c;制定一个学习计划&#xff0c;切勿零散的复习&#xff0c;最好是系统的复习&#xff0c;才能胜却在握 主要内容如下&#xff1a; BAT的面试题目相关性能优化相关相关…

App自动化测试笔记(一):搭建环境

一、三个环境 1、android模拟器&#xff1a;模拟安卓手机 2、androidSDK:android SDK给你提供开发测试所必须android API类库 3、java&#xff1a;android底层是c、c语言&#xff0c;应用层是java语言 二、java环境搭建 java安装 安装jdk-8u151-windows-x64.exe 配置环境变量…

小程序常用样式和组件

常用样式和组件 1. 组件和样式介绍 在开 Web 网站的时候&#xff1a; 页面的结构由 HTML 进行编写&#xff0c;例如&#xff1a;经常会用到 div、p、 span、img、a 等标签 页面的样式由 CSS 进行编写&#xff0c;例如&#xff1a;经常会采用 .class 、#id 、element 等选择器…

Stable Diffusion 模型分享:CG texture light and shadow(CG纹理光影)

本文收录于《AI绘画从入门到精通》专栏&#xff0c;专栏总目录&#xff1a;点这里。 文章目录 模型介绍生成案例案例一案例二案例三案例四案例五案例六案例七案例八 下载地址 模型介绍 一个拥有cg质感和光影的融合模型&#xff0c;偏2.5D 条目内容类型大模型基础模型SD 1.5来…

【JavaEE】_Spring MVC项目使用数组与集合传参

目录 1. 使用数组传参 1.2 传递单个参数 1.3 传递多个名称相同的参数 1.3.1 关于urlencode 2. 使用集合传参 1. 使用数组传参 创建一个Spring MVC项目&#xff0c;其中 .java文件内容如下&#xff1a; package com.example.demo.controller;import com.example.demo.Per…

二叉树——700. 二叉搜索树中的搜索、98. 验证二叉搜索树

二叉搜索树中的搜索 给定二叉搜索树&#xff08;BST&#xff09;的根节点 root 和一个整数值 val。 你需要在 BST 中找到节点值等于 val 的节点。 返回以该节点为根的子树。 如果节点不存在&#xff0c;则返回 null 。 示例 1: 输入&#xff1a;root [4,2,7,1,3], val 2 …

Lichee Pi 4A:RISC-V架构的开源硬件之旅

一、简介 Lichee Pi 4A是一款基于RISC-V指令集的强大Linux开发板&#xff0c;它凭借出色的性能和丰富的接口&#xff0c;吸引了众多开发者和爱好者的关注。这款开发板不仅适用于学习和研究RISC-V架构&#xff0c;还可以作为软路由、小型服务器或物联网设备的核心组件。 目录 一…

FreeRTOS操作系统学习——FreeRTOS工程介绍

FreeRTOS工程介绍 核心文件 FreeRTOS的最核心文件只有2个&#xff1a; FreeRTOS/Source/tasks.cFreeRTOS/Source/list.c 文件功能如下图&#xff1a; 头文件相关 内存管理文件 文件在 Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang 下&#xff0c;它也是放…