1+X 云计算运维与开发(中级)案例实战——单节点应用商城系统部署

1+X 云计算运维与开发(中级)——单节点应用系统部署

  • 前言
  • 1.思路
  • 2.实操
    • 1.修改主机名,修改 /etc/hosts 文件
    • 2.配置yum源
    • 3.使用yum来安装各个服务(java, mysql, nginx, redis)
    • 4.将 zookeeper-3.4.14.tar.gz 和 kafka_2.11-1.1.1.tgz 解压并启动
    • 5.配置并启动各个服务(java, mysql, nginx, redis)
      • 5.1 配置mysql
      • 5.2 配置redis
      • 5.3 配置nginx
    • 6.上传4个 .jar 文件,并且按顺序启动
  • 总结


前言

学而不思则罔,思而不学则殆。


1.思路

整个系统的部署说白了就是安装各种服务,然后修改配置文件,最后启动。
主机名!主机名!主机名!(重要的事说三遍)

1.修改主机名,修改 /etc/hosts 文件。
2.使用 gpmall-repo 文件和 CentOS-7-x86_64-DVD-1511.iso 文件来配置 yum源
3.使用yum来安装各个服务。
4.将 zookeeper-3.4.14.tar.gzkafka_2.11-1.1.1.tgz上传,解压,然后分别配置启动
5.配置并启动各个服务。
6.上传4个 .jar 文件,并且按顺序启动

2.实操

1.修改主机名,修改 /etc/hosts 文件

代码如下(示例):

[root@mall ~]# hostnamctl set-hostname mall
[root@mall ~]# logout					--使主机名生效
[root@mall ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
## 以下为新增内容
192.168.200.11 mall     				--这一行将决定你的kafka进程是否会正常运行
192.168.200.11 kafka.mall
192.168.200.11 mysql.mall
192.168.200.11 redis.mall
192.168.200.11 zookeeper.mall

说明:这里的主机名( hostnamctl set-hostname mall),我尝试过其他名称,然后在 /etc/hosts 文件中输入相对应的映射,但是会导致后期实验完成后,打开网页时白屏,我猜测和后面的 jar 包的内容有关,但是本人功力有限,所以只能中规中矩使用 mall

2.配置yum源

代码如下(示例):

[root@mall ~]# rm -rf /etc/yum.repos.d/*   								       	这一行的作用是删除原有的repo文件对后续的影响
[root@mall ~]# cat /etc/yum.repos.d/local.repo 
[gpmall]
name=gpmall
baseurl=file:///root/gpmall-repo															这里的gpmall-repo文件需要自己上传
gpgcheck=0
enabled=1
[centos]
name=centos
baseurl=file:///opt/cdrom																		 这里的/opt/cdrom需要自己创建
gpgcheck=0
enabled=1
[root@mall ~]# mkdir /opt/cdrom
[root@mall ~]# mount CentOS-7-x86_64-DVD-1511.iso /opt/cdrom
mount: /dev/loop0 is write-protected, mounting read-only
[root@mall ~]# yum repolist
Loaded plugins: fastestmirror
centos                                                   | 3.6 kB     00:00     
gpmall                                                   | 2.9 kB     00:00     
(1/3): centos/group_gz                                     | 155 kB   00:00     
(2/3): gpmall/primary_db                                   | 144 kB   00:00     
(3/3): centos/primary_db                                   | 2.8 MB   00:00     
Determining fastest mirrors
repo id                              repo name                            status
centos                               centos                               3,723
gpmall                               gpmall                                 165
repolist: 3,888

3.使用yum来安装各个服务(java, mysql, nginx, redis)

代码如下(示例):

[root@mall ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
...
[root@mall ~]# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
[root@mall ~]# yum -y install mariadb mariadb-server
[root@mall ~]# yum -y install nginx
[root@mall ~]# yum -y install redis

4.将 zookeeper-3.4.14.tar.gz 和 kafka_2.11-1.1.1.tgz 解压并启动

代码如下(示例):

[root@mall ~]# tar -zxvf zookeeper-3.4.14.tar.gz
[root@mall ~]# cd zookeeper-3.4.14/conf/
[root@mall conf]# mv zoo_sample.cfg zoo.cfg			##重命名
[root@mall conf]# cd ../bin
[root@mall bin]# pwd
/root/zookeeper-3.4.14/bin
[root@mall bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@mall bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone
[root@mall ~]# tar -zxvf kafka_2.11-1.1.1.tgz
[root@mall ~]# cd kafka_2.11-1.1.1/bin/
[root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties 
[root@mall bin]# jps
3204 QuorumPeerMain
3515 Kafka
3579 Jps

说明:一定要确认kafka进程正常运行

5.配置并启动各个服务(java, mysql, nginx, redis)

代码如下(示例):

5.1 配置mysql

[root@mall ~]# systemctl start mariadb
[root@mall ~]# mysql_secure_installation

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: #密码务必使用123456
Re-enter new password: 
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.

[root@mall ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.3.18-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

-------------------------------------------------------------------------------------------------------------------------

MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> use gpmall;
Database changed
MariaDB [gpmall]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
Query OK, 0 rows affected (0.000 sec)

MariaDB [gpmall]> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.000 sec)

MariaDB [gpmall]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [gpmall]> source /root/gpmall-single/gpmall.sql            ##这个gpmall.sql需要自己上传
Query OK, 0 rows affected (0.000 sec)
...
Query OK, 0 rows affected (0.000 sec)

MariaDB [gpmall]> Bye

[root@mall ~]# systemctl enable mariadb

5.2 配置redis

修改/etc/redis.conf文件
1.第61行用#注释掉

#bind 127.0.0.1

2.第80行把yes改为no

protected-mode no

[root@mall bin]# systemctl start redis && systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to
/usr/lib/systemd/system/redis.service.

5.3 配置nginx

代码如下(示例):

[root@mall ~]# vi /etc/nginx/conf.d/default.conf
	在error_page上一行开始编辑,添加以下内容:
	
    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@mall ~]# rm -rf /usr/share/nginx/html/*
[root@mall ~]# cp -R gpmall-single/dist/* /usr/share/nginx/html/
[root@mall ~]# systemctl start nginx && systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

6.上传4个 .jar 文件,并且按顺序启动

代码如下(示例):

[root@mall gpmall-single]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[1] 6825
[root@mall gpmall-single]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-single]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 6866
[root@mall gpmall-single]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-single]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[3] 6912
[root@mall gpmall-single]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-single]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4] 6951
[root@mall gpmall-single]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-single]# systemctl stop firewalld
s[root@mall gpmall-single]# setenforce 0

说明:每输入一遍 nohup命令之后,它会自动弹出一个提示,所以一共输入了 四次nohup,如果输入的结果 不正常(正不正常看[1]这样的提示,一般来讲[1],[2],[3],[4]),请 kill进程然后排错后重新按照顺序启动,最后,请 关闭防火墙

总结

多读书,多看报,少吃零食,好好睡觉。
努力就完啦!!!

你可能感兴趣的:(1+x,运维,云计算,kafka)