Neo4j Server启动失败

发表于2013年8月31日

最近需要用到Neo4j做个小试验,看似顺利安装却在启动server的时候报错。最终发现问题是JDK1.7安装时,少修改了一个symlink。

我的安装步骤如下:

从Oracle下载了JDK1.7,在~/.bashrc里修改了JAVA_HOME变量。

export JAVA_HOME=/usr/libexec/java_home -v 1.7

检查了一下当前jdk版本。

> source ~/.bashrc
> java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

看起来没什么问题,但实际上并没有完成。在/System/Library/Frameworks/JavaVM.framework/Versions 下有一个 CurrentJDK 的symlink,仍然指向JDK 1.6的路径。

如果没有修改symlink,则neo4j启动时报错。

> neo4j start
Using additional JVM arguments:  -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties 
-Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties 
-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Dneo4j.ext.udc.source=homebrew
Starting Neo4j Server...WARNING: not changing user
process [29976]... waiting for server to be ready.... Failed to start within 120 seconds.
Neo4j Server may have failed to start, please check the logs.

需要执行一下命令:

> cd /System/Library/Frameworks/JavaVM.framework/Versions
> sudo rm CurrentJDK
> sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/ CurrentJDK
> ls -l CurrentJDK
lrwxr-xr-x  1 root  wheel  59 Aug 31 01:58 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/

这时

> neo4j start
Using additional JVM arguments:  -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties 
-Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties 
-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Dneo4j.ext.udc.source=homebrew
Starting Neo4j Server...WARNING: not changing user
process [33636]... waiting for server to be ready....... OK.
Go to http://localhost:7474/webadmin/ for administration interface.

Neo4j Server顺利启动。网上看到有不少人报类似的错,但原因不全是JDK路径问题造成。

参考:

Ubuntu下用Vim编辑且不改变GBK编码的文件

发表于2012年3月14日

Ubuntu下用Vim编辑且不改变GBK编码的文件

sudo vi /var/lib/locales/supported.d/zh

添加以下内容:

zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN.GB2312 GB2312

执行

sudo locale-gen
vi ~/.vimrc

添加以下内容

set encoding=utf-8
set fileencodings=cp936,gb18030,ucs-bom,utf-8,big5,euc-jp,euc-kr,latin1
set termencoding=utf-8
language zh_CN.GB18030

以上配置可以实现打开编辑GBK编码的文件,但保存时并不改变编码。

笔记:Ubuntu下快速开始使用Python Thrift

发表于2012年2月8日

本文介绍如何在Ubuntu 10.04下安装Apache Thrift并用Python写一个Demo。

apt-get install libboost-dev libevent-dev python-dev automake pkg-config libtool flex bison sun-java6-jdk
wget http://www.apache.org/dist//thrift/0.8.0/thrift-0.8.0.tar.gz
tar zxvf thrift-0.8.0.tar.gz
cd thrift-0.8.0
./configure
make
sudo make install
sudo pip install thrift

编辑接口文件 hellowworld.thrift:

service HelloWorld {
    string ping(),
    string say(1:string msg)
}

编辑 server.py

#!/usr/bin/env python
 
import socket
import sys
sys.path.append('./gen-py')
 
from helloworld import HelloWorld
from helloworld.ttypes import *
 
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
 
class HelloWorldHandler:
  def ping(self):
    return "pong"
 
  def say(self, msg):
    ret = "Received: " + msg
    print ret
    return ret
 
handler = HelloWorldHandler()
processor = HelloWorld.Processor(handler)
transport = TSocket.TServerSocket("localhost", 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
 
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
 
print "Starting thrift server in python..."
server.serve()
print "done!"

编辑 client.py

#!/usr/bin/env python
 
import sys
sys.path.append('./gen-py')
 
from helloworld import HelloWorld
 
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
 
try:
  transport = TSocket.TSocket('localhost', 9090)
  transport = TTransport.TBufferedTransport(transport)
  protocol = TBinaryProtocol.TBinaryProtocol(transport)
  client = HelloWorld.Client(protocol)
  transport.open()
 
  print "client - ping"
  print "server - " + client.ping()
 
  print "client - say"
  msg = client.say("Hello!")
  print "server - " + msg
 
  transport.close()
 
except Thrift.TException, ex:
  print "%s" % (ex.message)
thrift --gen py helloworld.thrift
python server.py
python client.py

参考: Thrift the missing guide