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


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

Ambari搭建底層大數據環境

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

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

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

Hadoop的發行版本有不少,有華爲發行版,Intel發行版,Cloudera發行版(CDH),MapR版本,以及HortonWorks版本等。全部發行版都是基於Apache Hadoop衍生出來的,產生這些版本的緣由,是因爲Apache Hadoop的開源協議決定的:任何人能夠對其進行修改,並做爲開源或商業產品發佈和銷售。mysql

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

免費版本:
不收費的版本主要有三個(都是國外廠商)。
Cloudera版本(Cloudera’s Distribution Including Apache Hadoop)簡稱」CDH「。
Apache基金會hadoop
Hontonworks版本(Hortonworks Data Platform)簡稱「HDP」。
按照順序表明了國內的使用率,CDH和HDP雖然是收費版本,可是他們是開源的,只是收取服務費用,嚴格上講不屬於收費版本。sql

Ambari基於HDP安裝,可是他們不一樣版本之間有不一樣的對應關係。shell

Ambari2.7與HDP HDF的對應關係:數據庫

也就是支持最新的版本爲HDP 3.1.5 而HDP包含了大數據的基本組件以下:apache

已經很是的豐富了,下面咱們開始Ambari的安裝。

前期準備

前期準備分爲四部分

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

主機

請先準備好安裝Ambari的主機,開發環境能夠三臺就ok,其餘環境依據公司機器規模而肯定。

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

192.168.12.101 master
192.168.12.102 slave1
192.168.12.103 slave2

主機的最低要求以下:

軟件要求

在每一個主機上:

  • yumrpm(RHEL / CentOS / Oracle / Amazon Linux)
  • zypperphp_curl(SLES)
  • apt (Debian / Ubuntu)
  • scp, curl, unzip, tarwgetgcc*
  • OpenSSL(v1.01,內部版本16或更高版本)
  • Python(帶python-devel *)

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

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

free -m

本地倉庫

若是網速不夠快,咱們能夠將包下載下來,創建本地倉庫。網速夠快能夠忽略這步。

先下載安裝包

安裝httpd服務

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外的實時計算組件,須要手動安裝,也方便之後的升級。

集羣安裝

集羣安裝分爲如下幾步:

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

二、選擇一個做爲master節點,而後修改全部機器conf/flink-conf.yaml

jobmanager.rpc.address = master主機名

三、修改conf/slaves,將全部work節點寫入

work01
work02

四、在master上啓動集羣

bin/start-cluster.sh

安裝在Hadoop

咱們能夠選擇讓Flink運行在Yarn集羣上。

下載Flink for Hadoop的包

保證 HADOOP_HOME已經正確設置便可

啓動 bin/yarn-session.sh

運行flink示例程序

批處理示例:

提交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集羣部署

部署建議

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

  • 主節點部署 Coordinator 和 Overlord進程
  • 兩個數據節點運行 Historical 和 MiddleManager進程
  • 一個查詢節點 部署Broker 和 Router進程

將來咱們能夠添加更多的主節點和查詢節點

主節點建議 8vCPU 32GB內存

配置文件位於

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

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

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

參考文獻

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

更多實時數據分析相關博文與科技資訊,歡迎關注 「實時流式計算」 詳細ambari官網安裝文檔pdf請在關注「實時流式計算」 後臺回覆ambari

相關文章
相關標籤/搜索