1.1. RIAK
1.1.1. 下载RIAK
在以下URL下载RIAK 1.3.2的RPM包
$wgethttp://s3.amazonaws.com/downloads.basho.com/riak/1.3/1.3.2/rhel/6/riak-1.3.2-2.el6.x86_64.rpm
1.1.2. 安装RIAK
执行以下命令安装RIAK
$sudo rpm -Uvh riak-1.3.2-2.el6.x86_64.rpm
RIAK集群少需要3个节点方可运行(若需高可用则少需要4个节点)。
1.1.3. 配置RIAK
RIAK的配置文件位于/etc/riak文件夹下,包括vm.args和app.config两个文件:
$ >vi /etc/riak/vm.args
## Name of the riak node
-name riak@node1.surdoctest.com
## Cookie for distributed erlang. All nodes in the same cluster
## should use the same cookie or they will not be able to communicate.
-setcookie riak
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
##-heart
## Enable kernel poll and a few async threads
+K true
+A 64
## Treat error_logger warnings as warnings
+W w
## Increase number of concurrent ports/sockets
-env ERL_MAX_PORTS 64000
## Tweak GC to run more often
-env ERL_FULLSWEEP_AFTER 0
## Set the location of crash dumps
-env ERL_CRASH_DUMP /mnt/ssd/rkdata/log/erl_crash.dump
## Raise the ETS table limit
-env ERL_MAX_ETS_TABLES 256000
## Force the erlang VM to use SMP
-smp enable
## Raise the default erlang process limit
+P 256000
+zdbbl 16384
## Begin SSL distribution items, DO NOT DELETE OR EDIT THIS COMMENT
## To enable SSL encryption of the Erlang intra-cluster communication,
## un-comment the three lines below and make certain that the paths
## point to correct PEM data files. See docs TODO for details.
## -proto_dist inet_ssl
## -ssl_dist_opt client_certfile "/etc/riak/erlclient.pem"
## -ssl_dist_opt server_certfile "/etc/riak/erlserver.pem"
## End SSL distribution items, DO NOT DELETE OR EDIT THIS COMMENT
需要修改-name和-setcookie两个配置,其中-name配置当前节点的名字,@之前为节点名,可任意取,只需保证在集群内即可,@后为当前主机名或IP;-setcookie设置集群内的cookie,可任意取,但集群内各个节点必须一致。
$ >vi /etc/riak/app.config
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
[
%% Riak Client APIs config
{riak_api, [
%% pb_backlog is the maximum length to which the queue of pending
%% connections may grow. If set, it must be an integer >= 0.
%% By default the value is 5. If you anticipate a huge number of
%% connections being initialised *simultaneously*, set this number
%% higher.
{pb_backlog, 64},
%% pb_ip is the IP address that the Riak Protocol Buffers interface
%% will bind to. If this is undefined, the interface will not run.
{pb_ip, "0.0.0.0" },
%% pb_port is the TCP port that the Riak Protocol Buffers interface
%% will bind to
{pb_port, 8087 }
]},
%% Riak Core config
{riak_core, [
%% Default location of ringstate
{ring_state_dir, "/mnt/ssd30/rkdata/ring"},
%% Default ring creation size. Make sure it is a power of 2,
%% e.g. 16, 32, 64, 128, 256, 512 etc
{ring_creation_size, 128},
%% http is a list of IP addresses and TCP ports that the Riak
%% HTTP interface will bind.
{http, [ {"0.0.0.0", 8098 } ]},
%% https is a list of IP addresses and TCP ports that the Riak
%% HTTPS interface will bind.
%{https, [{ "127.0.0.1", 8098 }]},
%% Default cert and key locations for https can be overridden
%% with the ssl config variable, for example:
%{ssl, [
% {certfile, "/etc/riak/cert.pem"},
% {keyfile, "/etc/riak/key.pem"}
% ]},
%% riak_handoff_port is the TCP port that Riak uses for
%% intra-cluster data handoff.
{handoff_port, 8099 },
%% To encrypt riak_core intra-cluster data handoff traffic,
%% uncomment the following line and edit its path to an
%% appropriate certfile and keyfile. (This example uses a
%% single file with both items concatenated together.)
%{handoff_ssl_options, [{certfile, "/tmp/erlserver.pem"}]},
%% DTrace support
%% Do not enable 'dtrace_support' unless your Erlang/OTP
%% runtime is compiled to support DTrace. DTrace is
%% available in R15B01 (supported by the Erlang/OTP
%% official source package) and in R14B04 via a custom
%% source repository & branch.
{dtrace_support, false},
{default_bucket_props, [
{n_val,3},
{allow_mult,false},
{last_write_wins,false},
{precommit, []},
{postcommit, []},
{chash_keyfun, {riak_core_util, chash_std_keyfun}},
{linkfun, {modfun, riak_kv_wm_link_walker, mapreduce_linkfun}}
]},
%% Platform-specific installation paths (substituted by rebar)
{platform_bin_dir, "/usr/sbin"},
{platform_data_dir, "/var/lib/riak"},
{platform_etc_dir, "/etc/riak"},
{platform_lib_dir, "/usr/lib64/riak"},
{platform_log_dir, "/var/log/riak"}
]},
%% Riak KV config
{riak_kv, [
%% Storage_backend specifies the Erlang module defining the storage
%% mechanism that will be used on this node.
{storage_backend, riak_kv_eleveldb_backend},
%% raw_name is the first part of all URLS used by the Riak raw HTTP
%% interface. See riak_web.erl and raw_http_resource.erl for
%% details.
%{raw_name, "riak"},
%% Enable active anti-entropy subsystem + optional debug messages:
%% {anti_entropy, {on|off, []}},
%% {anti_entropy, {on|off, [debug]}},
{anti_entropy, {on, []}},
%% Restrict how fast AAE can build hash trees. Building the tree
%% for a given partition requires a full scan over that partition's
%% data. Once built, trees stay built until they are expired.
%% Config is of the form:
%% {num-builds, per-timespan-in-milliseconds}
%% Default is 1 build per hour.
{anti_entropy_build_limit, {1, 3600000}},
%% Determine how often hash trees are expired after being built.
%% Periodically expiring a hash tree ensures the on-disk hash tree
%% data stays consistent with the actual k/v backend data. It also
%% helps Riak identify silent disk failures and bit rot. However,
%% expiration is not needed for normal AAE operation and should be
%% infrequent for performance reasons. The time is specified in
%% milliseconds. The default is 1 week.
{anti_entropy_expire, 604800000},
%% Limit how many AAE exchanges/builds can happen concurrently.
{anti_entropy_concurrency, 2},
%% The tick determines how often the AAE manager looks for work
%% to do (building/expiring trees, triggering exchanges, etc).
%% The default is every 15 seconds. Lowering this value will
%% speedup the rate that all replicas are synced across the cluster.
%% Increasing the value is not recommended.
{anti_entropy_tick, 15000},
%% The directory where AAE hash trees are stored.
{anti_entropy_data_dir, "/mnt/ssd30/rkdata/anti_entropy"},
%% The LevelDB options used by AAE to generate the LevelDB-backed
%% on-disk hashtrees.
{anti_entropy_leveldb_opts, [{write_buffer_size, 4194304},
{max_open_files, 40}]},
%% mapred_name is URL used to submit map/reduce requests to Riak.
{mapred_name, "mapred"},
%% mapred_system indicates which version of the MapReduce
%% system should be used: 'pipe' means riak_pipe will
%% power MapReduce queries, while 'legacy' means that luke
%% will be used
{mapred_system, pipe},
%% mapred_2i_pipe indicates whether secondary-index
%% MapReduce inputs are queued in parallel via their own
%% pipe ('true'), or serially via a helper process
%% ('false' or undefined). Set to 'false' or leave
%% undefined during a rolling upgrade from 1.0.
{mapred_2i_pipe, true},
%% directory used to store a transient queue for pending
%% map tasks
%% Only valid when mapred_system == legacy
%% {mapred_queue_dir, "/var/lib/riak/mr_queue" },
%% Each of the following entries control how many Javascript
%% virtual machines are available for executing map, reduce,
%% pre- and post-commit hook functions.
{map_js_vm_count, 16 },
{reduce_js_vm_count, 12 },
{hook_js_vm_count, 4 },
%% Number of items the mapper will fetch in one request.
%% Larger values can impact read/write performance for
%% non-MapReduce requests.
%% Only valid when mapred_system == legacy
%% {mapper_batch_size, 5},
%% js_max_vm_mem is the maximum amount of memory, in megabytes,
%% allocated to the Javascript VMs. If unset, the default is
%% 8MB.
{js_max_vm_mem, 32},
%% js_thread_stack is the maximum amount of thread stack, in megabyes,
%% allocate to the Javascript VMs. If unset, the default is 16MB.
%% NOTE: This is not the same as the C thread stack.
{js_thread_stack, 64},
%% Number of objects held in the MapReduce cache. These will be
%% ejected when the cache runs out of room or the bucket/key
%% pair for that entry changes
%% Only valid when mapred_system == legacy
%% {map_cache_size, 10000},
%% js_source_dir should point to a directory containing Javascript
%% source files which will be loaded by Riak when it initializes
%% Javascript VMs.
%{js_source_dir, "/tmp/js_source"},
%% http_url_encoding determines how Riak treats URL encoded
%% buckets, keys, and links over the REST API. When set to 'on'
%% Riak always decodes encoded values sent as URLs and Headers.
%% Otherwise, Riak defaults to compatibility mode where links
%% are decoded, but buckets and keys are not. The compatibility
%% mode will be removed in a future release.
{http_url_encoding, on},
%% Switch to vnode-based vclocks rather than client ids. This
%% significantly reduces the number of vclock entries.
%% Only set true if *all* nodes in the cluster are upgraded to 1.0
{vnode_vclocks, true},
%% This option enables compatability of bucket and key listing
%% with 0.14 and earlier versions. Once a rolling upgrade to
%% a version > 0.14 is completed for a cluster, this should be
%% set to false for improved performance for bucket and key
%% listing operations.
{legacy_keylisting, false},
%% This option toggles compatibility of keylisting with 1.0
%% and earlier versions. Once a rolling upgrade to a version
%% > 1.0 is completed for a cluster, this should be set to
%% true for better control of memory usage during key listing
%% operations
{listkeys_backpressure, true}
]},
%% Riak Search Config
{riak_search, [
%% To enable Search functionality set this 'true'.
{enabled, false}
]},
%% Merge Index Config
{merge_index, [
%% The root dir to store search merge_index data
{data_root, "/mnt/ssd30/rkdata/merge_index"},
%% Size, in bytes, of the in-memory buffer. When this
%% threshold has been reached the data is transformed
%% into a segment file which resides on disk.
{buffer_rollover_size, 1048576},
%% Overtime the segment files need to be compacted.
%% This is the maximum number of segments that will be
%% compacted at once. A lower value will lead to
%% quicker but more frequent compactions.
{max_compact_segments, 20}
]},
%% Bitcask Config
{bitcask, [
{data_root, "/mnt/ssd30/rkdata/bitcask"}
]},
%% eLevelDB Config
{eleveldb, [
{data_root, "/mnt/ssd30/rkdata/leveldb"},
{write_buffer_size_min, 31457280},
{write_buffer_size_max, 62914560},
{max_open_files, 40},
{block_size, 524288},
{block_restart_interval, 16},
{cache_size, 524288000},
{sync, false},
{verify_checksums, false}
]},
%% Lager Config
{lager, [
%% What handlers to install with what arguments
%% The defaults for the logfiles are to rotate the files when
%% they reach 10Mb or at midnight, whichever comes first, and keep
%% the last 5 rotations. See the lager README for a description of
%% the time rotation format:
%% https://github.com/basho/lager/blob/master/README.org
%%
%% If you wish to disable rotation, you can either set the size to 0
%% and the rotation time to "", or instead specify a 2-tuple that only
%% consists of {Logfile, Level}.
{handlers, [
{lager_console_backend, info},
{lager_file_backend, [
{"/mnt/ssd30/rkdata/log/error.log", error, 10485760, "$D0", 5},
{"/mnt/ssd30/rkdata/log/console.log", info, 10485760, "$D0", 5}
]}
]},
%% Whether to write a crash log, and where.
%% Commented/omitted/undefined means no crash logger.
{crash_log, "/mnt/ssd30/rkdata/log/crash.log"},
%% Maximum size in bytes of events in the crash log - defaults to 65536
{crash_log_msg_size, 65536},
%% Maximum size of the crash log in bytes, before its rotated, set
%% to 0 to disable rotation - default is 0
{crash_log_size, 10485760},
%% What time to rotate the crash log - default is no time
%% rotation. See the lager README for a description of this format:
%% https://github.com/basho/lager/blob/master/README.org
{crash_log_date, "$D0"},
%% Number of rotated crash logs to keep, 0 means keep only the
%% current one - default is 0
{crash_log_count, 5},
%% Whether to redirect error_logger messages into lager - defaults to true
{error_logger_redirect, true}
]},
%% riak_sysmon config
{riak_sysmon, [
%% To disable forwarding events of a particular type, use a
%% limit of 0.
{process_limit, 30},
{port_limit, 2},
%% Finding reasonable limits for a given workload is a matter
%% of experimentation.
{gc_ms_limit, 100},
{heap_word_limit, 40111000},
%% Configure the following items to 'false' to disable logging
%% of that event type.
{busy_port, true},
{busy_dist_port, true}
]},
%% SASL config
{sasl, [
{sasl_error_logger, false}
]},
%% riak_control config
{riak_control, [
%% Set to false to disable the admin panel.
{enabled, false},
%% Authentication style used for access to the admin
%% panel. Valid styles are 'userlist' <TODO>.
{auth, userlist},
%% If auth is set to 'userlist' then this is the
%% list of usernames and passwords for access to the
%% admin panel.
{userlist, [{"user", "pass"}
]},
%% The admin panel is broken up into multiple
%% components, each of which is enabled or disabled
%% by one of these settings.
{admin, true}
]}
].
需要配置的配置节有以下几部分:
riak_api配置节下的pb_ip:二进制协议的绑定IP,一般设为0.0.0.0即可
riak_api配置节下的pb_ip:二进制协议的绑定端口
riak_core配置节下的ring_state_dir:存储hash数据的文件夹
riak_core配置节下的ring_creation_size:hash的分块数,默认值为64,可酌情增加(需是2的幂)
riak_core配置节下的http:http协议的绑定IP和端口
riak_core配置节下的handoff_port:节点间执行handoff操作的端口号
riak_core配置节下的default_bucket_props:默认的bucket设置
riak_kv配置节下的storage_backend:RIAK的后端存储引擎,需设置为riak_kv_eleveldb_backend
riak_kv配置节下的anti_entropy_data_dir:自动反熵数据的存储目录
merge_index配置节下的data_root:索引合并数据的存储目录
eleveldb配置节下的data_root:RIAK数据的主存储目录
eleveldb配置节下的其他配置参考上边的配置
lager配置节为日志配置,可根据情况进行设置
1.1.4. 启动RIAK节点
1) 先决条件
启动RIAK节点前,首先查看一下系统的文件描述符限制:
$ulimit-n
如果过小(1024以下)可提高该值:
$ulimit-SHn 65536
2) 启动RIAK
通过以下命令启动RIAK:
$ riak start
成功启动将不会有任何信息输出,如果启动节点出现问题会有错误信息的提示。
1.1.5. 初始化bucket
需对名为security.digestBucket的bucket设置其allow_mult属性为true
$ curl -XPUT -H "Content-Type: application/json" -d '{"props":{"allow_mult":true}}' http://127.0.0.1:8098/riak/security.digestBucket
来自:https://mp.weixin.qq.com/s/G_zJUckQvx9V6XO7tjQO2Q