怎么设置nodetool使用用户名密码访问

cassandra的nodetool工具使用jdk的jmx和cassandra节点通信。
nodetool是集群的重要管理工具。

在cassandra2.0版本中,nodetool默认是允许远程访问,其不需要密码的。
在cassandra2.1版本中,nodetool默认是只允许本机访问,很不方便,
如果远程访问功能打开,又不安全,防止别人乱操作,好方法就是加上访问权限控制。

第一步:打开远程访问权限
编辑conf/cassandra-env.sh文件。
找到:
LOCAL_JMX=yes 默认值监听localhost,只允许本机访问。
改为
LOCAL_JMX=no 表示远程也可以访问。

第二步:指定密码文件
同一文件,找到如下配置项:
JVM_OPTS=”$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true”
JVM_OPTS=”$JVM_OPTS -Dcom.sun.management.jmxremote.password.file=/home/cassandra/jmxremote.password”

第三步:创建密码文件

vi /home/cassandra/jmxremote.password
输入
myusername mypassword

注意:修改文件权限只能本用户访问:
chmod go-rwx /home/cassandra/jmxremote.password
否则启动的时候会报错
Error: Password file read access must be restricted: /home/cassandra/jmxremote.password

第四步:配置access文件
access权限控制权限,默认使用jdk目录下的:
$JAVA_HOME/jre/lib/management/jmxremote.access

写入myusername有读写权限
myusername readwrite

该文件也可以通过-Dcom.sun.management.jmxremote.access.file选项指定。

重启cassandra之后,你需要这样使用nodetool:
bin/nodetool -u myusername -pw mypassword status

猜你喜欢

转载自longzhun.iteye.com/blog/2343509