技术分享| 如何部署安装分布式序列号生成器系统
生活随笔
收集整理的這篇文章主要介紹了
技术分享| 如何部署安装分布式序列号生成器系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Tinyid介紹
Tinyid是滴滴開發的一款分布式ID系統,Tinyid是在美團(Leaf)的leaf-segment算法基礎上升級而來,不僅支持了數據庫多主節點模式,還提供了tinyid-client客戶端的接入方式,使用起來更加方便。但和美團(Leaf)不同的是,Tinyid只支持號段一種模式不支持雪花模式。
Tinyid的特性
- 全局唯一的long型ID
- 趨勢遞增的id
- 提供 http 和 java-client 方式接入
- 支持批量獲取ID
- 支持生成1,3,5,7,9…序列的ID
- 支持多個db的配置
Tinyid部署
JDK部署
[root@localhost packages]# tar zxvf jdk-8u121-linux-x64.tar.gz [root@localhost packages]# mv jdk1.8.0_121/ /usr/local/jdk [root@localhost packages]# vim /etc/profile ##末尾添加 export JAVA_HOME=/usr/local/jdk export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/ export PATH=$PATH:$JAVA_HOME/bin [root@localhost packages]# source /etc/profile [root@localhost packages]# java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)Maven部署
[root@localhost packages]# tar zxvf apache-maven-3.5.0-bin.tar.gz [root@localhost packages]# mv apache-maven-3.5.0 /usr/local/maven [root@localhost packages]# vim /etc/profile ##末尾添加 export MAVEN_HOME=/usr/local/maven export PATH=$MAVEN_HOME/bin:$PATH [root@localhost packages]# source /etc/profile [root@localhost packages]# mvn -version Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00) Maven home: /usr/local/mavenMySQL部署
[root@localhost ~]# yum -y install mariadb mariadb-server [root@localhost ~]# systemctl enable mariadb [root@localhost ~]# systemctl start mariadb [root@localhost ~]# mysql -uroot mysql> set password = password('123456'); mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; //設置mysql外網連接密碼 mysql> flush privileges;Tinyid部署
## 拉取代碼 [root@localhost local]# git clone https://github.com/didi/tinyid.git [root@localhost local]# cd tinyid/tinyid-server/## 導入SQL文件 [root@localhost tinyid-server]# mysql -uroot -p123456 mysql> create database tinyid; mysql> use tinyid; mysql> source /usr/local/tinyid/tinyid-server/db.sql; mysql> exit修改配置文件指定MySQL
[root@localhost tinyid-server]# vim src/main/resources/offline/application.properties
datasource.tinyid.primary.driver-class-name=com.mysql.jdbc.Driver datasource.tinyid.primary.url=jdbc:mysql://localhost:3306/tinyid?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 datasource.tinyid.primary.username=root datasource.tinyid.primary.password=123456## 注意修mysql地址和庫名稱 jdbc:mysql://localhost:3306/tinyid?啟動tinyid
[root@localhost local]# cd tinyid/tinyid-server/ [root@localhost tinyid-server]# sh build.sh offline [root@localhost tinyid-server]# java -jar output/tinyid-server-xxx.jar [root@localhost tinyid-server]# netstat -untpl | grep java tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 12836/java自啟動腳本
[root@localhost ~]# cd /usr/local/tinyid/tinyid-server
[root@localhost tinyid-server]# vim tinyid.sh
#!/bin/sh ## if [ -f /etc/init.d/functions ]; then. /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ]; then. /etc/rc.d/init.d/functions elseecho -e "\aJnice: unable to locate functions lib. Cannot continue."exit 0 fiulimit -n 65000 echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range## jar文件名稱 export JAVA_HOME=/usr/local/java/jdk1.8.0_181 export PATH=$JAVA_HOME/bin:$PATH:$PATH:/usr/ffmpeg/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar JAR_HOME=/usr/local/tinyid/tinyid-server/ JAR_NAME=tinyid-server-0.1.0-SNAPSHOT.jar## 過濾pid進程號 tpid=`ps -ef|grep $JAR_NAME | grep -v grep | grep -v kill | awk '{print $2}'`#--------------------------------------------------------------------------- # START #--------------------------------------------------------------------------- Start() {if [ $tpid ]; thenecho -n "tinyid process [${prog}] already running"echo_failureechoreturn 1fiif [ ! -f ${JAR_HOME}/output/${JAR_NAME} ]; thenecho -n "tinyid binary [${prog}] not found."echo_failureechoreturn 1fiecho -n "starting service (tinyid): "cd ${JAR_HOME}nohup java -jar ${JAR_HOME}/output/${JAR_NAME} > /dev/null 2>&1 &retval=$?if [ ${retval} == 0 ]; thenecho_successechoelseecho_failureechobreakfisleep 1return 0 }#--------------------------------------------------------------------------- # STOP #--------------------------------------------------------------------------- Stop() {echo -n "stopping service (tinyid): "kill -9 $tpidechoreturn 0 }#--------------------------------------------------------------------------- # MAIN #--------------------------------------------------------------------------- case "$1" instart)Start;;stop)Stop;;restart)Stopsleep 3Start;;*)echo "please use : $0 {start|stop|restart}" esacexit設置任務計劃
[root@localhost tinyid-server]# crontab -l
*/1 * * * * sh /usr/local/tinyid/tinyid-server/tinyid.sh start >/dev/null 2>&1總結
以上是生活随笔為你收集整理的技术分享| 如何部署安装分布式序列号生成器系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 模电基础知识点小结
- 下一篇: vs2013编译驱动错误-Inf2Cat