文件名稱 | 版本號 | 作者 | 備註 | |
---|---|---|---|---|
實操_HBase學習_持續更新。。。 | v0.0.1 | 飛豺 | 8416837 | hbase1.3.5| Ubuntu18 |
文章目錄
尊重版權,轉載請註明出處:https://blog.csdn.net/cc007cc009/article/details/101834881
概念
結構
稀疏矩陣
詞語 | 釋義 |
---|---|
稀疏矩陣 | 在矩陣中,若數值爲0的元素數目遠遠多於非0元素的數目,並且非0元素分佈沒有規律時,則稱該矩陣爲稀疏矩陣 |
稠密矩陣 | 與上述相反,若非0元素數目佔大多數時,則稱該矩陣爲稠密矩陣 |
稠密度 | 定義非零元素的總數比上矩陣所有元素的總數爲矩陣的稠密度 |
使用python打印一個稀疏矩陣看看↓
from scipy import sparse
row = [2,2,3,2]
col = [3,4,2,3]
c = sparse.coo_matrix((data,(row,col)),shape=(5,6))
print(c.toarray()) # 打印一個稀疏矩陣
非0的元素好比是數據,空Cell不佔空間。
這種結構方便存儲互聯網等數據,在統計分析時,載入數據後,可以將空值按一定規則補全。類稀疏矩陣形態的HBase表結構模擬圖↓
Scalable-可縮放的意義
schema-less無模式
每一行中,列的組成都是靈活的,行與行之間並不需要遵循相同的列定義。如第一行有三個字段,第二行卻可以有五個或兩個字段。沒有字段的部分就是0,因此與上文的稀疏矩陣結構相呼應了。
數據
異形數據
圖數據
圖數據:兩個節點之間的連接稱爲邊,節點稱爲頂點,頂點的邊數叫度數。
多租戶
多租戶間的隔離
HBase集羣中的RegionServers可以按邏輯劃分爲多個Groups,一個表可以與一個指定的Group綁定,可以將RegionServer Group理解成將一個大的集羣劃分成了多個邏輯子集羣,藉此可以實現多租戶間的隔離
管理
Zk
仲裁
如ha情境下,如果存在主Master和備Master,由Zookeeper裁定主備。
安裝
純樸的安裝包安裝-Ubuntu18.04.2
下載和配置
- 下載解壓
sudo wget http://mirrors.tuna.tsinghua.edu.cn/apache/hbase/1.3.5/hbase-1.3.5-bin.tar.gz # 下載tar包
sudo tar xvzf hbase-1.3.5-bin.tar.gz -C /home/app/
- 配置環境
cd /home/app/hbase-1.3.5/
sudo vim conf/hbase-env.sh # 配置java
echo ${JAVA_HOME} # 查看java_home,複製過去
將JAVA_HOME修正.
export HBASE_MANAGES_ZK=true # 自己管理ZK
- 配置存儲
# cd hbase根目錄
sudo vim conf/hbase-site.xml # ubuntu環境 => sudo gedit conf/hbase-site.xml
粘貼下述文件
<configuration>
<property>
<name>hbase.rootdir</name>
<!-- hdfs實例上安裝 => <value>hdfs://namenode.example.org:8020/hbase</value> -->
<value>file:///home/testuser/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/testuser/zookeeper</value>
</property>
</configuration>
以HDFS爲底層存儲的配置以及頁面截圖↓
<property>
<name>hbase.rootdir</name>
<!-- 下述地址即是Hadoop配置的HDFS-URI的子地址 -->
<value>hdfs://localhost:54310/hbase</value>
</property>
↑/hbase即是自定義的目錄
打入配置後↓
啓動
單機模式
僞集羣模式
- 簡單的啓動命令,先測試,之後再配置環境變量
# cd hbase根目錄 或者給命令配置環境變量
sh bin/start-hbase.sh
- 報錯↓
bin/start-hbase.sh: 51: [: false: unexpected operator
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:9NDPr4DH3jwecYKReeFtLrB6JnDVK8I8rGb6J5QOvf4.
Are you sure you want to continue connecting (yes/no)?
- 填入yes,繼續報錯↓
Are you sure you want to continue connecting (yes/no)? yes
localhost: Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
localhost: ssh_dispatch_run_fatal: Connection to 127.0.0.1 port 22: Broken pipe
mkdir: cannot create directory ‘/home/app/hbase-1.3.5/bin/../logs’: Permission denied
starting master, logging to /home/app/hbase-1.3.5/bin/../logs/hbase-abuntucc-master-ubuntu.out
/home/app/hbase-1.3.5/bin/hbase-daemon.sh: line 189: /home/app/hbase-1.3.5/bin/../logs/hbase-abuntucc-master-ubuntu.out: No such file or directory
↑沒有權限創建日誌目錄。
# 解決Broken pipe ↓
ssh -o ServerAliveInterval=60 [email protected]
使用母機Windows遠程連接該ubuntu服務器試試。
下載遠程軟件FinalShell
=> 點擊下載
連接成功↓
遠程後,結果一樣。
- 於是給目錄授權試試=>
sudo chmod 777 -R hbase-1.3.5/
,啓動ing↓
- 報錯分析
51: [: false: unexpected operator
# 解決
sudo chown -R abuntucc hbase-1.3.5/
sudo passwd root # root密碼設置
- 授權數據目錄
sudo chown -R abuntucc testuser/
sudo chmod 777 -R testuser/
- 啓動日誌,master的報錯:
Could not start ZK at requested port of 2181. ZK was started at port: 2182. Aborting as clients (e.g. shell) will not be able to find this ZK quorum.
↑找不到ZK
- 開啓分佈式,
conf/hbase-site.xml
增加↓
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
- 再次啓動,啓動成功,顯示三個進程↓
如果換了虛擬機ip,啓動時,HRegionServer報錯:連接之前的ip:16000這個地址失敗。那就需要將ip還原。
起始ip改爲原ip即可。可能是一個緩存bug。
進程 | 所屬節點 |
---|---|
HMaster | master |
HQuorumPeer | slave |
HRegionServer | slave |
解決每次啓動腳本都需要輸入當前系統密碼↓
sudo visudo
# 在%sudo ALL=(ALL:ALL) ALL下面添加一行
yourusername ALL=(ALL) NOPASSWD: ALL
操作
配置環境變量
sudo vim /etc/profile
# 添加↓
export HBASE_HOME=/home/app/hbase-1.3.5
export PATH=${HBASE_HOME}/bin:${JAVA_HOME}/bin:$PATH
source /etc/profile
測試成功與否,成功↓
shell操作-效率不高
建表
hbase shell # 輸入後,過一會兒出現光標,然後貼入建表命令
create 'student','Sname','Ssex','Sage','Sdept','course' # 建表
describe 'student' # 查看描述
create 'teacher',{NAME=>'username',VERSIONS=>5} # 創建表示指定保存的版本數
list # 列出所有表
列出全部表,當前只有student和teacher
添加數據,表名後的第一個參數是rowKey
put 'student','920003','Sname','9527';
put 'student','920003','Ssex','Male';
put 'student','920003','Sdept','IS';
put 'student','920005','Sname','祝枝山';
put 'student','920005','course:math','95';
put 'student','920005','course:agriculture','98'
# shell需逐條添加每個單元格,不便利.用分號間隔可以一次執行多條shell命令
查表
- 腳本
# 腳本
操作 | 命令 | 結果 |
---|---|---|
查詢全表 | scan '表名' |
|
根據行鍵查詢 | get 'student','920003' |
|
根據行鍵、族名查詢 | get 'student' ,'920005','course' |
|
根據行鍵、族名:列名查詢 | get 'student' ,'920005','course:agriculture' |
|
根據行鍵刪除一行 | deleteall 'student' ,'920003' |
|
根據行鍵、族名刪除列 | delete 'student','920003','Sage' |
|
更新數據-添加數據即可 | put 'student','920005','course:agriculture','100' | 原value==98 |
|
刪除表 | disable 'student';drop 'student' |
exit # 退出
hive操作hbase
待續。。。