基础配置
openstack创建云主机Centos 7.2- 将
gpmall文件上传至/root目录 - 配置本地
yum源
[root@localhost ~]# rm -rf /etc/yum.repos.d/CentOS-*
[root@localhost ~]# cat /etc/yum.repos.d/local.repo
[gpmall]
name=gpmall
baseurl=file:///root/gpmall/gpmall-repo
gpgcheck=0
enabled=1
- 修改
/etc/hosts
[root@localhost ~]# cat /etc/hosts
192.168.17.12 mall
192.168.17.12 zookeeper.mall
192.168.17.12 kafka.mall
192.168.17.12 redis.mall
192.168.17.12 mysql.mall
- 关闭防火墙及
SElinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
服务安装
Java
[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
Redis
[root@localhost ~]# yum -y install redis
Elasticsearch
[root@localhost ~]# yum -y install elasticsearch
Nginx
[root@localhost ~]# yum -y install nginx
Mariadb
[root@localhost ~]# yum -y install mariadb mariadb-server
Zookeeper
- 将提供的
zookeeper-3.4.14.tar.gz解压到/opt目录
[root@localhost ~]# tar -zxvf /root/gpmall/zookeeper-3.4.14.tar.gz -C /opt/.
- 进入到
/opt/zookeeper-3.4.14/conf目录下,将zoo_sample.cfg文件重命名为 zoo.cfg
[root@localhost ~]# cd /opt/zookeeper-3.4.14/conf/
[root@localhost conf]# mv zoo_sample.cfg zoo.cfg
- 进入到
/opt/zookeeper-3.4.14/bin目录下,启动ZooKeeper服务 ```Plain Text [root@localhost conf]# cd /opt/zookeeper-3.4.14/bin [root@localhost bin]# ./zkServer.sh start
4. 检查ZooKeeper状态
[root@localhost bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone
Kafka
- 将提供的
kafka_2.11-1.1.1.tgz包解压到/opt目录
[root@localhost ~]# tar -zxvf /root/gpmall/kafka_2.11-1.1.1.tgz -C /opt/.
- 进入到
kafka_2.11-1.1.1/bin目录下,启动Kafka服务
[root@localhost ~]# cd /opt/kafka_2.11-1.1.1/bin/
[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server.properties
- 使用
jps或者netstat –ntpl命令Kafka状态
[root@localhost ~]# jps
1656 QuorumPeerMain
1946 Kafka
2015 Jps
[root@localhost ~]# 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:22 0.0.0.0:* LISTEN 976/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 896/master
tcp6 0 0 :::9092 :::* LISTEN 1946/java
tcp6 0 0 :::2181 :::* LISTEN 1656/java
tcp6 0 0 :::52182 :::* LISTEN 1946/java
tcp6 0 0 :::22 :::* LISTEN 976/sshd
tcp6 0 0 ::1:25 :::* LISTEN 896/master
tcp6 0 0 :::56798 :::* LISTEN 1656/java
Kafka服务为9092端口配置数据库
- 修改配置文件
/etc/my.cnf
[root@localhost ~]# 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-handshak
- 重启数据库服务
[root@localhost ~]# systemctl restart mariadb
- 设置root密码为123456并登录
[root@localhost ~]# mysqladmin -uroot password 123456
[root@localhost ~]# mysql -uroot -p123456
- 设置
root用户权限
MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on *.* to 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.000 sec)
- 创建数据库并导入
gpmall.sql文件
MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> use gpmall;
Database changed
MariaDB [gpmall]> source /root/gpmall/gpmall_package/gpmall.sql;
配置Redis
- 修改配置文件
/etc/redis.conf
[root@localhost ~]# vi /etc/redis.conf
# 注释此行
bind 127.0.0.1
# 修改此行
protected-mode yes
为
protected-mode no
- 重启服务
[root@localhost ~]# systemctl restart redis
配置Elasticsearch
- 修改配置文件
/etc/elasticsearch/elasticsearch.yml
[root@localhost ~]# vi /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: 192.168.17.12
http.port: 9200
- 重启服务
[root@localhost ~]# systemctl restart elasticsearch
前端部署
- 将
dist目录下的文件,复制到Nginx默认项目路径(首先清空默认项目路径下的文件)
[root@localhost ~]# rm -rf /usr/share/nginx/html/*
[root@localhost ~]# cp -rvf /root/gpmall/gpmall_package/dist/* /usr/share/nginx/html/
- 修改
Nginx配置文件/etc/nginx/conf.d/default.conf
## 添加以下内容
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;
}
location /cashier {
proxy_pass http://127.0.0.1:8083;
}
- 重启服务
[root@localhost ~]# systemctl restart nginx
后端部署
[root@localhost ~]# cd gpmall/gpmall_package/
[root@localhost gpmall_package]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[root@localhost gpmall_package]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[root@localhost gpmall_package]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[root@localhost gpmall_package]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
网页访问
地址栏输入IP地址即可访问

一键部署
可使用脚本文件 gpmall_install.sh 一键部署
#!/bin/bash
#配置本地yum源
rm -rf /etc/yum.repos.d/CentOS-*
cat > /etc/yum.repos.d/local.repo <<EOF
[gpmall]
name=gpmall
baseurl=file:///root/gpmall/gpmall-repo
gpgcheck=0
enabled=1
EOF
#修改主机映射
cat >> /etc/hosts <<EOF
127.0.0.1 mall
127.0.0.1 zookeeper.mall
127.0.0.1 kafka.mall
127.0.0.1 redis.mall
127.0.0.1 mysql.mall
EOF
#安装net-tools
yum install -y net-tools
#安装服务资源包
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
yum -y install redis
yum -y install elasticsearch
yum -y install nginx
yum -y install mariadb mariadb-server
#配置zookeeper
tar -zxvf /root/gpmall/zookeeper-3.4.14.tar.gz -C /opt/.
cd /opt/zookeeper-3.4.14/conf/
mv zoo_sample.cfg zoo.cfg
cd /opt/zookeeper-3.4.14/bin
./zkServer.sh start
#配置kafka
tar -zxvf /root/gpmall/kafka_2.11-1.1.1.tgz -C /opt/.
cd /opt/kafka_2.11-1.1.1/bin/
./kafka-server-start.sh -daemon ../config/server.properties
jps
sleep 5
#修改数据库配置文件
cat >> /etc/my.cnf <<EOF
[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-handshak
EOF
#配置数据库
systemctl restart mariadb
name=`hostnamectl | grep "Transient hostname" | awk '{print $3}'`
mysqladmin -uroot password 123456
enter_mysql="mysql -uroot -p123456 -e"
$enter_mysql "grant all privileges on *.* to 'root'@'%' identified by '123456';"
$enter_mysql "grant all privileges on *.* to 'root'@'$name' identified by '123456';"
$enter_mysql "create database gpmall;"
$enter_mysql "use gpmall; source /root/gpmall/gpmall_package/gpmall.sql;"
#配置Redis
sed -i 's/^bind 127.0.0.1/# &/' /etc/redis.conf
sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
systemctl restart redis
#配置Elasticsearch
#添加内容
sed -i '2i http.cors.enabled: true' /etc/elasticsearch/elasticsearch.yml
sed -i '3i http.cors.allow-origin: "*"' /etc/elasticsearch/elasticsearch.yml
sed -i '4i http.cors.allow-credentials: true' /etc/elasticsearch/elasticsearch.yml
#取消注释
sed -i '/cluster.name: my-application/s/^#//' /etc/elasticsearch/elasticsearch.yml
sed -i '/node.name: node-1/s/^#//' /etc/elasticsearch/elasticsearch.yml
sed -i '/network.host:/s/^#//' /etc/elasticsearch/elasticsearch.yml
sed -i 's/network.host:.*/network.host: 127.0.0.1 /g' /etc/elasticsearch/elasticsearch.yml
sed -i '/http.port: 9200/s/^#//' /etc/elasticsearch/elasticsearch.yml
systemctl restart elasticsearch
#前端部署
rm -rf /usr/share/nginx/html/*
cp -rvf /root/gpmall/gpmall_package/dist/* /usr/share/nginx/html/
sed -i '12i location /user {' /etc/nginx/conf.d/default.conf
sed -i '13i proxy_pass http://127.0.0.1:8082;' /etc/nginx/conf.d/default.conf
sed -i '14i }' /etc/nginx/conf.d/default.conf
sed -i '15i location /shopping {' /etc/nginx/conf.d/default.conf
sed -i '16i proxy_pass http://127.0.0.1:8081;' /etc/nginx/conf.d/default.conf
sed -i '17i }' /etc/nginx/conf.d/default.conf
sed -i '18i location /cashier {' /etc/nginx/conf.d/default.conf
sed -i '19i proxy_pass http://127.0.0.1:8083;' /etc/nginx/conf.d/default.conf
sed -i '20i }' /etc/nginx/conf.d/default.conf
systemctl restart nginx
#服务重启
systemctl restart mariadb
sleep 5
systemctl restart redis
sleep 5
systemctl restart elasticsearch
sleep 5
systemctl restart nginx
sleep 5
#后端部署
cd
nohup java -jar /root/gpmall/gpmall_package/shopping-provider-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall/gpmall_package/user-provider-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall/gpmall_package/gpmall-shopping-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall/gpmall_package/gpmall-user-0.0.1-SNAPSHOT.jar &
注意:主机名需手动修改为mall或localhost

Comments NOTHING