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 ResolutionDependencies Resolved============================================================================================================================Package                    Arch                    Version                                     Repository             Size
============================================================================================================================
Updating:net-tools                  x86_64                  2.0-0.25.20131004git.el7                    base                  306 kTransaction Summary
============================================================================================================================
Upgrade  1 PackageTotal 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 transactionUpdating   : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                1/2Cleanup    : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                2/2Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                1/2Verifying  : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                2/2Updated:net-tools.x86_64 0:2.0-0.25.20131004git.el7Complete![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/mysqlSUCCESS!

进行初始化,并设置密码

[root@b2581295b40b ~]# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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 ServerCopyright (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.mzph.cn/news/722700.shtml

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

相关文章

C++核心编程之内存分区模型,引用,函数提高

1,类型分区模型 c程序在执行中,将内存大方向划分为4个区域 1,代码区:存放函数体的二进制代码,由操作系统进行管理的 2,全局区:存放全局变量和静态变量以及常量 3,栈区&#xff1…

Spring框架的优点

Spring框架是一个开放源代码的J2EE应用程序框架,是针对bean的生命周期进行管理的轻量级容器。 Spring解决了开发者在J2EE开发中遇到的许多常见的问题,提供了功能强大的IOC、AOP及Web MVC等功能。 轻量级:相对于EJB框架而言。 Spring 体系结…

Windows安装SSH教程

Windows安装SSH教程 一、SSH1.SSH简介2.SSH功能3.SSH验证3.1 第一种级别(基于口令的安全验证)3.2 第二种级别(基于密匙的安全验证) 4.SSH层次4.1 传输层协议 [SSH-TRANS]4.2 用户认证协议 [SSH-USERAUTH]4.3 连接协议 [SSH-CONNEC…

node-day3-es6模块化+webpack

模块化 一、模块化分类 回顾node.js模块化: node.js遵循了CommonJS的模块化规范【见下文】,其中: 1.导入其它模块使用require()方法 2.模块对外共享成员使用module.exports对象 模块化的好处: 大家都遵守同样的模块化规范写代…

【学习笔记】开源计算机视觉库OPENCV学习方案

本文中,我们试图提供一些学习OpenCV的详细和实用资源,这些资源包括基础知识、进阶技巧以及实践项目,旨在帮助初学者和进阶学习者更好地掌握和使用OpenCV库。 一、学习资源 官方文档:OpenCV的官方文档是学习OpenCV的最佳起点。它包…

向量数据库Chroma教程

引言 随着大模型的崛起,数据的海洋愈发浩渺无垠。受限于token的数量,无数的开发者们如同勇敢的航海家,开始在茫茫数据之海中探寻新的路径。他们选择了将浩如烟海的知识、新闻、文献、语料等,通过嵌入算法(embedding)的神秘力量,转化为向量数据,存储在神秘的Chroma向量…

飞书云文档API操作详细介绍

1.场景分析 公司内部很多文档都是由多人进行维护的,随时发生变更,因此在利用这些数据的时候就需要直接读取云文档的数据,从而执行下一步动作。团队云文档api执行权限一般需要管理员审核才能使用。如果你就是管理员,那么恭喜你&am…

【DIY】钱包的“电子卫士”的制作

一、工作原理 钱包的“电子卫士”电路如图1所示,其核心元件是微型蜂鸣器专用音响集成电路A,它与压电陶瓷蜂鸣片B、电池G等组成了一个体积小巧、发声响亮的简易蜂鸣器。 平时,钱包通过尼龙线与插头XP相接,而XP插入插孔XS内&#x…

AndroidUI--setContentView

我们的Activity通常继承自Activity或者AppCompatActivity,这两个setContentView流程是不同的 一、继承自Activity 1、Activity.setContentView Activity中setContentVIew调用了getWindow().setContentView(view, params); getWindow返回的是mWindow,mWi…

RedisDesktopManager连接Ubuntu的Redis失败解决办法

配置redis 1.设置redis在后台服务,修改配置文件 默认情况下是 no ,修改为yes,可以后台服务 2、设置redis端口,默认端口是6379,可以根据自己的需要,找到/et/redis/redis.conf文件, 修改port 3、设置密码 配置文件中…

ubuntu20.04“E: 软件包 vim 没有可安装候选”“/etc/apt/sources.list:7 中被配置了多次”解决方法

问题一:ubuntu20.04安装vim时提示“E: 软件包 vim 没有可安装候选” **解决:**更换下载,比如我原先使用的是清华源,后切换成阿里云源,ubuntu直接在“软件和更新”切换 问题一解决。 问题二:ubuntu20.04提…

JavaEE+springboot教学仪器设备管理系统o9b00-springmvc

本文旨在设计一款基于Java技术的教学仪器设备销售网站,以提高网站性能、功能完善、用户体验等方面的优势,解决现有教学仪器设备销售网站的问题,并为广大教育工作者和学生提供便捷的教学仪器设备销售渠道。本文首先介绍了Java技术的相关基础知…

华为昇腾系列——入门学习

概述 昇腾(Ascend)是华为推出的人工智能处理器品牌,其系列产品包括昇腾910和昇腾310芯片等。 生态情况 众所周知,华为昇腾存在的意义就是替代英伟达的GPU。从事AI开发的小伙伴,应该明白这个替代,不仅仅是…

【自动驾驶坐标系基础】Frenet坐标系和Cartesian坐标系的相互转换

Frenet坐标系和Cartesian坐标系的相互转换 2023.12.12 1 变量含义 Frenet和Cartesian相互转换即 [ s , s ˙ , s , d , d ˙ , d ] ↔ [ X , θ x , κ x , v x , a x ] [s,\dot{s},\ddot{s},d,\dot{d},\ddot{d}] \leftrightarrow[\boldsymbol{X},\theta_x,\kappa_x,v_x,a_…

【Unity开发】【VR】PICO项目在运行编辑器时无法正常显示游戏场景

【背景】 做了一个PICO项目,真机在手边时开发后用PC的Preview模式直接调试,真机不在手边时希望用VRTK的Simulation Rig,用键鼠模拟控制器输入进行快速调试。但是发现Simulation Rig状态下运行后,游戏场景变得很怪,很多…

RLT8762D---添加service

0 Preface/Foreword 1 系统初始化LE profile过程 正常开机流程中,gap初始化完成之后,才能进行LE profile初始化。 1.1 添加服务 1.1.1 注册支持服务个数(GATT Server) 函数: server_init 目的:set the number of services th…

MySql缓冲池命中率

缓冲池 大小查看 show variables like innodb_buffer_pool_size; 太小的innodb_buffer_pool_size是不利于性能的提升 命中率查看 一 、 通过以下命令查看相关数据: show global status like Innodb_buffer_pool_read%;结果如下: 命中率公式&#xff1…

Zabbix监控容器MongoDB,报错:Unknown metric mongodb.server.status

在Zabbix中配置监控MongoDB容器时,如果遇到Unknown metric mongodb.server.status这样的错误,通常意味着Zabbix Agent尝试从MongoDB获取某个预定义的性能指标(例如mongodb.server.status),但是未能成功识别或解析该指标…

GPT4+Python近红外光谱数据分析及机器学习与深度学习建模教程

原文链接:GPT4Python近红外光谱数据分析及机器学习与深度学习建模教程 第一:GPT4 1、ChatGPT(GPT-1、GPT-2、GPT-3、GPT-3.5、GPT-4模型的演变) 2、ChatGPT对话初体验 3、GPT-4与GPT-3.5的区别,以及与国内大语言模…

微信小程序开发系列(十六)·事件传参·data-*自定义数据

事件传参:在触发事件时,将一些数据作为参数传递给事件处理函数的过程,就是事件传参。 在微信小程序中,我们经常会在组件上添加一些自定义数据,然后在事件处理函数中获取这些自定义数据,从而完成业务逻辑的开发。 在组件上通过data-"的方式定义需要传递的数据,其…