目录
实验中使用的技术
实验过程
Java
Redis
Elasticsearch(先不用)
Nginx
MariaDB
ZooKeeper
Kafka
1.Xnode1克隆虚拟机gpmall
CRT连接(root密码:000000)
2修改主机名
[root@localhost ~]# hostnamectl set-hostname mall
[root@localhost ~]#bash
3.修改/etc/hosts
[root@mall ~]#vi /etc/hosts
#添加192.168.224.3 mall
[root@mall ~]#cat /etc/hosts
4.配置本地yum源
[root@mall ~]# vi /etc/yum.repos.d/local.repo
添加:
[gpmall]
name=gpmall
baseurl=file:///root/gpmall-repo
gpgcheck=0
enabled=1
5.安装基本服务
(1)安装java环境
[root@mall ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@mall ~]# java -version
(2)安装redis缓存服务
[root@mall ~]# yum install redis -y
(3)安装niginx服务
[root@mall ~]# yum install nginx -y
(4)安装mariaDB【root用户 123456】
[root@mall ~]# yum install mariadb mariadb-server -y
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql_secure_installation
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
(5)安装 ZooKeeper 服务
将提供的 zookeeper-3.4.14.tar.gz 上传至云主机的/opt 内
[root@mall ~]# tar -zxvf zookeeper-3.4.14.tar.gz
进入到 zookeeper-3.4.14/conf 目录下,将 zoo_sample.cfg 文件重命名为 zoo.cfg
[root@mall ~]# cd zookeeper-3.4.14/conf
[root@mall conf]# mv zoo_sample.cfg zoo.cfg
进入到 zookeeper-3.4.14/bin 目录下
[root@mall conf]# cd
[root@mall ~]# cd zookeeper-3.4.14/bin
[root@mall bin]# ./zkServer.sh start
查看 ZooKeeper 状态
[root@mall bin]# ./zkServer.sh status
(6)安装 Kafka 服务
将提供的 kafka_2.11-1.1.1.tgz 包上传到云主机的/opt 目录下
[root@mall ~]# tar -zxvf kafka_2.11-1.1.1.tgz
进入到 kafka_2.11-1.1.1/bin 目录下
[root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties
使用 jps 或者 netstat –ntpl 命令查看 Kafka 是否成功启动
[root@mall bin]# jps
[root@mall bin]# netstat -ntpl
6.启动服务
(1)启动数据库并配置
[root@mall ~]vi /etc/my.cnf
添加:
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
重动数据库命令如下
[root@mall ~]# systemctl restart mariadb
将 gpmall.sql 文件上传至云主机的/root 目录下。创建数据库 gpmall 并导入 gpmall.sql 文 件。
[root@mall ~]# mysql -uroot –p123456
MariaDB [(none)]> create database gpmall;
MariaDB [(none)]> use gpmall;
MariaDB [gpmall]> source /root/gpmall-single/gpmall.sql(这个目录下)
设置 root 用户的权限
MariaDB [gpmall]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
MariaDB [gpmall]> grant all privileges on *.* to root@"%" identified by '123456' with grant option;
MariaDB [gpmall]> flush privileges;
退出数据库并设置开机自启
ctrl+c退出
[root@mall ~]# systemctl enable mariadb
(2)启动 Redis 服务
[root@mall ~]#vi /etc/redis.conf
#bind 127.0.0.1
protected-mode yes改成protected-mode no
[root@mall ~]# systemctl start redis
[root@mall ~]# systemctl enable redis
(3)启动 Nginx 服务
[root@mall ~]# systemctl start nginx
[root@mall ~]# systemctl enable nginx
7.全局变量配置
修改/etc/hosts文件
添加:
192.168.224.3 kafka.mall
192.168.224.3 mysql.mall
192.168.224.3 redis.mall
192.168.224.3 zookeeper.mall
8.部署前端
进入gpmall-single目录
[root@mall ~]#cd gpmall-single/
[root@mall gpmall-single]#ls
复制到 Nginx 默认 项目路径
[root@mall gpmall-single]# rm -rf /usr/share/nginx/html/*
[root@mall gpmall-single]# cp -rvf dist/* /usr/share/nginx/html/
修改 Nginx 配置文件/etc/nginx/conf.d/default.conf
[root@mall gpmall-single]# vi /etc/nginx/conf.d/default.conf
添加:
location /user {
proxy_pass http://127.0.0.1:8082;
}
location /shopping {
proxy_pass http://127.0.0.1:8081;
}
location /cashier {
proxy_pass http://127.0.0.1:8083;
}
重启 Nginx 服务
[root@mall gpmall-single]# systemctl restart nginx
[root@mall gpmall-single]# ll
9.部署后端
[root@mall gpmall-single]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
克隆会话
[root@mall ~]#ls
[root@mall ~]#cd gpmall-single/
[root@mall gpmall-single]#ls
[root@mall gpmall-single]#pwd
[root@mall gpmall-single]#tail -100f nohup.out
[root@mall gpmall-single]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[root@mall gpmall-single]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[root@mall gpmall-single]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[root@mall gpmall-single]# jps(查一下)
10.网站访问
http://192.168.224.3
账号:test密码:test