介绍:
百度一下,开源神器
安装
教程参考
下载 解压 运行 操作记录 中途升级了jdk到1.8
bin目录下并没有bin/cassandra-cli 这个文件。
所以只能研究cqlsh 就涉及到要python了。
wget http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-x64.tar.gz?AuthParam=1472798727_b12d21e489365bb3f451f4967df7d694
jdk1.8
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html
注意url是windows下点下载后复制的
288 ll
289 mv jdk-8u101-linux-x64.tar.gz\?AuthParam\=1472798727_b12d21e489365bb3f451f4967df7d694 jdk.tar.gz
290 ll
291 tar -zxvf jdk.tar.gz -C /usr/local/jdk8
292 mkdir -p /usr/local/jdk8
293 tar -zxvf jdk.tar.gz -C /usr/local/jdk8
294 cd /usr/local/jdk8/
295 ll
296 cd jdk1.8.0_101/
297 pwd
298 vim /etc/profile
299 source /etc/profile
300 java -version
301 echo $JAVA_HOME
302 java -version
303 source /etc/profile
304 java -version
305 vim ~/.bashrc
306 reboot
307 java -version
308 su cassandra
309 cd /data/cassandra/
310 ll
311 cd apache-cassandra-3.7
312 ll
313 cd bin/
314 ll
315 ./cqlsh
316 ps -aux |grep cassandra
317 ps |grep cassandra
318 reboot
319 chown cassandra:cassandra /usr/local/cassandra-3.7/
320 cd /usr/local/cassandra-3.7/
321 ll
322 chown cassandra:cassandra /usr/local/cassandra-3.7
323 ll
324 chown cassandra:cassandra /usr/local/cassandra-3.7
325 ll
326 chown -R cassandra:cassandra /usr/local/cassandra-3.7
327 ll
328 chmod -R 777 /usr/local/cassandra-3.7
329 ll
330 bin/cassandra-cli --host localhost
331 cd bin/
332 ll
333 ./cassandra -cli --host localhost
334 ./nodetool status
335 ./cqlsh
启动
[root@template bin]# ./cassandra
Running Cassandra as root user or group is not recommended - please start Cassandra using a different system user.
If you really want to force running Cassandra as root, use -R command line option.
这里要新建个用户运行
270 useradd -d /usr/cassandra -m cassandra
271 passwd cassandra
[root@template bin]# su cassandra
[cassandra@template bin]$ ./cassandra
运行测试的时候
bin/cqlsh localhost
提示
No appropriate python interpreter found.
centos6上需要安装python环境
参考此篇
安装教程
参考此篇
安装完成后测试 bin/cqlsh
[root@template cassandra-3.7]# pwd
/usr/local/cassandra-3.7
[root@template cassandra-3.7]# bin/cqlsh localhost
Connection error: ('Unable to connect to any servers', {'localhost': error(111, "Tried connecting to [('::1', 9042, 0, 0), ('127.0.0.1', 9042)]. Last error: Connection refused")})
原来是之前前台运行的 那个窗口超时自动关闭了
重新启动了下
再试
[root@template cassandra-3.7]# bin/cqlsh localhost
Connected to Test Cluster at localhost:9042.
[cqlsh 5.0.1 | Cassandra 3.7 | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
cqlsh>
哟霍,成功了!cqlsh终于能用了!
来试试查询
cqlsh> SELECT cluster_name, listen_address FROM system.local;
cluster_name | listen_address
--------------+----------------
Test Cluster | 127.0.0.1
(1 rows)
cqlsh>
查了下cql的语法
参考此篇
sql cql
部分摘抄
//显示keyspace
cqlsh> describe keyspaces;
//创建keyspace
cqlsh> CREATE KEYSPACE IF NOT EXISTS myCas WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':1};
创建名字为mycas的keyspace.我们使用刚创建的keyspace:
//选择keyspace
cqlsh> use mycas
... ;
cqlsh:mycas> create table user(
... id int,
... user_name varchar,
... primary key(id) );
cqlsh:mycas>
//向表中添加数据
cqlsh> use mycas;
cqlsh:mycas> INSERT INTO users (id,user_name) VALUES (1,'zhangsan');
cqlsh:mycas> select * from users;
id | user_name
----+-----------
1 | zhangsan
插入数据的时候报错了
cqlsh:mycas> INSERT INTO users (id,user_name) VALUES (1,'root');
InvalidRequest: code=2200 [Invalid query] message="unconfigured table users"
表名错了 user 非users
[root@template bin]# ./cqlsh localhost
Connected to Test Cluster at localhost:9042.
[cqlsh 5.0.1 | Cassandra 3.7 | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
cqlsh> SELECT cluster_name, listen_address FROM system.local;
cluster_name | listen_address
--------------+----------------
Test Cluster | 127.0.0.1
(1 rows)
cqlsh> select * from mycas.user;
id | user_name
----+-----------
(0 rows)
cqlsh> use mycas;
cqlsh:mycas> insert into user(id,user_name) values (1,'root');
cqlsh:mycas> select * from user;
id | user_name
----+-----------
1 | root
(1 rows)
cqlsh:mycas>
cqlsh:mycas> select * from mycas.user;
id | user_name
----+-----------
1 | root
(1 rows)
cqlsh:mycas>
没有使用keyspace时查询的时候要加keyspace点表名
—————–2017年6月8日16:55:05—————–
在高性能计算机上安装遇到过的坑记录
配置环境变量时 等号两边不要有空格
报错信息
INFO [main] 2017-06-08 16:40:35,888 YamlConfigurationLoader.java:89 - Configuration location: file:/data02/home/zwh/cassandra/170cassandra/apache-cassandra-3.10/conf/cassandra.yaml
Exception (org.apache.cassandra.exceptions.ConfigurationException) encountered during startup: Invalid yaml: file:/data02/home/zwh/cassandra/170cassandra/apache-cassandra-3.10/conf/cassandra.yaml
Error: null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=Cannot create property=data_file_directories for JavaBean=org.apache.cassandra.config.Config@16267862; No single argument constructor found for class [Ljava.lang.String;; in 'reader', line 10, column 1:
cluster_name: 'Test Cluster'
^
Invalid yaml: file:/data02/home/zwh/cassandra/170cassandra/apache-cassandra-3.10/conf/cassandra.yaml
Error: null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=Cannot create property=data_file_directories for JavaBean=org.apache.cassandra.config.Config@16267862; No single argument constructor found for class [Ljava.lang.String;; in 'reader', line 10, column 1:
cluster_name: 'Test Cluster'
^
ERROR [main] 2017-06-08 16:40:36,340 CassandraDaemon.java:752 - Exception encountered during startup: Invalid yaml: file:/data02/home/zwh/cassandra/170cassandra/apache-cassandra-3.10/conf/cassandra.yaml
Error: null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=Cannot create property=data_file_directories for JavaBean=org.apache.cassandra.config.Config@16267862; No single argument constructor found for class [Ljava.lang.String;; in 'reader', line 10, column 1:
cluster_name: 'Test Cluster'
^
开始以为配置文件前面不能有空格删掉空格还是报错。折腾了一下发现data_file_directories 配置的时候要按注释的格式
# Directories where Cassandra should store data on disk. Cassandra
# will spread data evenly across them, subject to the granularity of
# the configured compaction strategy.
# If not set, the default directory is $CASSANDRA_HOME/data/data.
# data_file_directories:
# - /var/lib/cassandra/data
data_file_directories:
- /data02/home/zwh/cassandra/170cassandra/data
-
原因 配置应该按注释的格式 值要换一行 且前面要加一个 -
折腾完启动还是报错
com.sun.jna.LastErrorException: [22] h¶<@
at org.apache.cassandra.utils.CLibrary.fsync(Native Method) ~[apache-cassandra-3.10.jar:3.10]
at org.apache.cassandra.utils.CLibrary.trySync(CLibrary.java:308) ~[apache-cassandra-3.10.jar:3.10]
at org.apache.cassandra.utils.SyncUtil.trySync(SyncUtil.java:179) [apache-cassandra-3.10.jar:3.10]
at org.apache.cassandra.hints.HintsCatalog.fsyncDirectory(HintsCatalog.java:136) [apache-cassandra-3.10.jar:3.10]
at org.apache.cassandra.hints.HintsWriteExecutor$FsyncWritersTask.run(HintsWriteExecutor.java:189) [apache-cassandra-3.10.jar:3.10]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_131]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
at org.apache.cassandra.concurrent.NamedThreadFactory.lambda$threadLocalDeallocator$0(NamedThreadFactory.java:79) [apache-cassandra-3.10.jar:3.10]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131]
网上资料很少,我也很绝望啊!
v2 adds support for crappy old jna versions