(1)启动数据库并配置
修改数据库配置文件并启动Mariadb数据库,设置root用户密码为123456,并创建gpmall数据库,将提供的gpmall.sql导入。
修改/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 start mariadb
设置root用户的密码为123456并登录
[root@mall ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #默认按回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password: #输入数据库root密码123456
Re-enter new password: #重复输入密码123456
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@mall ~]# mysql -uroot –p123456
设置root用户的权限,命令如下:
MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456' with grant option;
Query OK, 0 rows affected (0.001 sec)
将gpmall.sql文件上传至云主机的/root目录下。创建数据库gpmall并导入gpmall.sql文件
MariaDB [(none)]> create database gpmall;
MariaDB [(none)]> use gpmall;
MariaDB [mall]> source /root/gpmall.sql
退出数据库并设置开机自启
MariaDB [mall]> exit;
[root@mall ~]# systemctl enable mariadb
(2)启动Redis服务
修改Redis配置文件,编辑/etc/redis.conf文件。
将bind 127.0.0.1这一行注释掉:
将protected-mode yes 改为protect-mode no。
启动Redis服务命令如下:
[root@mall ~]# systemctl start redis
[root@mall ~]# systemctl enable redis
(3)配置Elasticsearch服务并启动
配置Elasticsearch服务命令如下:
[root@mall ~]# vi /etc/elasticsearch/elasticsearch.yml
在文件最上面加入3条语句如下:
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
将如下4条语句前的注释符去掉,并修改network.host的IP为本机IP
cluster.name: my-application
node.name: node-1
network.host: 192.168.94.1
http.port: 9200
最后修改完之后保存退出。然后启动Elasticsearch并设置开机自启,命令如下
[root@mall ~]# systemctl start elasticsearch
[root@mall ~]# systemctl enable elasticsearch
(4)启动Nginx服务
[root@mall ~]# systemctl start nginx
[root@mall ~]# systemctl enable nginx
修改/etc/hosts文件
[root@mall ~]# vi /etc/hosts
192.168.100.10 kafka.mall
192.168.100.10 mysql.mall
192.168.100.10 redis.mall
192.168.100.10 zookeeper.mall
将dist目录上传至服务器的/root目录下。接着dist目录下的文件,复制到Nginx默认项目路径(首先清空默认路径下的文件)
[root@mall ~]# rm -rf /usr/share/nginx/html/*
[root@mall ~]# cp -rvf dist/* /usr/share/nginx/html/
修改Nginx配置文件/etc/nginx/conf.d/default.conf,添加映射如下所示
[root@mall ~]# vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
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;
}
#error_page 404 /404.html;
重启Nginx服务,命令如下:
[root@mall ~]# systemctl restart nginx
将提供的4个jar包上传到服务器的/root目录下,并启动,启动命令如下
[root@mall gpmall]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
按回车
[1] 6432
[root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’
按回车
[root@mall gpmall]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 6475
[root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’
按回车
[root@mall gpmall]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[3] 6523
[root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’
按回车
[root@mall gpmall]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4] 6563
[root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’
按回车
按照顺序运行4个jar包之后,后端部署完成。
打开浏览器,在地址栏输入http://192.168.100.10,访问界面。