安装&配置 (提前安装JDK&tomcat) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/solr-4.10.3.tgz.tgz" cd ~/soft if [ ! -d "/usr/local/solr" ]; then mkdir /usr/local/solr fi cp apache-tomcat-7.0 .79 .tar.gz /usr/local/solr cp solr-4.10 .3 .tgz.tgz /usr/local/solr tar -zxvf apache-tomcat-7.0 .79 .tar.gz tar -zxvf solr-4.10 .3 .tgz.tgz cp solr-4.10 .3 /example/solr /usr/local/solr/solrhome -r cp solr-4.10 .3 /example/webapps/solr.war /usr/local/solr/apache-tomcat-7.0 .79 /webapps/ var=/usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr.war tmp=${var path=${tmp%.*} if [ ! -d "/usr/local/solr/apache-tomcat-7.0.79/webapps/$path " ]; then mkdir /usr/local/solr/apache-tomcat-7.0 .79 /webapps/$path fi unzip -oq $var -d /usr/local/solr/apache-tomcat-7.0 .79 /webapps/$path rm -f $var if [ ! -d "/usr/local/solr/apache-tomcat-7.0.79/webapps/solr/WEB-INF/classes" ]; then mkdir /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/classes fi cp solr-4.10 .3 /example/resources/log4j.properties /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/classes/ cp solr-4.10 .3 /example/lib/ext/* /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/lib/ sed -i -e '/<\/env-entry>/{n;d;}' /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/web.xml sed -i -e '$!N;s/.*\n\(.*<env-entry>\)/\1/' -e 'P;D;' /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/web.xml sed -i -e 's/\/put\/your\/solr\/home\/here/\/usr\/local\/solr\/solrhome/g' /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/web.xml serverpath="/usr/local/solr/apache-tomcat-7.0.79/conf/server.xml" val="1" sed -i "s/<Server port=\" 8005 \"/<Server port=\" 80 `echo $val `5\"/g" $serverpath sed -i "s/<Connector port=\" 8080 \"/<Connector port=\" 808 `echo $val `\"/g" $serverpath sed -i "s/<Connector port=\" 8009 \"/<Connector port=\" 80 `echo $val `9\"/g" $serverpath wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/IK%20Analyzer%202012FF_hf1.zip" cp $HOME /soft/IK\ Analyzer\ 2012 FF_hf1.zip /usr/local/solr/ cd /usr/local/solr unzip IK\ Analyzer\ 2012 FF_hf1.zip cd IK\ Analyzer\ 2012 FF_hf1 cp IKAnalyzer2012FF_u1.jar /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/lib cp IKAnalyzer.cfg.xml /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/classes cp *.dic /usr/local/solr/apache-tomcat-7.0 .79 /webapps/solr/WEB-INF/classes schemafile="/usr/local/solr/solrhome/collection1/conf/schema.xml" sed -i -e 's/^<\/schema>//' $schemafile printf '<!-- IKAnalyzer--> <fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType> ### 不同项目得修改... <!-- 商品名称 --> <field name="item_title" type="text_ik" indexed="true" stored="true"/> <!-- 商品卖点 --> <field name="item_sell_point" type="text_ik" indexed="true" stored="false"/> <!-- 商品分类名称 --> <field name="item_category_name" type="string" indexed="true" stored="false"/> <!-- 商品价格 --> <field name="item_price" type="long" indexed="true" stored="true"/> <!-- 商品描述 --> <field name="item_description" type="text_ik" indexed="true" stored="false"/> <!-- 商品图片地址 --> <field name="item_image" type="string" indexed="false" stored="true"/> <!-- 目标域--> <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <!-- 将商品名称添加到目标域--> <copyField source="item_title" dest="item_keywords"/> <!-- 将商品卖点添加到目标域--> <copyField source="item_sell_point" dest="item_keywords"/> <!-- 将商品描述添加到目标域--> <copyField source="item_description" dest="item_keywords"/>' >> $schemafile echo -e "\n\n</schema>" >> $schemafile /usr/local/solr/apache-tomcat-7.0 .79 /bin/startup.sh
Solrcloud 安装&配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/zookeeper-3.4.6.tar.gz" wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/apache-tomcat-7.0.79.tar.gz" wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/solr-4.10.3.tgz.tgz" if [ ! -d "/usr/local/solrcloud" ]; then mkdir /usr/local/solrcloud fi cd ~/soft cp zookeeper-3.4 .6 .tar.gz /usr/local/solrcloud cd /usr/local/solrcloud tar -zxvf zookeeper-3.4 .6 .tar.gz mv zookeeper-3.4 .6 zk1 cd zk1/conf cp zoo_sample.cfg zoo.cfg sed -i -e 's/^dataDir=.*/dataDir=\/usr\/local\/solrcloud\/zk1\/data/g' zoo.cfg sed -i -e 's/^clientPort=.*/clientPort=2281/g' zoo.cfg ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" | head -n 1 ` echo -e "\n\n#集群中每台机器都是以下配置 #2881系列端口是zookeeper通信端口 #3881系列端口是zookeeper投票选举端口 server.1=${ipaddr}:2881:3881 server.2=${ipaddr}:2882:3882 server.3=${ipaddr}:2883:3883" >> zoo.cfgif [ ! -d "/usr/local/solrcloud/zk1/data" ]; then mkdir /usr/local/solrcloud/zk1/data fi echo "1" > /usr/local/solrcloud/zk1/data /myid cd /usr/local/solrcloud cp -r zk1 zk2 cp -r zk1 zk3 sed -i -e 's/^dataDir=.*/dataDir=\/usr\/local\/solrcloud\/zk2\/data/g' -e 's/^clientPort=.*/clientPort=2282/g' /usr/local/solrcloud/zk2/conf/zoo.cfg echo "2" > /usr/local/solrcloud/zk2/data /myid sed -i -e 's/^dataDir=.*/dataDir=\/usr\/local\/solrcloud\/zk3\/data/g' -e 's/^clientPort=.*/clientPort=2283/g' /usr/local/solrcloud/zk3/conf/zoo.cfg echo "3" > /usr/local/solrcloud/zk3/data /myid /usr/local/solrcloud/zk1/bin/zkServer.sh restart /usr/local/solrcloud/zk2/bin/zkServer.sh restart /usr/local/solrcloud/zk3/bin/zkServer.sh restart ps -ef | grep zook | grep solr | grep -e 'zk[0-9]/bin' /usr/local/solrcloud/zk1/bin/zkServer.sh status /usr/local/solrcloud/zk2/bin/zkServer.sh status /usr/local/solrcloud/zk3/bin/zkServer.sh status cd /usr/local/solrcloud cp /usr/local/solr/apache-tomcat-7.0 .79 ./tomcat8280 -r cp /usr/local/solr/apache-tomcat-7.0 .79 ./tomcat8380 -r cp /usr/local/solr/apache-tomcat-7.0 .79 ./tomcat8480 -r cp /usr/local/solr/apache-tomcat-7.0 .79 ./tomcat8580 -r path="/usr/local/solrcloud" names=("2" "3" "4" "5" ) count=${ for (( i=0 ; i<"$count " ; i=i+1 ))do file=${path}/tomcat8${names[$i ]}80 /conf/server.xml echo $file sed -i -e "/<Server port=\" .*\" shutdown=\" SHUTDOWN\">/s/[0-9]\{4\}/8${names[$i ]}05/g" \ -e "/<Connector port=\" .*\" protocol=\" AJP\/1.3 \" redirectPort=\" 8443 \" \/>/s/[0-9]\{4\}/8${names[$i ]}09/g" \ -e "/<Connector port=\" .*\" protocol=\" HTTP\/1.1 \"/s/[0-9]\{4\}/8${names[$i ]}80/g" $file done cd /usr/local/solrcloud cp -r /usr/local/solr/solrhome ./solrhome8280 cp -r /usr/local/solr/solrhome ./solrhome8380 cp -r /usr/local/solr/solrhome ./solrhome8480 cp -r /usr/local/solr/solrhome ./solrhome8580 path="/usr/local/solrcloud" names=("2" "3" "4" "5" ) count=${ for (( i=0 ; i<"$count " ; i=i+1 ))do file=${path}/tomcat8${names[$i ]}80 /webapps/solr/WEB-INF/web.xml echo $file sed -i -e "/<env-entry-value>.*<\/env-entry-value>/s/<env-entry-value>.*<\/env-entry-value>/<env-entry-value>\/usr\/local\/solrcloud\/solrhome8${names[$i ]}80<\/env-entry-value>/g" $file done ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" | head -n 1 ` path="/usr/local/solrcloud" names=("2" "3" "4" "5" ) count=${ for (( i=0 ; i<"$count " ; i=i+1 ))do file=${path}/solrhome8${names[$i ]}80 /solr.xml echo $file sed -i -e "s/<str name=\" host\">.*<\/str>/<str name=\" host\">$ipaddr <\/str>/g" \ -e "s/<int name=\" hostPort\">.*<\/int>/<int name=\" hostPort\">8${names[$i ]}80<\/int>/g" $file done ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" | head -n 1 ` path="/usr/local/solrcloud" names=("2" "3" "4" "5" ) count=${ for (( i=0 ; i<"$count " ; i=i+1 ))do file=${path}/tomcat8${names[$i ]}80 /bin/catalina.sh echo $file sed -i -e "/^#JAVA_OPTS/a\\JAVA_OPTS=\" -DzkHost=${ipaddr}:2281 ,${ipaddr}:2282 ,${ipaddr}:2283 \"" $file done ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" | head -n 1 ` /usr/local/solr/solr-4.10 .3 /example/scripts/cloud-scripts/zkcli.sh -zkhost ${ipaddr}:2281 ,${ipaddr}:2282 ,${ipaddr}:2283 -cmd upconfig -confdir /usr/local/solrcloud/solrhome8280/collection1/conf -confname myconf /usr/local/solrcloud/tomcat8280/bin/startup.sh /usr/local/solrcloud/tomcat8380/bin/startup.sh /usr/local/solrcloud/tomcat8480/bin/startup.sh /usr/local/solrcloud/tomcat8580/bin/startup.sh
集群分片 1 http://172.16.124.134:8280/solr/admin/collections?action=CREATE&name=collection2&numShards=2&replicationFactor=2
删除collection 1 http://172.16.124.134:8280/solr/admin/collections?action=DELETE&name=collection1
删除 匹配行的 前一行 & 后一行 1 2 sed -i "" -e '/<\/env-entry>/{n;d;}' web.xml sed -i "" -e :a -e '$!N;s/.*\n\(.*<env-entry>\)/\1/;ta' -e 'P;D' web.xml
参考:https://unix.stackexchange.com/questions/152312/remove-multiple-lines-after-a-pattern-match-but-only-after-pattern-match https://www.zhihu.com/question/26122927
python写的sed调试工具 https://www.cnblogs.com/lemon-le/p/6061189.html
shell 脚本中怎样将字符串转化为命令 可以使用eval命令。eval命令,如同熟悉的其他脚本语言,会将它的参数做为命令执行。eval命令将会首先扫描命令行进行所有的替换,然后再执行命令。该命令使用于那些一次扫描无法实现其功能的变量。该命令对变量进行两次扫描。这些需要进行两次扫描的变量有时候被称为复杂变量。 命令格式:eval [参数] 补充说明:eval可读取一连串的参数,然后再依参数本身的特性来执行。参数不限数目,彼此之间用分号分开。 用法示例: 将字符串变量s的值作为命令执行 s=”ls” eval $s
1 2 3 4 grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} -r -I $* . $* 以一个单字符串显示所有向脚本传递的参数。 如"$*" 用「"」括起来的情况、以" $1 $2 … $n "的形式输出所有参数。
参考:http://www.runoob.com/linux/linux-shell-passing-arguments.html
查看图片尺寸的命令 参考:http://blog.csdn.net/u014295667/article/details/46876265 http://www.webhek.com/post/get-image-dimensions-from-command-line.html
1 brew install imagemagick
maven项目下的 所有target目录大小的总和 1 find . -type d -name "target" | xargs -I {} du -s -k {} | awk '{size=size+$1}END{print size}'