shell脚本写了一键安装solr

shell脚本写了一键安装solr,本篇我们来看下如何一键安装zookeeper,散仙最近是最自动化安装脚本上迷了,咱们也不会复杂的,先从简单的开始联手,下面进入正题:

安装条件:
1,确保你的JAVA环境是OK的,JDK什么的
2,在root根目录下有一个zookeeper下好的压缩包
3,安装脚本默认放在root目录下
4,所有的安装目录,及压缩包命名,都在本脚本的前面几行定义,散仙为了方便写的比较固定,需要灵活的朋友们,可以做成动态的路径
5,确认上面的4步是ok的,下面就可以运行这个脚本了
6,安装完成后会在最后的状态里面打印出zk的运行情况



下面看散仙的安装日志:

zookeeper-3.4.5/contrib/zkfuse/src/event.cc  
zookeeper-3.4.5/contrib/zkfuse/src/event.h  
zookeeper-3.4.5/contrib/zkfuse/src/log.cc  
zookeeper-3.4.5/contrib/zkfuse/src/log.h  
zookeeper-3.4.5/contrib/zkfuse/src/log4cxx.properties  
zookeeper-3.4.5/contrib/zkfuse/src/Makefile.am  
zookeeper-3.4.5/contrib/zkfuse/src/mutex.h  
zookeeper-3.4.5/contrib/zkfuse/src/thread.cc  
zookeeper-3.4.5/contrib/zkfuse/src/thread.h  
zookeeper-3.4.5/contrib/zkfuse/src/zkadapter.cc  
zookeeper-3.4.5/contrib/zkfuse/src/zkadapter.h  
zookeeper-3.4.5/contrib/zkfuse/src/zkfuse.cc  
zookeeper-3.4.5/contrib/rest/zookeeper-3.4.5-rest.jar  
zookeeper-3.4.5/contrib/loggraph/build.xml  
zookeeper-3.4.5/contrib/loggraph/src/  
zookeeper-3.4.5/contrib/loggraph/zookeeper-3.4.5-loggraph.jar  
zookeeper-3.4.5/contrib/loggraph/src/java/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterException.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterParser.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JEntry.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogIterator.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogServer.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSkipList.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSource.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/MergedLogSource.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/TransactionEntry.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/TxnLogSource.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/FileLoader.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Fs.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/GraphData.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/JsonServlet.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/AndOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/Arg.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/EqualsOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/GreaterThanOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/LessThanOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NotOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NumberArg.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/OrOp.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/StringArg.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/SymbolArg.java  
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/XorOp.java  
zookeeper-3.4.5/contrib/fatjar/build.xml  
zookeeper-3.4.5/contrib/fatjar/conf/  
zookeeper-3.4.5/contrib/fatjar/src/  
zookeeper-3.4.5/contrib/fatjar/zookeeper-3.4.5-fatjar.jar  
zookeeper-3.4.5/contrib/fatjar/src/java/  
zookeeper-3.4.5/contrib/fatjar/src/java/org/  
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/  
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/zookeeper/  
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/zookeeper/util/  
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java  
zookeeper-3.4.5/contrib/fatjar/conf/mainClasses  
zookeeper-3.4.5/conf/configuration.xsl  
zookeeper-3.4.5/conf/log4j.properties  
zookeeper-3.4.5/conf/zoo_sample.cfg  
zookeeper-3.4.5/bin/README.txt  
zookeeper-3.4.5/bin/zkCleanup.sh  
zookeeper-3.4.5/bin/zkCli.cmd  
zookeeper-3.4.5/bin/zkCli.sh  
zookeeper-3.4.5/bin/zkEnv.cmd  
zookeeper-3.4.5/bin/zkEnv.sh  
zookeeper-3.4.5/bin/zkServer.cmd  
zookeeper-3.4.5/bin/zkServer.sh  
解压完毕!  
生成myid文件.......  
写入zoo.cfg文件成功!  
zk进程号: 2575  
检测到zookeeper进程存在,已关闭!  
开始启动zk.....  
JMX enabled by default  
Using config: /root/izk/zookeeper/bin/../conf/zoo.cfg  
Starting zookeeper ... bin/zkServer.sh: line 103: [: /tmp/zookeeper: binary operator expected  
STARTED  
启动完成....查看zookeeper状态  
JMX enabled by default  
Using config: /root/izk/zookeeper/bin/../conf/zoo.cfg  
Mode: standalone  
[root@ganglia ~]# jps  
2693 Jps  
2651 QuorumPeerMain  
[root@ganglia ~]#   
zookeeper-3.4.5/contrib/zkfuse/src/event.cc
zookeeper-3.4.5/contrib/zkfuse/src/event.h
zookeeper-3.4.5/contrib/zkfuse/src/log.cc
zookeeper-3.4.5/contrib/zkfuse/src/log.h
zookeeper-3.4.5/contrib/zkfuse/src/log4cxx.properties
zookeeper-3.4.5/contrib/zkfuse/src/Makefile.am
zookeeper-3.4.5/contrib/zkfuse/src/mutex.h
zookeeper-3.4.5/contrib/zkfuse/src/thread.cc
zookeeper-3.4.5/contrib/zkfuse/src/thread.h
zookeeper-3.4.5/contrib/zkfuse/src/zkadapter.cc
zookeeper-3.4.5/contrib/zkfuse/src/zkadapter.h
zookeeper-3.4.5/contrib/zkfuse/src/zkfuse.cc
zookeeper-3.4.5/contrib/rest/zookeeper-3.4.5-rest.jar
zookeeper-3.4.5/contrib/loggraph/build.xml
zookeeper-3.4.5/contrib/loggraph/src/
zookeeper-3.4.5/contrib/loggraph/zookeeper-3.4.5-loggraph.jar
zookeeper-3.4.5/contrib/loggraph/src/java/
zookeeper-3.4.5/contrib/loggraph/src/java/org/
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterException.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterParser.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JEntry.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogIterator.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogServer.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSkipList.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSource.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/MergedLogSource.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/TransactionEntry.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/TxnLogSource.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/FileLoader.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Fs.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/GraphData.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/JsonServlet.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/AndOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/Arg.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/EqualsOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/GreaterThanOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/LessThanOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NotOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NumberArg.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/OrOp.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/StringArg.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/SymbolArg.java
zookeeper-3.4.5/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/XorOp.java
zookeeper-3.4.5/contrib/fatjar/build.xml
zookeeper-3.4.5/contrib/fatjar/conf/
zookeeper-3.4.5/contrib/fatjar/src/
zookeeper-3.4.5/contrib/fatjar/zookeeper-3.4.5-fatjar.jar
zookeeper-3.4.5/contrib/fatjar/src/java/
zookeeper-3.4.5/contrib/fatjar/src/java/org/
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/zookeeper/
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/zookeeper/util/
zookeeper-3.4.5/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java
zookeeper-3.4.5/contrib/fatjar/conf/mainClasses
zookeeper-3.4.5/conf/configuration.xsl
zookeeper-3.4.5/conf/log4j.properties
zookeeper-3.4.5/conf/zoo_sample.cfg
zookeeper-3.4.5/bin/README.txt
zookeeper-3.4.5/bin/zkCleanup.sh
zookeeper-3.4.5/bin/zkCli.cmd
zookeeper-3.4.5/bin/zkCli.sh
zookeeper-3.4.5/bin/zkEnv.cmd
zookeeper-3.4.5/bin/zkEnv.sh
zookeeper-3.4.5/bin/zkServer.cmd
zookeeper-3.4.5/bin/zkServer.sh
解压完毕!
生成myid文件.......
写入zoo.cfg文件成功!
zk进程号: 2575
检测到zookeeper进程存在,已关闭!
开始启动zk.....
JMX enabled by default
Using config: /root/izk/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... bin/zkServer.sh: line 103: [: /tmp/zookeeper: binary operator expected
STARTED
启动完成....查看zookeeper状态
JMX enabled by default
Using config: /root/izk/zookeeper/bin/../conf/zoo.cfg
Mode: standalone
[root@ganglia ~]# jps
2693 Jps
2651 QuorumPeerMain
[root@ganglia ~]#


注意散仙的是单机安装,如果想要分布式安装也是非常简单的,用for循环加上ssh,远程执行,再对myid和zoo.cfg稍作配置即可。

散仙上面运行的是多次,运行的,大于第一次运行的,会在后面检测如果已经有zk的进程,会杀死,重启,单机版本,zk成功的标志就是显示状态为standalone

脚本如下:

Shell代码 shell脚本写了一键安装solr
  1. zkpath=/root/zookeeper-3.4.5.tar.gz  
  2. ipath=/root/izk  
  3. ipaddress="192.168.46.21"  
  4.   
  5. if  [ ! -e $ipath  ] ; then  
  6.   
  7. echo "路径不存在,创建安装路径!"  
  8.   
  9. mkdir  $ipath  
  10. else    
  11.   
  12. rm -rf $ipath"/"*  
  13. echo "路径存在,已清空完毕!"  
  14.   
  15. fi  
  1. echo "解压zk到指定目录下!"  
  2. sleep 2  
  3.   
  4. tar -zxvf $zkpath -C $ipath  
  5.   
  6.   
  7. echo "解压完毕!"  
  8.   
  9.   
  10. cd $ipath  
  11. mv zookeeper-3.4.5 zookeeper  
  12.   
  13. confpath=$ipath"/zookeeper"  
  14.   
  15. cd $confpath  
  16.   
  17. mkdir data   
  18.   
  19. cd data  
  20. echo "1" >> myid  
  21. echo "生成myid文件......."  
  22.   
  23.   
  24.   
  25. cd $confpath"/conf"  
  26.   
  27. mv zoo_sample.cfg zoo.cfg  
  28.   
  29. echo "tikcTime=2000" >> zoo.cfg  
  30. echo "dataDir=$confpath/data" >> zoo.cfg  
  31. echo "server.1=$ipaddress:2887:3887" >> zoo.cfg  
  32.   
  33. echo "写入zoo.cfg文件成功!"  
  34.   
  35. sleep 3  
  36.   
  37. pid=`ps -ef | grep  zookeeper | gawk '{ print $2}' | head -n 1`  
  38.   
  39. echo "zk进程号: $pid"  
  40.   
  41. sleep 2  
  42.   
  43. #检查进程号是否为空  
  44. if [ ! -z $pid  ] ; then  
  45.   
  46. kill -9 $pid  
  47.   
  48. echo "检测到zookeeper进程存在,已关闭!"  
  49.   
  50. fi  
  51.   
  52.   
  53.   
  54. echo "开始启动zk....."  
  55.   
  56. cd ..  
  57.   
  58. bin/zkServer.sh start  
  59.   
  60. echo "启动完成....查看zookeeper状态"  
  61.   
  62. bin/zkServer.sh status  

相关推荐