• 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

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

    1. [root@wq images_docker]# docker load -i CentOS7_1804.tar
    2. 4826cdadf1ef: Loading layer [==================================================>] 207.8MB/207.8MB
    3. 14373f3a403e: Loading layer [==================================================>] 173.8MB/173.8MB
    4. 5ac0fc2030b4: Loading layer [==================================================>] 6.656kB/6.656kB
    5. d4ce7d7d577a: Loading layer [==================================================>] 6.144kB/6.144kB
    6. ee747055941b: Loading layer [==================================================>] 6.656kB/6.656kB
    7. d0d06aa60ad3: Loading layer [==================================================>] 5.12kB/5.12kB
    8. b3f3bc1666f9: Loading layer [==================================================>] 5.632kB/5.632kB
    9. 9692fa18f16b: Loading layer [==================================================>] 2.56kB/2.56kB
    10. Loaded image: centos7:1804
    11. [root@wq ~]# docker images
    12. REPOSITORY TAG IMAGE ID CREATED SIZE
    13. centos7 1804 8c1f6d23d72e 4 years ago 370MB
    14. [root@wq ~]# docker run -d --name mall -p 8045:80 centos7:1804
    15. b2581295b40b15eb117f07fc221e91ed02ed91d7f1d145a69841c52e469ea82c
    16. [root@wq ~]# docker ps
    17. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    18. 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上传到服务器或者虚拟中

    1. [root@wq ~]# docker ps
    2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    3. 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
    4. [root@wq ~]# docker cp /root/gpmall-repo b2581295b40b:/root
    5. Successfully copied 323MB to b2581295b40b:/root

    /etc/hosts配置文件如下

    1.2  添加yum源

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

    2.  安装基础服务

    2.1  安装JAVA环境

    1. [root@b2581295b40b yum.repos.d]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
    2. [root@b2581295b40b yum.repos.d]# java -version
    3. openjdk version "1.8.0_402"
    4. OpenJDK Runtime Environment (build 1.8.0_402-b06)
    5. 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包到服务器或者虚拟机中

    1. [root@wq ~]# ll
    2. total 1113272
    3. drwxr-xr-x 5 root root 4096 Mar 5 19:46 gpmall-repo
    4. -rw-r--r-- 1 root root 37676320 Mar 5 20:12 zookeeper-3.4.14.tar.gz
    5. [root@wq ~]# docker cp zookeeper-3.4.14.tar.gz b2581295b40b:/root/
    6. Successfully copied 37.7MB to b2581295b40b:/root/
    7. # 容器内查看
    8. [root@b2581295b40b yum.repos.d]# ll /root
    9. total 36804
    10. -rw------- 1 root root 3302 May 31 2018 anaconda-ks.cfg
    11. drwxr-xr-x 5 root root 4096 Mar 5 11:46 gpmall-repo
    12. -rw-r--r-- 1 root root 37676320 Mar 5 12:12 zookeeper-3.4.14.tar.gz

    解压

    1. [root@b2581295b40b yum.repos.d]# tar -zxvf /root/zookeeper-3.4.14.tar.gz
    2. zookeeper-3.4.14/
    3. zookeeper-3.4.14/bin/
    4. zookeeper-3.4.14/bin/README.txt
    5. zookeeper-3.4.14/bin/zkCleanup.sh
    6. zookeeper-3.4.14/bin/zkCli.cmd
    7. zookeeper-3.4.14/bin/zkCli.sh
    8. zookeeper-3.4.14/bin/zkEnv.cmd
    9. zookeeper-3.4.14/bin/zkEnv.sh
    10. [root@b2581295b40b yum.repos.d]# ls
    11. CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Sources.repo CentOS-fasttrack.repo zookeeper-3.4.14
    12. CentOS-CR.repo CentOS-Media.repo CentOS-Vault.repo local.repo
    13. # 放到/opt目录下
    14. [root@b2581295b40b yum.repos.d]# mv zookeeper-3.4.14 /opt
    15. [root@b2581295b40b yum.repos.d]# cd /opt
    16. [root@b2581295b40b opt]# ll
    17. total 4
    18. drwxr-xr-x 14 2002 2002 4096 Mar 6 2019 zookeeper-3.4.14

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

    启动服务

    1. [root@b2581295b40b conf]# cd ../bin/
    2. [root@b2581295b40b bin]# pwd
    3. /opt/zookeeper-3.4.14/bin
    4. [root@b2581295b40b bin]# ./zkServer.sh start
    5. ZooKeeper JMX enabled by default
    6. Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
    7. Starting zookeeper ... STARTED
    8. [root@b2581295b40b bin]# ./zkServer.sh status
    9. ZooKeeper JMX enabled by default
    10. Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
    11. Mode: standalone

    2.7  安装kafka服务

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

    1. [root@wq ~]# ll
    2. total 1169400
    3. drwxr-xr-x 5 root root 4096 Mar 5 19:46 gpmall-repo
    4. -rw-r--r-- 1 root root 57471165 Mar 5 20:20 kafka_2.11-1.1.1.tgz
    5. -rw-r--r-- 1 root root 37676320 Mar 5 20:12 zookeeper-3.4.14.tar.gz
    6. # 上传到容器中
    7. [root@wq ~]# docker cp kafka_2.11-1.1.1.tgz b2581295b40b:/root
    8. Successfully copied 57.5MB to b2581295b40b:/root

    解压

    1. [root@b2581295b40b bin]# cd /opt
    2. [root@b2581295b40b opt]# pwd
    3. /opt
    4. [root@b2581295b40b opt]#
    5. [root@b2581295b40b opt]# tar -zxvf /root/kafka_2.11-1.1.1.tgz
    6. kafka_2.11-1.1.1/
    7. kafka_2.11-1.1.1/LICENSE
    8. kafka_2.11-1.1.1/NOTICE
    9. kafka_2.11-1.1.1/bin/
    10. kafka_2.11-1.1.1/bin/kafka-preferred-replica-election.sh
    11. kafka_2.11-1.1.1/bin/connect-standalone.sh
    12. kafka_2.11-1.1.1/bin/kafka-server-start.sh

    开启服务中查看

    1. [root@b2581295b40b opt]# cd kafka_2.11-1.1.1/bin/
    2. [root@b2581295b40b bin]# pwd
    3. /opt/kafka_2.11-1.1.1/bin
    4. [root@b2581295b40b bin]# ./kafka-server-start.sh -daemon ../config/server.properties
    5. [root@b2581295b40b bin]# jps
    6. 501 QuorumPeerMain
    7. 815 Kafka
    8. 879 Jps
    9. # 下载工具
    10. [root@b2581295b40b bin]# yum install -y net-tools
    11. Loaded plugins: fastestmirror, ovl
    12. Loading mirror speeds from cached hostfile
    13. * base: mirrors.aliyun.com
    14. * extras: mirrors.aliyun.com
    15. * updates: mirrors.aliyun.com
    16. Resolving Dependencies
    17. --> Running transaction check
    18. ---> Package net-tools.x86_64 0:2.0-0.24.20131004git.el7 will be updated
    19. ---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be an update
    20. --> Finished Dependency Resolution
    21. Dependencies Resolved
    22. ============================================================================================================================
    23. Package Arch Version Repository Size
    24. ============================================================================================================================
    25. Updating:
    26. net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
    27. Transaction Summary
    28. ============================================================================================================================
    29. Upgrade 1 Package
    30. Total download size: 306 k
    31. Downloading packages:
    32. Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
    33. net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
    34. Running transaction check
    35. Running transaction test
    36. Transaction test succeeded
    37. Running transaction
    38. Updating : net-tools-2.0-0.25.20131004git.el7.x86_64 1/2
    39. Cleanup : net-tools-2.0-0.24.20131004git.el7.x86_64 2/2
    40. Verifying : net-tools-2.0-0.25.20131004git.el7.x86_64 1/2
    41. Verifying : net-tools-2.0-0.24.20131004git.el7.x86_64 2/2
    42. Updated:
    43. net-tools.x86_64 0:2.0-0.25.20131004git.el7
    44. Complete!
    45. [root@b2581295b40b bin]# netstat -ntpl
    46. Active Internet connections (only servers)
    47. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    48. tcp 0 0 0.0.0.0:9092 0.0.0.0:* LISTEN 815/java
    49. tcp 0 0 0.0.0.0:2181 0.0.0.0:* LISTEN 501/java
    50. tcp 0 0 0.0.0.0:46029 0.0.0.0:* LISTEN 501/java
    51. tcp 0 0 0.0.0.0:34929 0.0.0.0:* LISTEN 815/java
    52. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/sshd
    53. tcp6 0 0 :::22 :::* LISTEN 1/sshd

    3.  开启服务

    3.1  启动MariaDB数据库

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

    进行初始化,并设置密码

    1. [root@b2581295b40b ~]# mysql_secure_installation
    2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
    3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
    4. In order to log into MariaDB to secure it, we'll need the current
    5. password for the root user. If you've just installed MariaDB, and
    6. you haven't set the root password yet, the password will be blank,
    7. so you should just press enter here.
    8. Enter current password for root (enter for none):
    9. OK, successfully used password, moving on...
    10. Setting the root password ensures that nobody can log into the MariaDB
    11. root user without the proper authorisation.
    12. Set root password? [Y/n] y
    13. New password:
    14. Re-enter new password:
    15. Password updated successfully!
    16. Reloading privilege tables..
    17. ... Success!
    18. By default, a MariaDB installation has an anonymous user, allowing anyone
    19. to log into MariaDB without having to have a user account created for
    20. them. This is intended only for testing, and to make the installation
    21. go a bit smoother. You should remove them before moving into a
    22. production environment.
    23. Remove anonymous users? [Y/n] y
    24. ... Success!
    25. Normally, root should only be allowed to connect from 'localhost'. This
    26. ensures that someone cannot guess at the root password from the network.
    27. Disallow root login remotely? [Y/n] n
    28. ... skipping.
    29. By default, MariaDB comes with a database named 'test' that anyone can
    30. access. This is also intended only for testing, and should be removed
    31. before moving into a production environment.
    32. Remove test database and access to it? [Y/n] y
    33. - Dropping test database...
    34. ... Success!
    35. - Removing privileges on test database...
    36. ... Success!
    37. Reloading the privilege tables will ensure that all changes made so far
    38. will take effect immediately.
    39. Reload privilege tables now? [Y/n] y
    40. ... Success!
    41. Cleaning up...
    42. All done! If you've completed all of the above steps, your MariaDB
    43. installation should now be secure.
    44. Thanks for using MariaDB!

    登录数据库设置权限

    1. [root@b2581295b40b ~]# mysql -uroot -p123456
    2. Welcome to the MariaDB monitor. Commands end with ; or \g.
    3. Your MariaDB connection id is 16
    4. Server version: 10.3.18-MariaDB MariaDB Server
    5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    7. MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
    8. Query OK, 0 rows affected (0.000 sec)
    9. MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
    10. Query OK, 0 rows affected (0.000 sec)

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

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

    导入数据

    1. MariaDB [(none)]> create database gpmall;
    2. Query OK, 1 row affected (0.000 sec)
    3. MariaDB [(none)]> use gpmall;
    4. Database changed
    5. MariaDB [gpmall]> source /root/gpmall.sql
    6. Query OK, 0 rows affected (0.000 sec)
    7. Query OK, 0 rows affected (0.000 sec)
    8. Query OK, 0 rows affected, 1 warning (0.002 sec)
    9. Query OK, 0 rows affected (0.010 sec)
    10. Query OK, 1 row affected (0.002 sec)
    11. Query OK, 1 row affected (0.002 sec)
    12. Query OK, 1 row affected (0.003 sec)
    13. Query OK, 0 rows affected, 1 warning (0.000 sec)
    14. Query OK, 0 rows affected (0.011 sec)
    15. Query OK, 1 row affected (0.002 sec)
    16. Query OK, 0 rows affected, 1 warning (0.000 sec)
    17. Query OK, 0 rows affected (0.010 sec)
    18. Query OK, 0 rows affected, 1 warning (0.000 sec)
    19. Query OK, 0 rows affected (0.041 sec)
    20. Query OK, 0 rows affected, 1 warning (0.000 sec)
    21. Query OK, 0 rows affected (0.011 sec)
    22. Query OK, 0 rows affected, 1 warning (0.000 sec)
    23. Query OK, 0 rows affected (0.011 sec)
    24. Query OK, 1 row affected (0.002 sec)
    25. Query OK, 1 row affected (0.002 sec)
    26. Query OK, 1 row affected (0.004 sec)
    27. Query OK, 0 rows affected, 1 warning (0.000 sec)
    28. Query OK, 0 rows affected (0.010 sec)
    29. Query OK, 1 row affected (0.002 sec)
    30. Query OK, 0 rows affected, 1 warning (0.000 sec)
    31. Query OK, 0 rows affected (0.015 sec)
    32. Query OK, 1 row affected (0.002 sec)
    33. Query OK, 1 row affected (0.002 sec)
    34. Query OK, 1 row affected (0.003 sec)
    35. Query OK, 1 row affected (0.003 sec)
    36. Query OK, 1 row affected (0.002 sec)
    37. Query OK, 1 row affected (0.002 sec)
    38. Query OK, 1 row affected (0.002 sec)
    39. Query OK, 1 row affected (0.002 sec)
    40. Query OK, 1 row affected (0.002 sec)
    41. Query OK, 1 row affected (0.002 sec)
    42. Query OK, 1 row affected (0.002 sec)
    43. Query OK, 1 row affected (0.002 sec)
    44. Query OK, 1 row affected (0.002 sec)
    45. Query OK, 1 row affected (0.002 sec)
    46. Query OK, 1 row affected (0.002 sec)
    47. Query OK, 1 row affected (0.002 sec)
    48. Query OK, 1 row affected (0.002 sec)
    49. Query OK, 1 row affected (0.002 sec)
    50. Query OK, 1 row affected (0.002 sec)
    51. Query OK, 1 row affected (0.002 sec)
    52. Query OK, 1 row affected (0.002 sec)
    53. Query OK, 1 row affected (0.002 sec)
    54. Query OK, 1 row affected (0.002 sec)
    55. Query OK, 0 rows affected, 1 warning (0.000 sec)
    56. Query OK, 0 rows affected (0.019 sec)
    57. Query OK, 1 row affected (0.003 sec)
    58. Query OK, 1 row affected (0.002 sec)
    59. Query OK, 1 row affected (0.002 sec)
    60. Query OK, 1 row affected (0.002 sec)
    61. Query OK, 1 row affected (0.002 sec)
    62. Query OK, 1 row affected (0.002 sec)
    63. Query OK, 1 row affected (0.002 sec)
    64. Query OK, 1 row affected (0.003 sec)
    65. Query OK, 1 row affected (0.002 sec)
    66. Query OK, 1 row affected (0.002 sec)
    67. Query OK, 1 row affected (0.002 sec)
    68. Query OK, 1 row affected (0.002 sec)
    69. Query OK, 1 row affected (0.002 sec)
    70. Query OK, 1 row affected (0.002 sec)
    71. Query OK, 1 row affected (0.002 sec)
    72. Query OK, 1 row affected (0.002 sec)
    73. Query OK, 1 row affected (0.002 sec)
    74. Query OK, 1 row affected (0.002 sec)
    75. Query OK, 1 row affected (0.002 sec)
    76. Query OK, 1 row affected (0.002 sec)
    77. Query OK, 1 row affected (0.002 sec)
    78. Query OK, 1 row affected (0.002 sec)
    79. Query OK, 1 row affected (0.002 sec)
    80. Query OK, 1 row affected (0.002 sec)
    81. Query OK, 1 row affected (0.002 sec)
    82. Query OK, 1 row affected (0.002 sec)
    83. Query OK, 0 rows affected, 1 warning (0.000 sec)
    84. Query OK, 0 rows affected (0.011 sec)
    85. Query OK, 1 row affected (0.002 sec)
    86. Query OK, 1 row affected (0.002 sec)
    87. Query OK, 1 row affected (0.003 sec)
    88. Query OK, 1 row affected (0.003 sec)
    89. Query OK, 1 row affected (0.002 sec)
    90. Query OK, 1 row affected (0.002 sec)
    91. Query OK, 1 row affected (0.002 sec)
    92. Query OK, 1 row affected (0.002 sec)
    93. Query OK, 1 row affected (0.002 sec)
    94. Query OK, 1 row affected (0.002 sec)
    95. Query OK, 1 row affected (0.002 sec)
    96. Query OK, 1 row affected (0.002 sec)
    97. Query OK, 1 row affected (0.003 sec)
    98. Query OK, 1 row affected (0.002 sec)
    99. Query OK, 1 row affected (0.002 sec)
    100. Query OK, 1 row affected (0.002 sec)
    101. Query OK, 1 row affected (0.002 sec)
    102. Query OK, 1 row affected (0.002 sec)
    103. Query OK, 1 row affected (0.002 sec)
    104. Query OK, 1 row affected (0.002 sec)
    105. Query OK, 1 row affected (0.002 sec)
    106. Query OK, 1 row affected (0.002 sec)
    107. Query OK, 1 row affected (0.002 sec)
    108. Query OK, 0 rows affected, 1 warning (0.000 sec)
    109. Query OK, 0 rows affected (0.011 sec)
    110. Query OK, 0 rows affected, 1 warning (0.000 sec)
    111. Query OK, 0 rows affected (0.018 sec)
    112. Query OK, 1 row affected (0.002 sec)
    113. Query OK, 1 row affected (0.002 sec)
    114. Query OK, 1 row affected (0.002 sec)
    115. Query OK, 0 rows affected, 1 warning (0.000 sec)
    116. Query OK, 0 rows affected (0.018 sec)
    117. Query OK, 1 row affected (0.002 sec)
    118. Query OK, 0 rows affected, 1 warning (0.000 sec)
    119. Query OK, 0 rows affected (0.015 sec)
    120. Query OK, 0 rows affected, 1 warning (0.000 sec)
    121. Query OK, 0 rows affected (0.011 sec)
    122. Query OK, 1 row affected (0.002 sec)
    123. Query OK, 0 rows affected, 1 warning (0.000 sec)
    124. Query OK, 0 rows affected (0.014 sec)
    125. Query OK, 1 row affected (0.002 sec)
    126. Query OK, 1 row affected (0.002 sec)
    127. Query OK, 1 row affected (0.003 sec)
    128. Query OK, 1 row affected (0.003 sec)
    129. Query OK, 1 row affected (0.002 sec)
    130. Query OK, 1 row affected (0.002 sec)
    131. Query OK, 1 row affected (0.003 sec)
    132. Query OK, 0 rows affected, 1 warning (0.000 sec)
    133. Query OK, 0 rows affected (0.013 sec)
    134. Query OK, 1 row affected (0.002 sec)
    135. Query OK, 1 row affected (0.002 sec)
    136. Query OK, 1 row affected (0.003 sec)
    137. Query OK, 1 row affected (0.002 sec)
    138. Query OK, 1 row affected (0.002 sec)
    139. Query OK, 1 row affected (0.003 sec)
    140. Query OK, 1 row affected (0.002 sec)
    141. Query OK, 1 row affected (0.002 sec)
    142. Query OK, 1 row affected (0.002 sec)
    143. Query OK, 1 row affected (0.002 sec)
    144. Query OK, 1 row affected (0.002 sec)
    145. Query OK, 1 row affected (0.002 sec)
    146. Query OK, 1 row affected (0.002 sec)
    147. Query OK, 1 row affected (0.002 sec)
    148. Query OK, 1 row affected (0.002 sec)
    149. Query OK, 1 row affected (0.002 sec)
    150. Query OK, 1 row affected (0.002 sec)
    151. Query OK, 1 row affected (0.002 sec)
    152. Query OK, 1 row affected (0.002 sec)
    153. Query OK, 1 row affected (0.002 sec)
    154. Query OK, 1 row affected (0.003 sec)
    155. Query OK, 1 row affected (0.002 sec)
    156. Query OK, 1 row affected (0.002 sec)
    157. Query OK, 1 row affected (0.002 sec)
    158. Query OK, 1 row affected (0.002 sec)
    159. Query OK, 1 row affected (0.002 sec)
    160. Query OK, 1 row affected (0.002 sec)
    161. Query OK, 1 row affected (0.002 sec)
    162. Query OK, 1 row affected (0.002 sec)
    163. Query OK, 1 row affected (0.002 sec)
    164. Query OK, 1 row affected (0.002 sec)
    165. Query OK, 1 row affected (0.002 sec)
    166. Query OK, 1 row affected (0.002 sec)
    167. Query OK, 1 row affected (0.002 sec)
    168. Query OK, 1 row affected (0.002 sec)
    169. Query OK, 1 row affected (0.067 sec)
    170. Query OK, 1 row affected (0.002 sec)
    171. Query OK, 1 row affected (0.002 sec)
    172. Query OK, 1 row affected (0.002 sec)
    173. Query OK, 0 rows affected, 1 warning (0.000 sec)
    174. Query OK, 0 rows affected (0.011 sec)
    175. Query OK, 0 rows affected, 1 warning (0.001 sec)
    176. Query OK, 0 rows affected (0.013 sec)
    177. Query OK, 0 rows affected, 1 warning (0.000 sec)
    178. Query OK, 0 rows affected (0.010 sec)
    179. Query OK, 0 rows affected, 1 warning (0.000 sec)
    180. Query OK, 0 rows affected (0.011 sec)
    181. Query OK, 1 row affected (0.002 sec)
    182. Query OK, 0 rows affected (0.000 sec)
    183. MariaDB [gpmall]> Ctrl-C -- exit!
    184. Aborted

    3.2  启动redis服务

    1. [root@b2581295b40b ~]# redis-server
    2. 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
    3. _._
    4. _.-``__ ''-._
    5. _.-`` `. `_. ''-._ Redis 3.2.12 (00000000/0) 64 bit
    6. .-`` .-```. ```\/ _.,_ ''-._
    7. ( ' , .-` | `, ) Running in standalone mode
    8. |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
    9. | `-._ `._ / _.-' | PID: 1446
    10. `-._ `-._ `-./ _.-' _.-'
    11. |`-._`-._ `-.__.-' _.-'_.-'|
    12. | `-._`-._ _.-'_.-' | http://redis.io
    13. `-._ `-._`-.__.-'_.-' _.-'
    14. |`-._`-._ `-.__.-' _.-'_.-'|
    15. | `-._`-._ _.-'_.-' |
    16. `-._ `-._`-.__.-'_.-' _.-'
    17. `-._ `-.__.-' _.-'
    18. `-._ _.-'
    19. `-.__.-'
    20. 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.
    21. 1446:M 05 Mar 12:39:50.359 # Server started, Redis version 3.2.12
    22. 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.
    23. 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.
    24. 1446:M 05 Mar 12:39:50.359 * DB loaded from disk: 0.000 seconds
    25. 1446:M 05 Mar 12:39:50.359 * The server is now ready to accept connections on port 6379

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

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

    3.3  启动Elasticsearch

    添加三行内容到最上面

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

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

    1. cluster.name: my-application
    2. node.name: node-1
    3. network.host: 172.16.51.29
    4. http.port: 920
    1. [root@b2581295b40b /]# adduser elasticsearch
    2. adduser: user 'elasticsearch' already exists
    3. [root@b2581295b40b /]# mkdir /home/elasticsearch
    4. [root@b2581295b40b /]# chown elasticsearch:elasticsearch /home/elasticsearch
    5. [root@b2581295b40b /]# sudo chown -R elasticsearch:elasticsearch /var/log/elasticsearch/
    6. [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到容器中

    1. [root@wq ~]# ll
    2. total 1368780
    3. drwxr-xr-x 5 root root 4096 Mar 5 19:46 gpmall-repo
    4. -rw-r--r-- 1 root root 47765224 Mar 5 21:01 gpmall-shopping-0.0.1-SNAPSHOT.jar
    5. -rw-r--r-- 1 root root 59239 Mar 5 20:33 gpmall.sql
    6. -rw-r--r-- 1 root root 39005468 Mar 5 21:01 gpmall-user-0.0.1-SNAPSHOT.jar
    7. -rw-r--r-- 1 root root 57471165 Mar 5 20:20 kafka_2.11-1.1.1.tgz
    8. -rw-r--r-- 1 root root 54936064 Mar 5 21:01 shopping-provider-0.0.1-SNAPSHOT.jar
    9. -rw-r--r-- 1 root root 62386947 Mar 5 21:01 user-provider-0.0.1-SNAPSHOT.jar
    10. -rw-r--r-- 1 root root 37676320 Mar 5 20:12 zookeeper-3.4.14.tar.gz
    11. [root@wq ~]# docker cp shopping-provider-0.0.1-SNAPSHOT.jar b2581295b40b:/root
    12. Successfully copied 54.9MB to b2581295b40b:/root
    13. [root@wq ~]# docker cp user-provider-0.0.1-SNAPSHOT.jar b2581295b40b:/root
    14. Successfully copied 62.4MB to b2581295b40b:/root
    15. [root@wq ~]# docker cp gpmall-user-0.0.1-SNAPSHOT.jar b2581295b40b:/root
    16. Successfully copied 39MB to b2581295b40b:/root
    17. [root@wq ~]# docker cp gpmall-shopping-0.0.1-SNAPSHOT.jar b2581295b40b:/root
    18. Successfully copied 47.8MB to b2581295b40b:/root
    19. [root@wq ~]# docker cp dist b2581295b40b:/root
    20. Successfully copied 11.5MB to b2581295b40b:/root

    容器中查看

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

    添加hosts

    1. [root@b2581295b40b ~]# cat /etc/hosts
    2. 127.0.0.1 localhost
    3. ::1 localhost ip6-localhost ip6-loopback
    4. fe00::0 ip6-localnet
    5. ff00::0 ip6-mcastprefix
    6. ff02::1 ip6-allnodes
    7. ff02::2 ip6-allrouters
    8. 172.17.0.2 b2581295b40b
    9. 172.17.0.2 kafka.b2581295b40b
    10. 172.17.0.2 mysql.b2581295b40b
    11. 172.17.0.2 redis.b2581295b40b
    12. 172.17.0.2 zookeeper.b2581295b40b

    4.1  部署前端

    1. [root@b2581295b40b ~]# rm -rf /usr/share/nginx/html/*
    2. [root@b2581295b40b ~]# cp -rvf dist/* /usr/share/nginx/html/
    3. 'dist/index.html' -> '/usr/share/nginx/html/index.html'
    4. 'dist/static' -> '/usr/share/nginx/html/static'
    5. 'dist/static/fonts' -> '/usr/share/nginx/html/static/fonts'
    6. 'dist/static/fonts/element-icons.b02bdc1.ttf' -> '/usr/share/nginx/html/static/fonts/element-icons.b02bdc1.ttf'
    7. 'dist/static/svg' -> '/usr/share/nginx/html/static/svg'
    8. 'dist/static/svg/search.svg' -> '/usr/share/nginx/html/static/svg/search.svg'
    9. 'dist/static/svg/shop.svg' -> '/usr/share/nginx/html/static/svg/shop.svg'
    10. 'dist/static/svg/arrow.svg' -> '/usr/share/nginx/html/static/svg/arrow.svg'

    编辑配置文件

    1. [root@b2581295b40b ~]# vi /etc/nginx/conf.d/default.conf
    2. [root@b2581295b40b ~]# cat /etc/nginx/conf.d/default.conf
    3. server {
    4. listen 80;
    5. server_name localhost;
    6. #charset koi8-r;
    7. #access_log /var/log/nginx/host.access.log main;
    8. location / {
    9. root /usr/share/nginx/html;
    10. index index.html index.htm;
    11. }
    12. location /user {
    13. proxy_pass http://127.0.0.1:8082;
    14. }
    15. location /shopping {
    16. proxy_pass http://127.0.0.1:8081;
    17. }
    18. #error_page 404 /404.html;

    重启nginx服务

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

    4.2  部署后端

    1. [root@b2581295b40b ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
    2. [1] 1724
    3. [root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'
    4. [root@b2581295b40b ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
    5. [2] 1773
    6. [1] Exit 1 nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar
    7. [root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'
    8. [root@b2581295b40b ~]#
    9. [root@b2581295b40b ~]#
    10. [root@b2581295b40b ~]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
    11. [3] 1821
    12. [2] Exit 1 nohup java -jar user-provider-0.0.1-SNAPSHOT.jar
    13. [root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'
    14. [root@b2581295b40b ~]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
    15. [4] 1842
    16. [root@b2581295b40b ~]# nohup: ignoring input and appending output to 'nohup.out'

    登录验证

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

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

  • 相关阅读:
    C# CEFSharp WPF开发桌面程序实现“同一网站多开”
    Python爬虫:为什么你爬取不到网页数据
    行情分析——加密货币市场大盘走势(10.27)
    Apache Impala 4.1概览
    Pyhton学习笔记第一天(Python基本语句)
    Javascript知识【JS-全局函数对象&JS-事件】
    2022年7月Web3行业月度发展报告区块链篇 | 陀螺科技会员专享
    数仓面试题(1)
    Linux下提取文件夹下的所有文件名称
    算法----删掉一个元素以后全为 1 的最长子数组
  • 原文地址:https://blog.csdn.net/qq_61785413/article/details/136487690