1. 1、修改主机名
    2. [root@xnode1 ~]# hostnamectl set-hostname mall //修改主机名,修改完成使用ctrl+d退出登录
    3. 2、添加主机名映射文件
    4. [root@mall ~]# vi /etc/hosts //编辑主机名映射文件
    5. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    6. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    7. 192.168.200.11 mall
    8. 192.168.200.11 redis.mall
    9. 192.168.200.11 kafka.mall
    10. 192.168.200.11 zookeeper.mall
    11. 192.168.200.11 mysql.mall
    12. 3、配置Yum
    13. [root@mall ~]# vi /etc/yum.repos.d/local.repo //编辑yum源文件
    14. [centos] //源ID
    15. name=centos //源名称
    16. baseurl=file:///opt/centos //源路径
    17. gpgcheck=0 //校验为0
    18. enabled=1 //自启
    19. [mall]
    20. name=mall
    21. baseurl=file:///root/gpmall-repo
    22. gpgcheck=0
    23. enabled=1
    24. 4、安装服务
    25. [root@mall ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel redis nginx mariadb mariadb-server //安装jdk、数据库、缓存、nginx服务
    26. 5、关闭防火墙以及selinux
    27. [root@mall ~]# systemctl stop firewalld && systemctl disable firewalld //关闭防火墙并设置开机不自启
    28. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    29. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
    30. [root@mall ~]# setenforce 0 //临时关闭selinux
    31. 6、查看jdk版本
    32. [root@mall ~]# java -version //查看jdk版本号
    33. openjdk version "1.8.0_222"
    34. OpenJDK Runtime Environment (build 1.8.0_222-b10)
    35. OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
    36. 7、配置zookeeper服务
    37. [root@mall ~]# tar -zxvf zookeeper-3.4.14.tar.gz //解压zookeeper压缩包
    38. [root@mall ~]# cd zookeeper-3.4.14/conf/ //进入zookeeper/conf目录下
    39. [root@mall conf]# mv zoo_sample.cfg zoo.cfg //给zoo_sample文件改名
    40. [root@mall conf]# cd ../bin/ //进入到zookeeper/bin目录下
    41. [root@mall bin]# ./zkServer.sh start //启动zookeeper服务
    42. ZooKeeper JMX enabled by default
    43. Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
    44. Starting zookeeper ... STARTED
    45. [root@mall bin]# ./zkServer.sh status //查看zookeeper服务状态
    46. ZooKeeper JMX enabled by default
    47. Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
    48. Mode: standalone
    49. 8、配置kafka
    50. root@mall bin]# cd //进入root目录
    51. [root@mall ~]# tar -zxvf kafka_2.11-1.1.1.tgz //解压kafka压缩包
    52. [root@mall ~]# cd kafka_2.11-1.1.1/bin/ //进入bin目录
    53. [root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties //启动kafka服务
    54. [root@mall bin]# cd //进入root目录
    55. [root@mall ~]# jps //使用命令查看进程,有kafka服务证明启动无误
    56. 3456 QuorumPeerMain
    57. 3771 Kafka
    58. 3836 Jps
    59. [root@mall ~]# yum -y install net-tools //安装net-tools(此工具用来查看端口号)
    60. [root@mall ~]# netstat -ntpl //查询到端口9092,对应的服务为kafka
    61. Active Internet connections (only servers)
    62. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    63. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1467/sshd
    64. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1970/master
    65. tcp6 0 0 :::36141 :::* LISTEN 3456/java
    66. tcp6 0 0 :::22 :::* LISTEN 1467/sshd
    67. tcp6 0 0 ::1:25 :::* LISTEN 1970/master
    68. tcp6 0 0 :::47043 :::* LISTEN 3771/java
    69. tcp6 0 0 :::9092 :::* LISTEN 3771/java
    70. tcp6 0 0 :::2181 :::* LISTEN 3456/java
    71. 9、配置数据库
    72. [root@mall ~]# vi /etc/my.cnf //编辑数据库配置文件
    73. #
    74. # This group is read both both by the client and the server
    75. # use it for options that affect everything
    76. #
    77. [client-server]
    78. #
    79. # include all files from the config directory
    80. #
    81. !includedir /etc/my.cnf.d
    82. [mysqld] //从此行开始插入
    83. init_connect='SET collation_connection = utf8_unicode_ci'
    84. init_connect='SET NAMES utf8'
    85. character-set-server=utf8
    86. collation-server=utf8_unicode_ci
    87. skip-character-set-client-handshake
    88. [root@mall ~]# systemctl restart mariadb //重启数据库服务
    89. [root@mall ~]# systemctl enable mariadb //设置数据库开机自启
    90. [root@mall ~]# mysql_secure_installation //初始化数据库服务,使用此命令必须保证数据库已经启动否则无效
    91. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
    92. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
    93. In order to log into MariaDB to secure it, we'll need the current
    94. password for the root user. If you've just installed MariaDB, and
    95. you haven't set the root password yet, the password will be blank,
    96. so you should just press enter here.
    97. Enter current password for root (enter for none):
    98. OK, successfully used password, moving on...
    99. Setting the root password ensures that nobody can log into the MariaDB
    100. root user without the proper authorisation.
    101. Set root password? [Y/n] y
    102. New password: //设置密码为123456,必须设置为123456,否则后面对接jar包不成功,造成商城页面不可弹出
    103. Re-enter new password: //再输入一遍
    104. Password updated successfully!
    105. Reloading privilege tables..
    106. ... Success!
    107. By default, a MariaDB installation has an anonymous user, allowing anyone
    108. to log into MariaDB without having to have a user account created for
    109. them. This is intended only for testing, and to make the installation
    110. go a bit smoother. You should remove them before moving into a
    111. production environment.
    112. Remove anonymous users? [Y/n] y //询问是否移除匿名用户--y
    113. ... Success!
    114. Normally, root should only be allowed to connect from 'localhost'. This
    115. ensures that someone cannot guess at the root password from the network.
    116. Disallow root login remotely? [Y/n] n //询问是否禁止远程登陆--n
    117. ... skipping.
    118. By default, MariaDB comes with a database named 'test' that anyone can
    119. access. This is also intended only for testing, and should be removed
    120. before moving into a production environment.
    121. Remove test database and access to it? [Y/n] y //询问是否移除匿名用户--y
    122. - Dropping test database...
    123. ... Success!
    124. - Removing privileges on test database...
    125. ... Success!
    126. Reloading the privilege tables will ensure that all changes made so far
    127. will take effect immediately.
    128. Reload privilege tables now? [Y/n] y //询问是否刷新权限--y
    129. ... Success!
    130. Cleaning up...
    131. All done! If you've completed all of the above steps, your MariaDB
    132. installation should now be secure.
    133. Thanks for using MariaDB!
    134. [root@mall ~]# mysql -uroot -p123456 //登录数据库,用户为root,密码为123456
    135. Welcome to the MariaDB monitor. Commands end with ; or \g.
    136. Your MariaDB connection id is 15
    137. Server version: 10.3.18-MariaDB MariaDB Server
    138. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    139. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    140. MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option; //授权所有用户拥有本地数据库的所有权限
    141. Query OK, 0 rows affected (0.000 sec)
    142. MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456' with grant option; //赋予任何远程主机用root用户连接到mysql 所有库的权限,密码为123456
    143. Query OK, 0 rows affected (0.000 sec)
    144. MariaDB [(none)]> create database gpmall; //创建数据库,名为gpmall
    145. Query OK, 1 row affected (0.000 sec)
    146. MariaDB [(none)]> use gpmall; //进入数据库
    147. Database changed
    148. MariaDB [gpmall]> source /root/gpmall-single/gpmall.sql //将本地数据导入到数据库中
    149. 10、配置redis服务
    150. [root@mall ~]# vi /etc/redis.conf //编辑redis配置文件
    151. 进入文件后,不要做任何操作,直接输入:set nu显示行号,然后将文本改为插入模式,将第61行前加#进行注释,再将第80行中的yes改为no,最后保存退出
    152. [root@mall ~]# systemctl restart redis //更改文件后,重启redis服务
    153. [root@mall ~]# systemctl enable redis //设置redis服务开机自启
    154. [root@mall ~]# netstat -ntpl //查看端口号,找到6379端口,对应的服务为redis
    155. 11、配置nginx服务
    156. [root@mall ~]# rm -rf /usr/share/nginx/html/* //删除Nginx服务站点目录下所有内容
    157. [root@mall ~]# cp -rvf gpmall-single/dist/* /usr/share/nginx/html/ //将本地web包拷贝到站点目录下
    158. [root@mall ~]# vi /etc/nginx/conf.d/default.conf //编辑nginx的配置文件
    159. 进入配置文件后找到第一个location,将下面内容添加进去
    160. location /user {
    161. proxy_pass http://127.0.0.1:8082;
    162. }
    163. location /shopping {
    164. proxy_pass http://127.0.0.1:8081;
    165. }
    166. location /cashier {
    167. proxy_pass http://127.0.0.1:8083;
    168. }
    169. [root@mall ~]# systemctl restart nginx //添加完成后重启nginx服务,如果遇到服务报错,则检查Nginx配置文件是否正确
    170. [root@mall ~]# netstat -ntpl //查看端口号,有无80端口暴露,对应服务为nginx
    171. 12、部署后端jar
    172. [root@mall ~]# cd gpmall-single/ //进入存放后端jar包文件目录
    173. [root@mall ~]# gpmall-single]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar & //分别在后台,启动下面四个jar
    174. [root@mall ~]# gpmall-single]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
    175. [root@mall ~]# gpmall-single]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
    176. [root@mall ~]# gpmall-single]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
    177. [root@mall gpmall-single]# jobs
    178. [1] Running nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
    179. [2] Running nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
    180. [3]- Running nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
    181. [4]+ Running nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
    182. 注意:如果在命令启动过程中遇到EXIT字样,则为jar包出现闪退,检查前面所部署的服务是否运行正常,以及主机名映射文件是否书写正确
    183. 13、浏览器登录验证
    184. 如果前面每个服务都运行正常,且jar包没有出现闪退,那么使用浏览器输入192.168.200.11进行验证,如果发现有图片并且有文字出现,则gpmall商城部署正常。