用戶畫像大數據環境搭建——從零開始搭建實時用戶畫像 -四-

本章我們開始正式搭建大數據環境,目標是構建一個穩定的可以運維監控的大數據環境。我們將採用 Ambari 搭建底層的 Hadoop 環境,使用原生的方式搭建 Flink,Druid,Superset 等實時計算環境。使用大數據構建工具與原生安裝相結合的方式,共同完成大數據環境的安裝。

Ambari 搭建底層大數據環境

Apache Ambari 是一種基於 Web 的工具,支持 Apache Hadoop 集羣的供應、管理和監控。Ambari 已支持大多數 Hadoop 組件,包括 HDFS、MapReduce、Hive、Pig、 Hbase、Zookeeper、Sqoop 和 Hcatalog 等。

Apache Ambari 支持 HDFS、MapReduce、Hive、Pig、Hbase、Zookeepr、Sqoop 和 Hcatalog 等的集中管理。也是頂級的 hadoop 管理工具之一。

目前 Ambari 的版本已經更新到 2.7,支持的組件也越來越豐富。

Hadoop 的發行版本有很多,有華爲發行版,Intel 發行版,Cloudera 發行版(CDH),MapR 版本, 以及 HortonWorks 版本等。所有發行版都是基於 Apache Hadoop 衍生出來的,產生這些版本的原因,是由於 Apache Hadoop 的開源協議決定的:任何人可以對其進行修改,並作爲開源或商業產品發佈和銷售。

收費版本:收費版本一般都會由新的特性。國內絕大多數公司發行的版本都是收費的,例如 Intel 發行版本,華爲發行版本等。

Ambari 基於 HDP 安裝,但是他們不同版本之間有不同的對應關係。

已經非常的豐富了,下面我們開始 Ambari 的安裝。

前期準備

前期準備分爲四部分

主機,數據庫,瀏覽器,JDK

主機

請先準備好安裝 Ambari 的主機,開發環境可以三臺就 ok,其他環境依據公司機器規模而確定。

假設開發環境的三臺機器爲:

192.168.12.101 master 192.168.12.102 slave1 192.168.12.103 slave2

主機的最低要求如下:

軟件要求

在每個主機上:

Ambari 主機應至少具有 1 GB RAM,並具有 500 MB 可用空間。

要檢查任何主機上的可用內存,請運行:

free -m

本地倉庫

如果網速不夠快,我們可以將包下載下來,建立本地倉庫。網速夠快可以忽略這步。

yum install yum-utils createrepo
[root@master ~]# yum -y install httpd
[root@master ~]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@master ~]# chkconfig httpd on

隨後建立一個本地 yum 源

mkdir -p /var/www/html/

將剛剛下載的包解壓到這個目錄下。

隨後通過瀏覽器 訪問 成功

createrepo  ./
製作本地源  修改文件裏邊的源地址
vi  ambari.repo
vi hdp.repo


#VERSION_NUMBER=2.7.5.0-72
[ambari-2.7.5.0]
#json.url = http://public-repo-1.hortonworks.com/HDP/hdp_urlinfo.json
name=ambari Version - ambari-2.7.5.0
baseurl=https://username:password@archive.cloudera.com/p/ambari/centos7/2.x/updates/2.7.5.0
gpgcheck=1
gpgkey=https://username:password@archive.cloudera.com/p/ambari/centos7/2.x/updates/2.7.5.0/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1

[root@master ambari]# yum clean all
[root@master ambari]# yum makecache
[root@master ambari]# yum repolist

軟件準備

爲了方便以後的管理,我們要對機器做一些配置

安裝JDK
下載地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

rpm -ivh jdk-8u161-linux-x64.rpm
java -version
通過vi /etc/hostname 進行修改機器名  這裏主要是爲了可以實現通過名稱來查找相應的服務器

  各個節點修改成相應的名稱,分別爲master,slave1.slave2
  vi /etc/hosts
192.168.12.101 master
192.168.12.102 slave1
192.168.12.103 slave2

 vi /etc/sysconfig/network
 NETWORKING=yes
HOSTNAME=master(其他的節點也對應修改)
關閉防火牆
[root@master~]#systemctl disable firewalld
[root@master~]#systemctl stop firewalld
ssh免密
ssh-keygen

ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

不同的環境會有不同的問題存在,大家可以參考官網手冊進行相應的安裝。

安裝 ambari-server

ambariserver 將最終帶我們完成大數據集羣的安裝

yum install ambari-server

Installing : postgresql-libs-9.2.18-1.el7.x86_64         1/4
Installing : postgresql-9.2.18-1.el7.x86_64              2/4
Installing : postgresql-server-9.2.18-1.el7.x86_64       3/4
Installing : ambari-server-2.7.5.0-124.x86_64           4/4
Verifying  : ambari-server-2.7.5.0-124.x86_64           1/4
Verifying  : postgresql-9.2.18-1.el7.x86_64              2/4
Verifying  : postgresql-server-9.2.18-1.el7.x86_64       3/4
Verifying  : postgresql-libs-9.2.18-1.el7.x86_64         4/4

Installed:
  ambari-server.x86_64 0:2.7.5.0-72
Dependency Installed:
 postgresql.x86_64 0:9.2.18-1.el7
 postgresql-libs.x86_64 0:9.2.18-1.el7
 postgresql-server.x86_64 0:9.2.18-1.el7
Complete!

啓動與設置

設置

ambari-server setup

不推薦直接用內嵌的 postgresql,因爲其他服務還要用 mysql

安裝配置 MySql

yum install -y wget

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

rpm -ivh mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server

systemctl enable mysqld

systemctl start mysqld.service

systemctl status mysqld.service

grep "password" /var/log/mysqld.log

mysql -uroot -p

set global validate_password_policy=0;

set global validate_password_length=1;

set global validate_password_special_char_count=0;

set global validate_password_mixed_case_count=0;

set global validate_password_number_count=0;

select @@validate_password_number_count,@@validate_password_mixed_case_count,@@validate_password_number_count,@@validate_password_length;



ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

grant all privileges on . to 'root'@'%' identified by 'password' with grant option;

flush privileges;

exit
yum -y remove mysql57-community-release-el7-10.noarch

下載mysql驅動,放到三臺的

/opt/ambari/mysql-connector-java-5.1.48.jar


初始化數據庫

mysql -uroot -p
create database ambari;

use ambari

source /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql



CREATE USER 'ambari'@'localhost' IDENTIFIED BY 'bigdata';

CREATE USER 'ambari'@'%' IDENTIFIED BY 'bigdata';

GRANT ALL PRIVILEGES ON ambari.* TO 'ambari'@'localhost';

GRANT ALL PRIVILEGES ON ambari.* TO 'ambari'@'%';

FLUSH PRIVILEGES;

完成 ambari 的配置

[root@localhost download]# ambari-server setup
Using python  /usr/bin/python
Setup ambari-server
Checking SELinux...
SELinux status is 'enabled'
SELinux mode is 'permissive'
WARNING: SELinux is set to 'permissive' mode and temporarily disabled.
OK to continue [y/n] (y)? y
Customize user account for ambari-server daemon [y/n] (n)? y
Enter user account for ambari-server daemon (root):
Adjusting ambari-server permissions and ownership...
Checking firewall status...
Checking JDK...
[1] Oracle JDK 1.8 + Java Cryptography Extension (JCE) Policy Files 8
[2] Custom JDK
==============================================================================
Enter choice (1): 2
WARNING: JDK must be installed on all hosts and JAVA_HOME must be valid on all hosts.
WARNING: JCE Policy files are required for configuring Kerberos security. If you plan to use Kerberos,please make sure JCE Unlimited Strength Jurisdiction Policy Files are valid on all hosts.
Path to JAVA_HOME: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
Validating JDK on Ambari Server...done.
Check JDK version for Ambari Server...
JDK version found: 8
Minimum JDK version is 8 for Ambari. Skipping to setup different JDK for Ambari Server.
Checking GPL software agreement...
GPL License for LZO: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
Enable Ambari Server to download and install GPL Licensed LZO packages [y/n] (n)? y
Completing setup...
Configuring database...
Enter advanced database configuration [y/n] (n)? y
Configuring database...
==============================================================================
Choose one of the following options:
[1] - PostgreSQL (Embedded)
[2] - Oracle
[3] - MySQL / MariaDB
[4] - PostgreSQL
[5] - Microsoft SQL Server (Tech Preview)
[6] - SQL Anywhere
[7] - BDB
==============================================================================
Enter choice (1): 3
Hostname (localhost):
Port (3306):
Database name (ambari):
Username (ambari):
Enter Database Password (bigdata):
Configuring ambari database...
Enter full path to custom jdbc driver: /opt/ambari/mysql-connector-java-5.1.48.jar
Copying /opt/ambari/mysql-connector-java-5.1.48.jar to /usr/share/java
Configuring remote database connection properties...
WARNING: Before starting Ambari Server, you must run the following DDL directly from the database shell to create the schema: /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql
Proceed with configuring remote database connection properties [y/n] (y)? y
Extracting system views...
.....
Ambari repo file contains latest json url http://public-repo-1.hortonworks.com/HDP/hdp_urlinfo.json, updating stacks repoinfos with it...
Adjusting ambari-server permissions and ownership...
Ambari Server 'setup' completed successfully.

隨後就可以啓動了

ambari-server start

ambari-server status

ambari-server stop

訪問如下地址

http://<your.ambari.server>:8080

集羣安裝

接下來進行集羣的安裝,包括命名,ssh 免密,選擇版本,規劃集羣

最終完成集羣安裝,我們就可以在頁面管理我們的集羣了。

詳細官網安裝文檔 pdf 請在關注 “實時流式計算” 後臺回覆 ambari

實時計算環境搭建

由於 ambari 支持的 druid 版本較低,目前暫不支持 flink,所以除 kafka 外的實時計算組件,需要手動安裝,也方便以後的升級。

集羣安裝

集羣安裝分爲以下幾步:

1、在每臺機器上覆制解壓出來的 flink 目錄。

2、選擇一個作爲 master 節點,然後修改所有機器 conf/flink-conf.yaml

jobmanager.rpc.address = master主機名

3、修改 conf/slaves, 將所有 work 節點寫入

work01
work02

4、在 master 上啓動集羣

bin/start-cluster.sh

安裝在 Hadoop

我們可以選擇讓 Flink 運行在 Yarn 集羣上。

下載 Flink for Hadoop 的包

保證 HADOOP_HOME 已經正確設置即可

啓動 bin/yarn-session.sh

批處理示例:

提交 flink 的批處理 examples 程序:

bin/flink run examples/batch/WordCount.jar

這是 flink 提供的 examples 下的批處理例子程序,統計單詞個數。

$ bin/flink run examples/batch/WordCount.jar
Starting execution of program
Executing WordCount example with default input data set.
Use --input to specify file input.
Printing result to stdout. Use --output to specify output path.
(a,5)
(action,1)
(after,1)
(against,1)
(all,2)
(and,12)
(arms,1)
(arrows,1)
(awry,1)
(ay,1)

Druid 集羣部署

部署建議

集羣部署採用的分配如下:

未來我們可以添加更多的主節點和查詢節點

conf/druid/cluster/master

16 vCPU 122GB 內存 2 * 1.9TB SSD

配置文件位於

conf/druid/cluster/data

查詢服務器 建議 8vCPU 32GB 內存

配置文件位於

conf/druid/cluster/query

開始部署

下載最新 0.17.0 發行版

解壓

tar -xzf apache-druid-0.17.0-bin.tar.gz
cd apache-druid-0.17.0

集羣模式的主要配置文件都位於:

conf/druid/cluster

配置元數據存儲

conf/druid/cluster/_common/common.runtime.properties

替換

druid.metadata.storage.connector.connectURI
druid.metadata.storage.connector.host

例如配置 mysql 爲元數據存儲

在 mysql 中配置好訪問權限:

-- create a druid database, make sure to use utf8mb4 as encoding
CREATE DATABASE druid DEFAULT CHARACTER SET utf8mb4;

-- create a druid user
CREATE USER 'druid'@'localhost' IDENTIFIED BY 'druid';

-- grant the user all the permissions on the database we just created
GRANT ALL PRIVILEGES ON druid.* TO 'druid'@'localhost';

在 druid 中配置

druid.extensions.loadList=["mysql-metadata-storage"]
druid.metadata.storage.type=mysql
druid.metadata.storage.connector.connectURI=jdbc:mysql://<host>/druid
druid.metadata.storage.connector.user=druid
druid.metadata.storage.connector.password=diurd

配置深度存儲

將數據存儲配置爲 S3 或者 HDFS

比如配置 HDFS,修改

conf/druid/cluster/_common/common.runtime.properties
druid.extensions.loadList=["druid-hdfs-storage"]

#druid.storage.type=local
#druid.storage.storageDirectory=var/druid/segments

druid.storage.type=hdfs
druid.storage.storageDirectory=/druid/segments

#druid.indexer.logs.type=file
#druid.indexer.logs.directory=var/druid/indexing-logs

druid.indexer.logs.type=hdfs
druid.indexer.logs.directory=/druid/indexing-logs

將 Hadoop 配置 XML(core-site.xml,hdfs-site.xml,yarn-site.xml,mapred-site.xml)放在 Druid 中

conf/druid/cluster/_common/

配置 zookeeper 連接

還是修改

conf/druid/cluster/_common/

下的

druid.zk.service.host

爲 zk 服務器地址就可以了

啓動集羣

啓動前注意打開端口限制

主節點:

derby 1527

zk 2181

Coordinator 8081

Overlord 8090

數據節點:

Historical 8083

Middle Manager 8091, 8100–8199

查詢節點:

Broker 8082

Router 8088

記得將剛纔配好的 druid 複製到各個節點

啓動主節點

由於我們使用外部 zk 所以使用 no-zk 啓動

bin/start-cluster-master-no-zk-server

啓動數據服務器

bin/start-cluster-data-server

啓動查詢服務器

bin/start-cluster-query-server

這樣的話 集羣就啓動成功了!

至此,我們的大數據環境基本搭建完畢,下一章我們將接入數據,開始進行標籤的開發,未完待續~

參考文獻

《用戶畫像:方法論與工程化解決方案》

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/RBDiQPEKefEM1uIYF-XmQQ