- Description
- Requirements
- Installation
- Usage
- FAQ
- Appendix
- License
Distributed sequence and timestamp generator. Generates sequence numbers or timestamp with no collision with Zookeeper to store its waypoints. It's able to generate 10000 IDs by millisecond and has been tested in production for at least two years.
- At least three servers for ZooKeeper with 2GB min. The SCN server can run on one of them (512MB min).
- Java 7+ (see Appendix, section A).
- SBT 0.13.0+ (see Appendix, section B).
The process will be done in three steps:
- Installation of ZooKeeper's cluster.
- Export ZooKeeper config via the ZooKeeperClusterTool.
- Installation of SCN.
Duration: ~20 mins.
Installation of ZooKeeper (on three servers at least, you have to repeat theses commands for each server)
sudo apt-get update
cd ~ && wget http://mirror.csclub.uwaterloo.ca/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar -xvf zookeeper-3.4.6.tar.gz
sudo nano ~/zookeeper-3.4.6/conf/zoo.cfg
Use the Appendix, section C.sudo mkdir -p /var/lib/zookeeper
sudo nano /var/lib/zookeeper/myid
Type X where X is the number of your server in zoo.cfg (1, 2 or 3 from zoo.cfg) then save your file.cd ~/zookeeper-3.4.6
sudo bin/zkServer.sh start
- (Optional)
bin/zkCli.sh -server yourip:2181
Verify if ZooKeeper is running.
cd ~ ; wget https://github.com/wajam/nrv/archive/master.zip
unzip master
(sudo apt-get install -y unzip if you don’t have).cd nrv-master/ ; sbt stage
sudo nano local.cluster
Use the Appendix, section D. Careful to modify the IP and PORT to your convenience. If you need more than one SCN server, repeat the two line with the IP and the /votes../nrv-zookeeper/target/start
to see the help and do a update with your local.cluster file config. Everything should be fine if you see your config file below theAdd
section.
Example of result:
Remove
Add
/services/scn=scn
/services/scn/members/0=0:10.24.130.7:nrv=9595
/services/scn/members/0/votes
Update
Ignore
wget https://github.com/wajam/scn/archive/master.zip && unzip master
cd scn-master && sbt stage
sudo nano ./etc/default.properties
and modify two lines
scn.nrv.zookeeper.servers=YOURSERVER1,YOURSERVER2,etc.
scn.storage = zookeeper
./bin/start -Dscn.config=etc/default.properties com.wajam.scn.ScnServer
The SCN server exposes by default an API on port 9500. There is only two calls:
/timestamps/:name/next
Return IDs following the current timestamp./sequences/:name/next
Return IDs starting by 0 (or the number given in your the default.properties).
If you want to have more than one ID, you can use the query param length
:
/timestamps/:name/next?length=1000
/sequences/:name/next?length=1000
Either you forgot to modify the scn.nrv.zookeeper.servers
in the default.properties or you didn't start your ZooKeeper servers.
Follow the Installation of SCN
for every new SCN server and then just add theses line for each SCN server in local.cluster in the Export ZooKeeper Config
:
/services/scn/members/0=0:YOURNRVCLIENTIP:nrv=YOURNRVPORT (default 9595)
/services/scn/members/0/votes
Your local.cluster should be like that:
/services/scn=scn
/services/scn/members/0=0:YOURNRVCLIENTIP1:nrv=YOURNRVPORT
/services/scn/members/0/votes
/services/scn/members/0=0:YOURNRVCLIENTIP2:nrv=YOURNRVPORT
/services/scn/members/0/votes
...
/services/scn/members/0=0:YOURNRVCLIENTIPN:nrv=YOURNRVPORT
/services/scn/members/0/votes
A - Installation of Java 7 OpenJDK (if you prefer another JDK, feel free to install your own but we need Java)
sudo apt-get install openjdk-7-jdk -y
Install OpenJDK 7.sudo update-alternatives --config java
Select the right version of Java.
wget https://dl.bintray.com/sbt/debian/sbt-0.13.6.deb
sudo dpkg -i sbt-0.13.6.deb
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=10.0.0.2:2888:3888
server.2=10.0.0.3:2888:3888
server.3=10.0.0.4:2888:3888
# Replace IP servers with yours
# SCN
/services/scn=scn
/services/scn/members/0=0:YOURNRVCLIENTIP:nrv=YOURNRVPORT (default 9595)
/services/scn/members/0/votes
The MIT License
Copyright (c) 2012-2015 Wajam Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.