cassandra 学习(本文教你如何快速部署cassandra)
- 一、部署
- 二、故障解决
一、部署
主机ip:
node1 172.31.0.44
node2 172.31.0.43
node3 172.31.0.40
1、添加cassandra网络yum源 [root@k8s-master ~]# cat >/etc/yum.repos.d/cassandra.repo <<EOF [cassandra] name=Apache Cassandra baseurl=https://www.apache.org/dist/cassandra/redhat/311x/ gpgcheck=1 repo_gpgcheck=1 gpgkey=https://www.apache.org/dist/cassandra/KEYS EOF
2、安装cassandra [root@k8s-master ~]# yum -y install cassandra
Complete!
3、修改配置文件配置集群信息
[root@k8s-master ~]# vim /etc/cassandra/conf/cassandra.yaml [root@k8s-master ~]# cat /etc/cassandra/conf/cassandra.yaml|grep -v '#'|sed '/^ *$/d' cluster_name: 'Test Cluster' num_tokens: 256 hinted_handoff_enabled: true hinted_handoff_throttle_in_kb: 1024 max_hints_delivery_threads: 2 hints_directory: /var/lib/cassandra/hints hints_flush_period_in_ms: 10000 max_hints_file_size_in_mb: 128 batchlog_replay_throttle_in_kb: 1024 authenticator: AllowAllAuthenticator authorizer: AllowAllAuthorizer role_manager: CassandraRoleManager roles_validity_in_ms: 2000 permissions_validity_in_ms: 2000 credentials_validity_in_ms: 2000 partitioner: org.apache.cassandra.dht.Murmur3Partitioner data_file_directories: - /var/lib/cassandra/data commitlog_directory: /var/lib/cassandra/commitlog cdc_enabled: false disk_failure_policy: stop commit_failure_policy: stop prepared_statements_cache_size_mb: thrift_prepared_statements_cache_size_mb: key_cache_size_in_mb: key_cache_save_period: 14400 row_cache_size_in_mb: 0 row_cache_save_period: 0 counter_cache_size_in_mb: counter_cache_save_period: 7200 saved_caches_directory: /var/lib/cassandra/saved_caches commitlog_sync: periodic commitlog_sync_period_in_ms: 10000 commitlog_segment_size_in_mb: 32 seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: - seeds: "172.31.0.44,172.31.0.43,172.31.0.40" #节点ip concurrent_reads: 32 concurrent_writes: 32 concurrent_counter_writes: 32 concurrent_materialized_view_writes: 32 memtable_allocation_type: heap_buffers index_summary_capacity_in_mb: index_summary_resize_interval_in_minutes: 60 trickle_fsync: false trickle_fsync_interval_in_kb: 10240 storage_port: 7000 ssl_storage_port: 7001 listen_address: 172.31.0.44 #本机IP start_native_transport: true native_transport_port: 9042 start_rpc: false rpc_address: 172.31.0.44 #本机IP rpc_port: 9160 rpc_keepalive: true rpc_server_type: sync thrift_framed_transport_size_in_mb: 15 incremental_backups: false snapshot_before_compaction: false auto_snapshot: true column_index_size_in_kb: 64 column_index_cache_size_in_kb: 2 compaction_throughput_mb_per_sec: 16 sstable_preemptive_open_interval_in_mb: 50 read_request_timeout_in_ms: 5000 range_request_timeout_in_ms: 10000 write_request_timeout_in_ms: 2000 counter_write_request_timeout_in_ms: 5000 cas_contention_timeout_in_ms: 1000 truncate_request_timeout_in_ms: 60000 request_timeout_in_ms: 10000 slow_query_log_timeout_in_ms: 500 cross_node_timeout: false endpoint_snitch: SimpleSnitch dynamic_snitch_update_interval_in_ms: 100 dynamic_snitch_reset_interval_in_ms: 600000 dynamic_snitch_badness_threshold: 0.1 request_scheduler: org.apache.cassandra.scheduler.NoScheduler server_encryption_options: internode_encryption: none keystore: conf/.keystore keystore_password: cassandra truststore: conf/.truststore truststore_password: cassandra client_encryption_options: enabled: false optional: false keystore: conf/.keystore keystore_password: cassandra internode_compression: dc inter_dc_tcp_nodelay: false tracetype_query_ttl: 86400 tracetype_repair_ttl: 604800 enable_user_defined_functions: false enable_scripted_user_defined_functions: false enable_materialized_views: true windows_timer_interval: 1 transparent_data_encryption_options: enabled: false chunk_length_kb: 64 cipher: AES/CBC/PKCS5Padding key_alias: testing:1 key_provider: - class_name: org.apache.cassandra.security.JKSKeyProvider parameters: - keystore: conf/.keystore keystore_password: cassandra store_type: JCEKS key_password: cassandra tombstone_warn_threshold: 1000 tombstone_failure_threshold: 100000 batch_size_warn_threshold_in_kb: 5 batch_size_fail_threshold_in_kb: 50 unlogged_batch_across_partitions_warn_threshold: 10 compaction_large_partition_warning_threshold_mb: 100 gc_warn_threshold_in_ms: 1000 back_pressure_enabled: false back_pressure_strategy: - class_name: org.apache.cassandra.net.RateBasedBackPressure parameters: - high_ratio: 0.90 factor: 5 flow: FAST Cassandra中的大多数配置都是通过可以设置的yaml属性完成的cassandra.yaml。您至少应该考虑设置以下属性: cluster_name:群集的名称。 seeds:种子节点至少为两个个或者多个(不能是全部节点),以逗号分隔的群集种子IP地址列表,建议将两个以上的节点作为种子节点,不建议所有的节点加入种子节点。 storage_port:如果开启防火墙,确保没有防火墙阻止此端口。 listen_address:节点的IP地址,这是允许其他节点与此节点通信的因素。 native_transport_port:对于storage_port,请确保此端口未被防火墙阻止,因为客户端将在此端口上与Cassandra通信。 更改目录的位置
启动
[root@k8s-master ~]# service cassandra start Reloading systemd: [ OK ] Starting cassandra (via systemctl): [ OK ] [root@k8s-master ~]# ps -ef|grep cassandra cassand 15047 1 99 10:10 ? 00:00:29 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre/bin/java -Xloggc:/var/log/cassandra/gc.log -ea -XX: UseThreadPriorities -XX:ThreadPriorityPolicy=42 -XX: HeapDumpOnOutOfMemoryError -Xss256k -XX:StringTableSize=1000003 -XX: AlwaysPreTouch -XX:-UseBiasedLocking -XX: UseTLAB -XX: ResizeTLAB -XX: UseNUMA -XX: PerfDisableSharedMem -Djava.net.preferIPv4Stack=true -XX: UseParNewGC -XX: UseConcMarkSweepGC -XX: CMSParallelRemarkEnabled -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=1 -XX:CMSInitiatingOccupancyFraction=75 -XX: UseCMSInitiatingOccupancyOnly -XX:CMSWaitDuration=10000 -XX: CMSParallelInitialMarkEnabled -XX: CMSEdenChunksRecordAlways -XX: CMSClassUnloadingEnabled -XX: PrintGCDetails -XX: PrintGCDateStamps -XX: PrintHeapAtGC -XX: PrintTenuringDistribution -XX: PrintGCApplicationStoppedTime -XX: PrintPromotionFailure -XX: UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M -Xms8003M -Xmx8003M -Xmn800M -XX: UseCondCardMark -XX:CompileCommandFile=/etc/cassandra/conf/hotspot_compiler -javaagent:/usr/share/cassandra/lib/jamm-0.3.0.jar -Dcassandra.jmx.local.port=7199 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.password.file=/etc/cassandra/jmxremote.password -Djava.library.path=/usr/share/cassandra/lib/sigar-bin -Dcassandra.libjemalloc=/usr/lib64/libjemalloc.so.1 -XX:OnOutOfMemoryError=kill -9 %p -Dlogback.configurationFile=logback.xml -Dcassandra.logdir=/var/log/cassandra -Dcassandra.storagedir= -Dcassandra-pidfile=/var/run/cassandra/cassandra.pid -cp /etc/cassandra/conf:/usr/share/cassandra/lib/airline-0.6.jar:/usr/share/cassandra/lib/antlr-runtime-3.5.2.jar:/usr/share/cassandra/lib/asm-5.0.4.jar:/usr/share/cassandra/lib/caffeine-2.2.6.jar:/usr/share/cassandra/lib/cassandra-driver-core-3.0.1-shaded.jar:/usr/share/cassandra/lib/commons-cli-1.1.jar:/usr/share/cassandra/lib/commons-codec-1.9.jar:/usr/share/cassandra/lib/commons-lang3-3.1.jar:/usr/share/cassandra/lib/commons-math3-3.2.jar:/usr/share/cassandra/lib/compress-lzf-0.8.4.jar:/usr/share/cassandra/lib/concurrentlinkedhashmap-lru-1.4.jar:/usr/share/cassandra/lib/concurrent-trees-2.4.0.jar:/usr/share/cassandra/lib/disruptor-3.0.1.jar:/usr/share/cassandra/lib/ecj-4.4.2.jar:/usr/share/cassandra/lib/guava-18.0.jar:/usr/share/cassandra/lib/HdrHistogram-2.1.9.jar:/usr/share/cassandra/lib/high-scale-lib-1.0.6.jar:/usr/share/cassandra/lib/hppc-0.5.4.jar:/usr/share/cassandra/lib/jackson-core-asl-1.9.13.jar:/usr/share/cassandra/lib/jackson-mapper-asl-1.9.13.jar:/usr/share/cassandra/lib/jamm-0.3.0.jar:/usr/share/cassandra/lib/javax.inject.jar:/usr/share/cassandra/lib/jbcrypt-0.3m.jar:/usr/share/cassandra/lib/jcl-over-slf4j-1.7.7.jar:/usr/share/cassandra/lib/jctools-core-1.2.1.jar:/usr/share/cassandra/lib/jflex-1.6.0.jar:/usr/share/cassandra/lib/jna-4.2.2.jar:/usr/share/cassandra/lib/joda-time-2.4.jar:/usr/share/cassandra/lib/json-simple-1.1.jar:/usr/share/cassandra/lib/jstackjunit-0.0.1.jar:/usr/share/cassandra/lib/libthrift-0.9.2.jar:/usr/share/cassandra/lib/log4j-over-slf4j-1.7.7.jar:/usr/share/cassandra/lib/logback-classic-1.1.3.jar:/usr/share/cassandra/lib/logback-core-1.1.3.jar:/usr/share/cassandra/lib/lz4-1.3.0.jar:/usr/share/cassandra/lib/metrics-core-3.1.5.jar:/usr/share/cassandra/lib/metrics-jvm-3.1.5.jar:/usr/share/cassandra/lib/metrics-logback-3.1.5.jar:/usr/share/cassandra/lib/netty-all-4.0.44.Final.jar:/usr/share/cassandra/lib/ohc-core-0.4.4.jar:/usr/share/cassandra/lib/ohc-core-j8-0.4.4.jar:/usr/share/cassandra/lib/reporter-config3-3.0.3.jar:/usr/share/cassandra/lib/reporter-config-base-3.0.3.jar:/usr/share/cassandra/lib/sigar-1.6.4.jar:/usr/share/cassandra/lib/slf4j-api-1.7.7.jar:/usr/share/cassandra/lib/snakeyaml-1.11.jar:/usr/share/cassandra/lib/snappy-java-1.1.1.7.jar:/usr/share/cassandra/lib/snowball-stemmer-1.3.0.581.1.jar:/usr/share/cassandra/lib/ST4-4.0.8.jar:/usr/share/cassandra/lib/stream-2.5.2.jar:/usr/share/cassandra/lib/thrift-server-0.3.7.jar:/usr/share/cassandra/apache-cassandra-3.11.3.jar:/usr/share/cassandra/apache-cassandra-thrift-3.11.3.jar:/usr/share/cassandra/stress.jar: org.apache.cassandra.service.CassandraDaemon root 15308 3906 0 10:11 pts/1 00:00:00 grep --color=auto cassandra
4、登录验证
[root@k8s-master ~]# cqlsh 172.31.0.44
Connected to Test Cluster at 172.31.0.44:9042.
[cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> exit
5、查看集群转态
[root@k8s-master ~]# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.31.0.44 69.95 KiB 256 74.3% 8122f9ae-f85e-4026-a864-131c3f628284 rack1
UN 172.31.0.43 69.89 KiB 256 62.0% ae46627f-6e7f-4194-a2b4-90c443530a49 rack1
UN 172.31.0.40 69.91 KiB 256 63.7% f81b3304-44f6-4282-8e89-ae860b39ddd4 rack1
二、故障解决
1、错误: 日志:
[root@cassandra01 conf]# tail -f /var/log/cassandra/cassandra.log OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000cc800000, 864026624, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 864026624 bytes for committing reserved memory. # An error report file with more information is saved as: # /tmp/hs_err_pid31935.log
解决方法: 调整内存参数
vim jvm.options #参数默认关闭,打开并修改为512m #-Xms4g #-Xmx4g -Xms512m -Xmx512m
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com