在linux系统下单节点部署应用商城系统,功能依旧完善,只需要一台主机即可,较为简单
IP地址 | 主机名 |
---|---|
192.168.200.50 | mall |
代码如下
#hostnamectl set-hostname mall
#hostnamectl ##查看主机名
配置全局变量,在/etc/hosts文档最后加入如下代码:
192.168.200.50 kafka.mall
192.168.200.50 mysql.mall
192.168.200.50 redis.mall
192.168.200.50 zookeeper.mall
192.168.200.50 java.mall
删除/etc/yum.repo/下所有的文件,重新配置yum源
代码如下
#vi /etc/yum.repos.d/local.repo
[centos] ##默认使用centos
name=centos
baseurl=file:///opt/centos
gpgmall=0
enabled=1
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
gpgmall=0
enabled=1
这里需要创建/opt/centos文件,并挂载/dev/cdrom(只有挂载了才能使用yum)
#mkdir /opt/centos
#mount /dev/cdrom /opt/centos
安装Java环境
#yum install -y java java-devel
安装redis缓存服务
#yum install -y redis
安装Elasticsearch服务
#yum install -y elasticsearch
安装nginx服务
#yum install -y nginx
安装mariadb数据库
#yum install -y mariadb mariadb-server
安装zookeeper
下载地址
https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
将下载好的zookeeper压缩包上传至/opt/目录下,并解压,然后进入zookeeper-3.4.14/conf目录下,将zoo_sample.cfg文件重命名为zoo.cfg
#mv zoo_sample.cfg zoo.cfg
启动zookeeper:
进入到zookeeper-3.4.14/bin目录下,启动zookeeper服务
#./zkServer.sh start
#./zkServer.sh status ##查看zookeeper状态
安装kafka(这里用到的kafka版本为kafka_2.11-1.1.1)
下载地址
http://kafka.apache.org/downloads
将下载的kafka_2.11-1.1.1.tgz包上传到/opt目录下,并解压
进入到kafka_2.11-1.1.1/bin目录下,启动Kafka服务
#./kafka-server-start.sh -daemon ../config/server.properties
#jps ##查看kafka服务是否启动成功
至此,应用商城所需的服务已经安装完毕,然后需要启动所需的服务:数据库、redis、Elasticsearch和nginx
[mysqld]
init_connect='SET collation_connection=utf8_unicode_ci'
init_conncet='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
#mysql_secure_installation
#mysql -uroot -p123456
>grant all privileges on *.* to root@localhost identified by '123456' with grant option;
>grant all privileges on *.* to root@"%" identified by '123456' with grant option;
#systemctl start redis
#systemctl enable redis ##设置redis开机自启
http.cors.enabled:true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
并将如下四条语句前的注释去掉,并修改network.host的ip为本机ip
如下图所示:
最后修改完之后保存并退出,然后启动elasticsearch并设置开机自启:
#systemctl start elasticsearch
#systemctl enable elasticsearch
#rm -rf /usr/share/nginx/html/*
#cp -rvf dist/* /usr/share/nginx/html/
location /usr {
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;
}
#systemctl restart nginx
#curl http://192.168.200.50/#/home