docker单节点搭建在线商城

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

目录

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进行登录

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

数据库分库分表中间件选择

目前分库分表的中间件有三种设计思路,分别是: 采用分散式架构,适用于用Java开发的高性能轻量级OLTP应用程序,以Sharding-JDBC为代表。采用中间层Proxy架构,提供了静态输入和所有语言支持,适用于OLAP应用程…

验证Tomcat进程是否启动成功 ps -ef | grep tomcat

验证Tomcat启动是否成功,有多种方式: 查看启动日志 more /usr/local/apache-tomcat-9.0.86/logs/catalina.out tail -50 /usr/local/apache-tomcat-9.0.86/logs/catalina.out 查看进程 ps -ef | grep tomcat 注意: ps命令是linux下非常强…

《剑指offer》14--剪绳子(整数拆分)[C++]

目录 题目描述 贪心算法 输出结果 题目描述 把一根绳子剪成多段,并且使得每段的长度乘积最大。 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。 示例 1: 输入: 2 输出: 1 解释:…

ZYNQ--PS_PL交互(AXI_HP)

AXI_HP接口 通过AXI_HP接口,可直接通过AXI_FULL协议向DDR中通过DMA传输数据。 BD设计 AXI_HP接口设置 AXI_Master代码 module axi_full_master #(parameter C_M_TARGET_SLAVE_BASE_ADDR 32h40000000,parameter integer C_M_AXI_BURST_LEN 16,parameter …

代码随想录算法训练营第22天|235.二叉搜索树的最近公共祖先、701.二叉搜索树中的插入操作、450.删除二叉搜索树中的节点

目录 一、力扣235.二叉搜索树的最近公共祖先1.1 题目1.2 思路1.3 代码 二、力扣701.二叉搜索树中的插入操作2.1 题目2.2 思路2.3 代码 三、力扣450.删除二叉搜索树中的节点3.1 题目3.2 思路3.3 代码3.4 总结 一、力扣235.二叉搜索树的最近公共祖先 1.1 题目 1.2 思路 利用二叉…

09-Linux部署Redis

Linux部署Redis 简介 Redis,全称为Remote Dictionary Server(远程字典服务),是一个开源的、使用ANSI C语言编写的、支持网络连接的、基于内存的、同时支持持久化的日志型Key-Value数据库,并提供多种语言的API。 Red…

七、西瓜书——降维与度量学习

1.K近邻 k 近邻(k-Nearest Neighbor,简称 kNN)学习是一种常用的监督学习方法,其工作机制非常简单: 给定测试样本,基于某种距离度量找出训练集中与其最靠近的k个训练样本,然后基于这k个“邻居”的信息来进行预测,通常,在分类任务中可使用“投票法”&#…

$nextTick底层原理(详细) - vue篇

公众号:需要以下pdf,关注下方 2023已经过完了,让我们来把今年的面试题统计号,来备战明年的金三银四!所以,不管你是社招还是校招,下面这份前端面试工程师高频面试题,请收好。 前言 n…

CUDA学习笔记04:向量之和

参考资料 CUDA编程模型系列二(向量操作)_哔哩哔哩_bilibili (非常好的学习资料!) vs2019 随意新建一个空项目,按照之前的环境配置配好项目依赖: CUDA学习笔记02:测试程序hello world-CSDN博客 代码结构…

jitpack上传aar异常: ERROR: No build artifacts found

问题 如图所示,提示 ERROR: No build artifacts found 解决 无法找到artifacts的情况下,我们就需要手动添加artifacts 。 //maven-publish 插件的配置 // publishing 用于定义项目的发布相关配置 publishing {// 配置maven 仓库repositories { Repo…

5201B数据网络测试仪

|5201B数据网络测试仪| | 产品综述 | 电科思仪5201B便携式数据网络测试仪,集成高性能IP基础测试硬件平台,提供L2-L3流量测试及协议仿真解决方案,支持以太网报文线速生成与分析、统计、报文捕获,以及路由、接入、组播、数据中心等协…

item_fee-获得淘宝商品快递费用 API调用说明获取测试key

item_fee-获得淘宝商品快递费用 .通过传入商品id、区域id,来获取该商品的快递费用。 公共参数 点此获取API请求地址 名称类型必须描述keyString是调用key(必须以GET方式拼接在URL中)secretString是调用密钥api_nameString是API接口名称&a…

Linux系统的服务/进程

系统守护进程(服务) •服务就是运行在网络服务器上监听用户请求的进程 •服务是通过端口号来区分的 常见的服务及其对应的端口 1.ftp:21 FTP指的是文件传输协议,它是用于在计算机网络上进行文件传输的标准网络协议。通过FTP&am…

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

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

通过XML调用CAPL脚本进行测试(新手向)

目录 0 引言 1 XML简介 2 通过XML调用CAPL脚本 0 引言 纪念一下今天这个特殊日子,四年出现一次的29号。 在CANoe中做自动化测试常用的编程方法有CAPL和XML两种,二者各有各的特色,对于CAPL来说新手肯定是更熟悉一些,因为说到在C…

C#高级:Winform桌面开发中DataGridView的详解

一、每条数据增加一个按钮&#xff0c;点击输出对应实体 请先确保正确添加实体的名称和文本&#xff1a; private void button6_Click(object sender, EventArgs e) {//SQL查询到数据&#xff0c;存于list中List<InforMessage> list bll.QueryInforMessage();//含有字段…

动静态库-动态库加载

动静态库 前言引入 一、静态库1. 创建静态库①原理②创建 2. 使用静态库①借助编译选项②只需要带库名 3. 小结 二、动态库1. 创建动态库2. 使用动态库 三、 动态库加载原理——进程地址空间1. 地址①程序没有被加载前的地址②程序加载后的地址 2. 原理①动态库的地址②原理 前…

Redis中的单线程高性能原因和其他高级命令

单线程 Redis是单线程吗&#xff1f; Redis的单线程主要是指Redis的网络IO和键值对读写是由一个线程来完成的&#xff0c;这也是 Redis对外提供键值存储的主要流程。但Redis的其他功能&#xff0c;比如持久化、异步删除、 集群数据同步等&#xff0c;其实是由额外的线程执行的…

Spring Cloud 面试题及答案整理,最新面试题

Spring Cloud中断路器的原理及其作用是什么&#xff1f; Spring Cloud断路器的原理和作用基于以下几个关键点&#xff1a; 1、故障隔离机制&#xff1a; 在微服务架构中&#xff0c;断路器作为一种故障隔离机制&#xff0c;当某个服务实例出现问题时&#xff0c;断路器会“断…

紫光展锐携手中兴通讯成功完成业界首个5G N102芯网一体方案联调

近日&#xff0c;紫光展锐携手中兴通讯成功完成业界首个5G N102频段的芯网一体方案联调&#xff0c;包括5G NR数据呼叫、时延和峰值速率测试等用例。这是双方在5G产品和研发方面取得的重大创新成果&#xff0c;为推动N102频段在5G行业的应用奠定了坚实基础。 3GPP定义的N102频段…