yum install autoconf automake cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-plain flex gcc gcc-c++ gdb git java-1.8.0-openjdk-devel krb5-server krb5-workstation libtool make openssl-devel patch pkgconfig redhat-lsb-core rsyncunzip vim-common which -y |
cd /data git clone https://github.com/apache/kudu cd kudu build-support/enable_devtoolset.sh |
mkdir thirdparty/src/ cd thirdparty/src/ wget http://d3dr9sfxru4sde.cloudfront.net/glog-0.3.5.tar.gz wget http://d3dr9sfxru4sde.cloudfront ... elease-1.8.0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/gflags-2.2.0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/gperftools-2.6.90.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/protobuf-3.4.1.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/cmake-3.9.0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/snappy-1.1.4.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/zlib-1.2.8.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/libev-4.20.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/rapidjson-0.11.zip wget http://d3dr9sfxru4sde.cloudfront.net/squeasel- 9335b81317a6451d5a37c5dc7ec088eecbf68c82.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/mustache- 87a592e8aa04497764c533acd6e887618ca7b8a8.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/google-styleguide- 7a179d1ac2e08a5cc1622bec900d1e0452776713.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/gcovr-3.0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/curl-7.59.0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/crcutil- 42148a6df6986a257ab21c80f8eca2e54544ac4d.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/libunwind-1.3-rc1.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/python-2.7.13.tar.gz wget http://d3dr9sfxru4sde.cloudfront ... iwyu-0.9.src.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/lz4-lz4-r130.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/bitshuffle-55f9b4c.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/nvml-1.1.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/boost_1_61_0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/breakpad- 9eac2058b70615519b2c4d8c6bdbfca1bd079e39.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/sparsehash-c11- 47a55825ca3b35eab1ca22b7ab82b9544e32a9af.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/sparsepp- 824860bb76893d163efbcff330734b9f62eecb17.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/thrift-0.11.0.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/bison-3.0.4.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/hive- 498021fa15186aee8b282d3c032fbd2cede6bec4-stripped.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/hadoop-2.8.5-stripped.tar.gz wget http://d3dr9sfxru4sde.cloudfront.net/apache-sentry- 2c9a927a9e87cba0e4c0f34fc0b55887c6636927-bin.tar.gz |
cd ../../ thirdparty/build-if-necessary.sh # 这个命令会把上面下载的依赖全部安装执行Kudu 的./configura |
mkdir build/release -p cd build/release/ ../../build-support/enable_devtoolset.sh |
../../thirdparty/installed/common/bin/cmake DCMAKE_BUILD_TYPE=release ../.. make -j4 make DESTDIR=/data/kudu/build/release/kudu install |
ln -s /data/kudu/build/release/kudu/usr/local/include/* /usr/local/include/ ln -s /data/kudu/build/release/kudu/usr/local/lib64/* /usr/local/lib64/ ln -s /data/kudu/build/release/kudu/usr/local/share/* /usr/local/share/ ======== MASTER ======== mkdir conf cd conf cat >>master.gflagfile<<EOF ## Comma-separated list of the RPC addresses belonging to all Masters in this cluster. ## NOTE: if not specified, configures a non-replicated Master. --master_addresses=kudu1:7051,kudu2:7051,kudu3:7051 --rpc_bind_addresses=kudu1:7051 --fs_wal_dir=/data/kudu_data/master/wal --fs_data_dirs=/data/kudu_data/master/data --enable_process_lifetime_heap_profiling=true --heap_profile_path=/data/kudu_data/master/heap --rpc-encryption=disabled --rpc_authentication=disabled #--unlock_unsafe_flags=true #--allow_unsafe_replication_factor=true #--max_log_size=1800 --max_log_size=2048 #--memory_limit_hard_bytes=0 --memory_limit_hard_bytes=1073741824 --default_num_replicas=3 --max_clock_sync_error_usec=10000000 --consensus_rpc_timeout_ms=30000 --follower_unavailable_considered_failed_sec=300 --leader_failure_max_missed_heartbeat_periods=3 #--block_manager_max_open_files=10240 #--server_thread_pool_max_thread_count=-1 --tserver_unresponsive_timeout_ms=60000 --rpc_num_service_threads=10 --max_negotiation_threads=50 --min_negotiation_threads=10 --rpc_negotiation_timeout_ms=3000 --rpc_default_keepalive_time_ms=65000 #--rpc_num_acceptors_per_address=1 --rpc_num_acceptors_per_address=5 #--master_ts_rpc_timeout_ms=30000 --master_ts_rpc_timeout_ms=60000 #--remember_clients_ttl_ms=60000 --remember_clients_ttl_ms=3600000 #--remember_responses_ttl_ms=60000 --remember_responses_ttl_ms=600000 #--rpc_service_queue_length=50 --rpc_service_queue_length=1000 #--raft_heartbeat_interval_ms=500 --raft_heartbeat_interval_ms=60000 #--heartbeat_interval_ms=1000 --heartbeat_interval_ms=60000 --heartbeat_max_failures_before_backoff=3 ## You can avoid the dependency on ntpd by running Kudu with --use-hybrid- clock=false ## This is not recommended for production environment. ## NOTE: If you run without hybrid time the tablet history ## forever. Eventually you may run out of disk space. --use_hybrid_clock=false --webserver_enabled=true --metrics_log_interval_ms=60000 --webserver_port=8051 #--webserver_doc_root=/data/kudu/www EOF ======== TSERVER ========= cat >>tserver.gflagfile<<EOF ## Comma-separated list of the RPC addresses belonging to all Masters in this cluster. ## NOTE: if not specified, configures a non-replicated Master. --tserver_master_addrs=kudu1:7051,kudu2:7051,kudu3:7051 --rpc_bind_addresses=kudu:7050 --log_dir=/data/kudu_data/tserver/logs --log_filename=kudu1 --fs_wal_dir=/data/kudu_data/tserver/wal --fs_data_dirs=/data/kudu_data/tserver/data --enable_process_lifetime_heap_profiling=true --heap_profile_path=/data/kudu_data/tserver/heap --rpc-encryption=disabled --rpc_authentication=disabled #--unlock_unsafe_flags=true #--allow_unsafe_replication_factor=true #--max_log_size=1800 --max_log_size=2048 #--memory_limit_hard_bytes=0 --memory_limit_hard_bytes=1073741824 --default_num_replicas=3 --max_clock_sync_error_usec=10000000 --consensus_rpc_timeout_ms=30000 --follower_unavailable_considered_failed_sec=300 --leader_failure_max_missed_heartbeat_periods=3 #--block_manager_max_open_files=10240 #--server_thread_pool_max_thread_count=-1 --tserver_unresponsive_timeout_ms=60000 --rpc_num_service_threads=10 --max_negotiation_threads=50 --min_negotiation_threads=10 --rpc_negotiation_timeout_ms=3000 --rpc_default_keepalive_time_ms=65000 #--rpc_num_acceptors_per_address=1 --rpc_num_acceptors_per_address=5 #--master_ts_rpc_timeout_ms=30000 --master_ts_rpc_timeout_ms=60000 #--remember_clients_ttl_ms=60000 #--remember_responses_ttl_ms=60000 --remember_responses_ttl_ms=600000 #--rpc_service_queue_length=50 --rpc_service_queue_length=1000 #--raft_heartbeat_interval_ms=500 --raft_heartbeat_interval_ms=60000 #--heartbeat_interval_ms=1000 --heartbeat_interval_ms=60000 --heartbeat_max_failures_before_backoff=3 ## You can avoid the dependency on ntpd by running Kudu with --use-hybrid- clock=false ## This is not recommended for production environment. ## NOTE: If you run without hybrid time the tablet history GC will not work. ## Therefore when you delete or update a row the history of that data will be kept ## forever. Eventually you may run out of disk space. --use_hybrid_clock=false --webserver_enabled=true --metrics_log_interval_ms=60000 --webserver_port=8050 #--webserver_doc_root=/data/kudu/www EOF |
========= MASTER ========= cat >>/usr/lib/systemd/system/kudu-master.service<<EOF [Unit] Description=Apache Kudu Master Server Documentation=http://kudu.apache.org [Service] Environment=KUDU_HOME=/data/kudu ExecStart=/data/kudu/build/release/bin/kudu-master -- flagfile=/data/kudu/build/release/conf/master.gflagfile TimeoutStopSec=5 Restart=on-failure User=kudu #LimitNOFILE=65535 #LimitNPROC=10240 [Install] WantedBy=multi-user.target EOF ========= TSERVER ========= cat >>/usr/lib/systemd/system/kudu-tserver.service<<EOF [Unit] Description=Apache Kudu Master Server Documentation=http://kudu.apache.orgEnvironment=KUDU_HOME=/data/kudu ExecStart=/data/kudu/build/release/bin/kudu-tserver -- flagfile=/data/kudu/build/release/conf/tserver.gflagfile TimeoutStopSec=5 Restart=on-failure User=kudu #LimitNOFILE=65535 #LimitNPROC=10240 [Install] WantedBy=multi-user.target EOF |
useradd kudu |
mkdir /data/kudu_data/{master,tserver}/{data,wal,logs,heap} -p chown -R kudu.kudu /data/kudu_data/ chown -R kudu.kudu /data/kudu/ cd /data |
cat >>/etc/profile<<EOF export PATH=${PATH}:/data/kudu/build/release/bin EOF source /etc/profile 启动程序
构建maven工程、导入依赖 |
/** * 创建表 */ @Test public void createTable() throws KuduException { //判断表是否存在,不存在就构建 if(!kuduClient.tableExists(tableName)){ //构建创建表的schema信息-----就是表的字段和类型 ArrayList<ColumnSchema> columnSchemas = new ArrayList<ColumnSchema>(); columnSchemas.add(new ColumnSchema.ColumnSchemaBuilder("id", Type.INT32).key(true).build()); columnSchemas.add(new ColumnSchema.ColumnSchemaBuilder("name", Type.STRING).build()); columnSchemas.add(new ColumnSchema.ColumnSchemaBuilder("sex", Type.INT32).build()); Schema schema = new Schema(columnSchemas); //指定创建表的相关属性 CreateTableOptions options = new CreateTableOptions(); ArrayList<String> partitionList = new ArrayList<String>(); //指定kudu表的分区字段是什么 partitionList.add("id"); // 按照 id.hashcode % 分区数 = 分区号 options.addHashPartitions(partitionList,6); kuduClient.createTable(tableName,schema,options); } } |
/** * 向表加载数据 */ @Test public void insertTable() throws KuduException { //向表加载数据需要一个kuduSession对象 KuduSession kuduSession = kuduClient.newSession(); kuduSession.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); //需要使用kuduTable来构建Operation的子类实例对象 KuduTable kuduTable = kuduClient.openTable(tableName); for(int i=1;i<=10;i++){ Insert insert = kuduTable.newInsert(); PartialRow row = insert.getRow(); row.addInt("id",i); row.addString("name","zhangsan-"+i); row.addInt("age",20+i); row.addInt("sex",i%2); kuduSession.apply(insert);//最后实现执行数据的加载操作 } } |
/** * 查询表的数据结果 */ @Test public void queryData() throws KuduException { //构建一个查询的扫描器 KuduScanner.KuduScannerBuilder kuduScannerBuilder = kuduClient.newScannerBuilder(kuduClient.openTable(tableName)); columnsList.add("name"); columnsList.add("age"); columnsList.add("sex"); kuduScannerBuilder.setProjectedColumnNames(columnsList); //返回结果集 KuduScanner kuduScanner = kuduScannerBuilder.build(); //遍历 while (kuduScanner.hasMoreRows()){ RowResultIterator rowResults = kuduScanner.nextRows(); while (rowResults.hasNext()){ RowResult row = rowResults.next(); int id = row.getInt("id"); String name = row.getString("name"); int age = row.getInt("age"); int sex = row.getInt("sex"); System.out.println("id="+id+" name="+name+" age="+age+" sex="+sex); } } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |