docker单节点搭建在线商城

news/2024/6/17 14:56:12 标签: 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进行登录


http://www.niftyadmin.cn/n/5408838.html

相关文章

SpringCloudGateway工作原理与链路图

SpringCloudGateway基本介绍 Spring Cloud Gateway 构建于Spring Boot 2.x、 Spring WebFlux和Project Reactor之上。因此,在使用 Spring Cloud Gateway 时,您可能不会应用许多熟悉的同步库(例如 Spring Data 和 Spring Security)和模式。 Spring Cloud Gateway 需要 Sprin…

简单介绍SpeechPrompt、SpeechPrompt V2、SpeechGen

主要介绍SpeechPrompt、SpeechPrompt V2、SpeechGen SpeechPrompt 模型结构和原理(语音到符号) 整体思路:音频特征提取(HuBert/CPC),离散–》deep prompt speechLM(GSLM)—》概率映射–>目标Verbaliz…

Docker常见命令使用

Docker命令是使用Docker的基础。这里记录下Docker日常运维过程中经常使用到的一些命令,更全面的命令还请参考Docker官网。 docker用法概述 Docker命令可以通过CLI工具实现与服务器的交互。Docker命令的语法如下: docker [DOCKER-COMMAND] [OPTIONS] […

【论文阅读】(DALLE-3)Improving Image Generation with Better Captions

(DALLE-3)Improving Image Generation with Better Captions 文章目录 (DALLE-3)Improving Image Generation with Better Captions简介Method实验 引用: Betker J, Goh G, Jing L, et al. Improving image generation…

App前端开发跨平台框架比较:React Native、Flutter、Xamarin等

引言 移动应用开发领域的跨平台框架正在不断演进,为开发者提供更多选择。在本文中,我们将比较几个流行的跨平台框架:React Native、Flutter和Xamarin等。讨论它们的优缺点、适用场景以及开发体验。 第一部分 React Native: 优缺点、适用场景…

自然语言处理(NLP)技术介绍

自然语言处理(NLP)技术是一种使计算机能够理解、处理和生成人类语言的技术。以下是一些举例说明NLP技术的应用场景: 机器翻译:NLP技术可用于将一种语言的文本或口语翻译成另一种语言。例如,谷歌翻译就是一个使用NLP技术…

uniapp上拉加载、下拉刷新

我这个是自定义header、main、和footer的布局&#xff0c;是盒子中的上拉加载、下拉刷新&#xff0c;不是页面的&#xff0c;废话不说&#xff0c;直接上代码&#xff01; <template><view class"assembly"><u-navbar title"个人中心" lef…

【JavaEE】_Spring MVC项目之使用对象传参

目录 1. 使用对象传参 2. 后端参数重命名问题 2.1 关于RequestPara注解 本专栏关于Spring MVC项目的单个及多个参数传参一文中&#xff0c;已经介绍过了对于不同个数的参数传参问题&#xff0c;原文链接如下&#xff1a; 【JavaEE】_Spring MVC 项目单个及多个参数传参-CSD…