一、Hadoop錯誤:Name node is in safe modecss
解決:關閉Hadoop安全模式 html
hadoop dfsadmin -safemode leave
二、解壓縮.gz 和 .bz2格式文件java
在 tar
命令所在的那一行中,x
標記指定 tar
命令執行解壓縮操做,f
標記則指定壓縮包的文件名。 tar -xf spark-1.2.0-bin-hadoop2.4.tgz
node
.tar.gz 格式解壓爲 mysql
tar -zxvf xx.tar.gz
.tar.bz2 格式解壓爲 jquery
tar -jxvf xx.tar.bz2
三、從Windows到Linux文件亂碼解決命令linux
iconv -f GBK -t UTF-8 aa.json -o bb.json
四、解壓.bin文件nginx
./**.bin
在JDK官網下載了一個jdk-6u45-linux-x64.bingit
解壓命令爲:redis
./jdk-6u45-linux-x64.bin
五、MySQL中文亂碼
編輯 /etc/mysql/my.cnf
[client] default-character-set=utf8 [mysqld] character-set-server=utf8
而後重啓MySQL
sudo /etc/init.d/mysql restart
show variables like 'character%';
CentOS
vi /etc/my.cnf
service mysqld restart
六、CentOS經常使用命令
關閉防火牆 chkconfig iptables off
查看防火牆狀態 service iptables status
http://blog.csdn.net/hooperzao/article/details/25111321
http://bdbaishitong.blog.163.com/blog/static/201493080201378662648/
CentOS 7關閉防火牆
systemctl stop firewalld.service #中止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
七、Linux修改文件夾權限及擁有者
chmod -R 777 file
chown -R hadoop:hadoop file
八、Tomcat啓動中止
以服務啓動Tomcat nohup bin/startup.sh &
關閉Tomcat服務 bin/shutdown.sh
九、Java解析CST格式時間
SimpleDateFormat simple = new SimpleDateFormat( "EEE MMM dd HH:mm:ss 'CST' yyyy", Locale.US); DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.format(simple.parse(「Mon Nov 19 14:06:58 CST 2012」.toString())
十、打開hiveserver2, 之後臺進程的方式啓動
hive --service hiveserver2 &
十一、MongoDB解析GridFS中的ISODate
Date simple = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CST' yyyy",Locale.US);
Date result=simple.parse(simple.format(new Date()));
十二、MongoDB多條件查詢
查詢某個時間區間的數據
BasicDBList conditionList = new BasicDBList();
conditionList.add(new BasicDBObject("uploadDate", new BasicDBObject("$gte", lowTime)));// 查詢條件-時間下界
conditionList.add(new BasicDBObject("uploadDate", new BasicDBObject("$lte", highTime)));// 查詢條件-時間上界
DBObject queryCondition = new BasicDBObject("$and", conditionList);
GridFS gf = new GridFS(db);
DBCursor cursor = gf.getDB().getCollection("fs.files").find(queryCondition);//從表 fs.files 中查詢出全部JPG文件
或者
List<GridFSDBFile> fileList = gf.find(queryCondition);
刪除GridFS中數據
gf.remove(queryCondition);// 刪除GridFS中圖片數據
參考:http://blog.csdn.net/mcpang/article/details/8731065
1三、jar文件後臺運行
若是在終端中執行java -jar xxx.jar&命令,當終端關閉時,xxx.jar也會同時結束運行,可是若是執行nohup java -jar xxx.jar&命令,則程序會在後臺一直運行,值得注意的是,此時程序控制臺輸出會被轉移到nohup.out文件中。
1四、MongoDB修改鏈接數
MongoClient client=new MongoClient ("127.0.0.1",27017); MongoOptions option = client.getMongoOptions(); client.setConnectionsPerHost(100);// 設置每一個主機的鏈接數 client.setThreadsAllowedToBlockForConnectionMultiplier(50);// 設置線程隊列數
http://api.mongodb.org/java/2.13/
1五、清空文件夾並重建
File file = new File(System.getProperty("user.dir") + "/dataToMatch"); if (!file.exists() && !file.isDirectory()) {// 不存在 file.mkdir(); } else if (file.exists() && file.isDirectory()) {// 存在 String basePath = file.getAbsolutePath(); String[] fileStrs = file.list(); File tp = null; for (String path : fileStrs) { tp = new File(basePath + "/" + path); tp.delete(); } file.delete(); file.mkdir(); } else { TimerJob.log.info("ERROR!"); }
1六、List、Map、DBObject定義時初始化值
List
List<String> list = new ArrayList<String>() { { add("string1"); add("string2"); // some other add() code...... add("stringN"); } };
Map
Map<String, String> map = new HashMap<String, String>() { { put("key1", "value1"); put("key2", "111cn.Net"); // .... some other put() code put("keyN", "valueN"); } };
BasicDBObject
DBObject object= new BasicDBObject() { { put("name", name; put("id", id); } };
1七、MySQL修改root密碼
mysql -u root mysql> use mysql; mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root'; mysql> FLUSH PRIVILEGES;
http://jingyan.baidu.com/article/0320e2c198ad5f1b87507bc8.html
1八、CentOS 6.5 SSH免密碼登錄
(1)檢查linux是否安裝了SSH,命令爲:
rpm -qa | grep ssh
安裝SSH命令
yum install ssh 或者 yum install openssh-server yum -y install openssh-clients
(2)檢查ssh服務是否開啓,命令爲:
service sshd status
若已經開啓則顯示爲:
/etc/init.d/sshd: line 33: /etc/sysconfig/sshd: Permission denied openssh-daemon (pid 1946) is running...
若沒有開啓,則開啓ssh服務,命令爲:
service sshd start 或者 /etc/init.d/sshd start
(3)檢查ssh是不是自動啓動狀態,命令爲:
chkconfig --list sshd
2~5爲on則表示ssh會在系統啓動時自動啓動
(4)生成公鑰和私鑰
ssh-keygen -t rsa 或者 ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
接着
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 或者 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
(5)在服務器上更改權限
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
(6)驗證
ssh -version ssh localhost
(7)查看是否啓動22端口
netstat -antp | grep sshd
1九、Hadoop錯誤 org.apache.hadoop.yarn.exceptions.YarnException: Unauthorized request to start container.解決方法
問題緣由:namenode,datanode時間同步問題
解決辦法:多個datanode與namenode進行時間同步
在每臺服務器上執行(把當前時區調整爲上海+8區,而後利用ntpdate同步標準時間)
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ntpdate us.pool.ntp.org
若是沒有ntpdate,則安裝
yum install -y ntpdate
reboot重啓以後,
查看時間和日期
date
查看當前時區
date -R
20、CentOS7沒法使用ifconfig
安裝net-tools包
yum install net-tools
2一、CentOS 6.5安裝MySQL
1)安裝
yum install -y mysql-server mysql mysql-devel
2)啓動MySQL
service mysqld start
3)設置開機啓動
chkconfig mysqld on
4)第一次啓動MySQL後,設置root帳號密碼
mysqladmin -u root password '123456'
5) 設置遠程登錄
登錄MySQL
mysql -u root -p
而後輸入
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by '123456' WITH GRANT OPTION; flush privileges;
exit
並重啓MySQL
service mysqld restart
2二、hive錯誤解決
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: An exception was thrown while adding/validating class(es) : Specified key was too long; max key length is 767 bytes
解決辦法:
登錄MySQL,運行
alter database hive character set latin1;
2三、Java寫文件指定編碼格式
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("data\\" + date + ".txt"), "UTF-8"));
2四、JSP顯示本地圖片
須要設置虛擬目錄,也就是說把硬盤上一個目錄映射到tomcat的工做目錄下,而後tomcat就能夠根據一個映射關係找到硬盤中的文件了。
修改Tomcat的conf/server.xml文件
在<Host>標籤內加入以下代碼
<Context crossContext="true" docBase="/home/jason/upload" path="/upload" reloadable="true"></Context>
其中docBase就是本地電腦的絕對路徑
path就是設置的虛擬路徑
修改完以後須要重啓tomcat服務器
而後,在JSP中調用
<input type="image" src="/upload/google.png" width="538px" height="190px" />
2五、解壓.rar文件
wget http://www.rarsoft.com/rar/rarlinux-4.0.1.tar.gz
tar -zxvf rarlinux-4.0.1.tar.gz cd rar make
運行命令rar時,出現下面這個問題
rar: /lib/i686/nosegneg/libc.so.6: version `GLIBC_2.7' not found (required by rar)
則進入rar目錄
cp rar_static /usr/local/bin/rar
解壓rar文件
rar x file.rar
打包成rar文件
rar file.rar ./file/
2六、Java讀寫UTF-8文本
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("temp.txt")), "UTF-8"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("temp.txt")), "UTF-8"));
根據狀況修改編碼格式
unicode unicode big endian
utf-8 utf-8
utf-16 unicode
gb2312 ANSI
2七、查看操做系統版本相關信息
cat /etc/issue
查看系統版本
cat /etc/redhat-release
2八、查看系統硬件信息
grep MemTotal /proc/meminfo #查看內存總量 cat /proc/cpuinfo #查看CPU信息
free -m 查看內存信息
2九、查看端口狀態
/etc/init.d/iptables status
參考:http://www.centoscn.com/CentOS/help/2013/0725/558.html
30、nameserver
vi /etc/resolv.conf
nameserver 8.8.8.8 nameserver 8.8.4.4 nameserver 127.0.0.1
3一、CentOS 6.5 修改系統ulimit 暨 org.apache.tomcat.jni.Error: 24: Too many open files 解決方法
vi /etc/security/limits.conf
添加
vi /etc/security/limits.d/90-nproc.conf
3二、CentOS服務器 netstat命令 查看TCP鏈接數信息
netstat命令的功能是顯示網絡鏈接、路由表和網絡接口的信息,可讓用戶得知有哪些網絡鏈接正在運做。在平常工做中,咱們最經常使用的也就兩個參數,即netstat –an,以下所示:
# netstat -an
netstat -an參數中stat(狀態)的含義以下:
LISTEN:偵聽來自遠方的TCP端口的鏈接請求;
SYN-SENT:在發送鏈接請求後等待匹配的鏈接請求;
SYN-RECEIVED:在收到和發送一個鏈接請求後等待對方對鏈接請求的確認;
ESTABLISHED:表明一個打開的鏈接,咱們經常使用此做爲併發鏈接數;
FIN-WAIT-1:等待遠程TCP鏈接中斷請求,或先前的鏈接中斷請求的確認;
FIN-WAIT-2:從遠程TCP等待鏈接中斷請求;
CLOSE-WAIT:等待從本地用戶發來的鏈接中斷請求;
CLOSING:等待遠程TCP對鏈接中斷的確認;
LAST-ACK:等待原來發向遠程TCP的鏈接中斷的確認;
TIME-WAIT:等待足夠的時間以確保遠程TCP鏈接收到中斷請求的確認;
CLOSED:沒有任何鏈接狀態;
在平常工做中,咱們能夠用shell組合命令來查看服務器的TCP鏈接狀態並彙總,命令以下:
netstat -an|awk '/^tcp/{++S[$NF]}END{for (a in S)print a,S[a]}'
參數說明:
CLOSED:沒有鏈接活動或正在進行的;
LISTEN:服務器正在等待的進入呼叫;
SYN_RECV:一個鏈接請求已經到達,等待確認;
SYN_SENT:應用已經開始,打開一個鏈接;
ESTABLISHED:正常數據傳輸狀態,也能夠近似的理解爲當前服務器的併發數;
FIN_WAIT1:應用已經完成;
FIN_WAIT2:另外一邊贊成釋放;
ITMED_WAIT:等待全部分組死掉;
CLOSING:兩邊同時嘗試關閉;
TIME_WAIT:另外一邊已初始化一個釋放;
LAST_ACK:等待全部分組死掉;
統計 TCP鏈接數 命令:
netstat -an |grep 'ESTABLISHED' |grep 'tcp' |wc -l
參考:http://blog.csdn.net/youngqj/article/details/763089
3三、Windows下修改MySQL最大鏈接數
在C:\ProgramData\MySQL\MySQL Server 5.6目錄下,修改my.ini
max_connections=3000
3四、CentOS 6.5 x64安裝htop
# yum install -y wget # wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm # yum repolist # yum install -y htop
3五、MySQL去除字段中的空格
update `dictionary_0` set `abbre`=replace(`abbre`,' ','');
3六、jQuery UI autocomplete的提示框屬性設置
jquery-ui.css:
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #DCDCDC;//設置鼠標通過提示條目時的邊框顏色 background: #DCDCDC url("images/ui-bg_glass_100_fdf5ce_1x400.png") 50% 50% repeat-x;//設置鼠標通過時提示條目的背景顏色 font-weight: normal;//設置鼠標通過時字體的粗細 color: #000000;//設置鼠標通過時字體的顏色 } .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited, .ui-state-focus a, .ui-state-focus a:hover, .ui-state-focus a:link, .ui-state-focus a:visited { color: #000000; text-decoration: none; }
具體的能夠嘗試更改。
3七、Cookie
在保存cookie以前把值編碼下:
Cookie cookie = new Cookie(name, URLEncoder.encode(value, "UTF-8"));
取cookie值時解碼:
String value = URLDecoder.decode(cookie.getValue(), "UTF-8");
3八、Hive啓動報錯(Hive 1.2.1+Hadoop 2.6.0)
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
at jline.console.ConsoleReader.<init>(ConsoleReader.java:230)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
解決辦法:
將/opt/hadoop-2.6.0/share/hadoop/yarn/lib 下的jline-0.9.94.jar換成hive lib中的jline-2.12.jar
3九、-bash: jps: command not found
vi ~/.bash_profile
修改
PATH=$PATH:$HOME/bin 》》》 PATH=$PATH:$HOME/bin:/sbin:/usr/bin:/usr/sbin
source /etc/profile
40、Spark Streaming中空batches處理的兩種方法
Spark Streaming是近實時(near real time)的小批處理系統。對給定的時間間隔(interval),Spark Streaming生成新的batch並對它進行一些處理。每一個batch中的數據都表明一個RDD,可是若是一些batch中沒有數據會發生什麼事情呢?Spark Streaming將會產生EmptyRDD的RDD,它的定義以下:
package org.apache.spark.rdd import scala.reflect.ClassTag import org.apache.spark.{Partition, SparkContext, TaskContext} /** * An RDD that has no partitions and no elements. */ private[spark] class EmptyRDD[T: ClassTag](sc: SparkContext) extends RDD[T](sc, Nil) { override def getPartitions: Array[Partition] = Array.empty override def compute(split: Partition, context: TaskContext): Iterator[T] = { throw new UnsupportedOperationException("empty RDD") } }
能夠看到這個RDD並不對任何父RDD有依賴關係,咱們不能調用compute方法計算每一個分區的數據。EmptyRDD的存在是爲了保證Spark Streaming中多個batch的處理是一致的。可是存在EmptyRDD有時候會產生一些問題,好比:若是你想將接收到的Streaming數據寫入HDFS中:
val ssc = new StreamingContext(args(0), "iteblog", Seconds(10)) val socketStream = ssc.socketTextStream("www.iteblog.com", 8888) val outputDir = args(1) socketStream.foreachRDD(rdd => { rdd.saveAsTextFile(outputDir) })
當你調用foreachRDD的時候若是當前rdd是EmptyRDD,這樣會致使在HDFS上生成大量的空文件!這確定不是咱們想要的,咱們只想在存在數據的時候才寫HDFS,咱們能夠經過如下的兩種方法來避免這種狀況:
socketStream.foreachRDD(rdd => { if (rdd.count() != 0) { rdd.saveAsTextFile(outputDir) } })
EmptyRDD的count確定是0,因此這樣能夠避免寫空文件,或者咱們也能夠用下面方法解決:
socketStream.foreachRDD(rdd => { if (!rdd.partitions.isEmpty) { rdd.saveAsTextFile(outputDir) } })
EmptyRDD是沒有分區的,因此調用partitions.isEmpty是true。這樣也能夠解決上述問題。
雖然上面兩種方法均可以解決這個問題,可是推薦使用第二種方法。由於第一種方法調用了RDD的count函數,這是一個Action,會觸發一次Job的計算,當你的數據量比較大的時候,這可能會帶來性能方面的一些影響;而partitions.isEmpty是不須要觸發Job的。
不過若是你使用的是Sprk 1.3.0,你能夠調用isEmpty函數來判斷一個RDD是否爲空,這個函數是在SPARK-5270引入的。
轉自:http://www.iteblog.com/archives/1304
4一、YARN中的kill應用的操做命令
bin/yarn application -kill <applicationId>
42、Kafka基本操做
啓動後臺運行 /opt/kafka/bin/kafka-server-start.sh -daemon /opt/kafka/config/server.properties
中止 /opt/kafka/bin/kafka-server-stop.sh
命令行建立主題
/opt/kafka/bin/kafka-topics.sh --create --zookeeper 192.168.1.101:2181,192.168.1.102:2181,192.168.1.103:2181/kafka --replication-factor 1 --partitions 3 --topic Prediction
命令行建立生產者和消費者
/opt/kafka/bin/kafka-console-producer.sh --broker-list 192.168.1.101:9092,192.168.1.102:9092,192.168.1.103:9092 --topic Prediction
/opt/kafka/bin/kafka-console-consumer.sh --zookeeper 192.168.1.101:2181,192.168.1.102:2181,192.168.1.103:2181/kafka --topic Prediction
4三、CentOS查看文件大小
查找大文件
find pathName -type f -size +800M
查看某文件夾佔用總的空間大小
du -h --max-depth=1 pathName
4四、Tomcat時區與系統時區不一致
修改catalina.bat 或 catalina.sh,添加
WINDOWS:
set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx800m -Duser.timezone=GMT+08
LINUX :
JAVA_OPTS="-Xms512m -Xmx900m -Duser.timezone=GMT+08"
45、問題描述:VMware 十二、CentOS7_1511,電腦死機,強制關機,重啓後沒法進行用戶目錄,掛載/home失敗,出現以下bug
注:這裏採用克隆一個虛擬系統來進行修復過程,以避免修復錯誤形成損失。
修復過程:
1)輸入root密碼進入系統;
2)使用 df -h命令,能夠看到沒有掛載/home目錄,而/etc/fstab中設置了默認掛載
3)使用 lvdisplay命令能夠查看home所在的卷爲/dev/centos/home
4)執行xfs_repair -n /dev/centos/home ,檢查文件系統是否損壞
5)執行xfs_repair修復文件系統
# xfs_repair -L /dev/centos/home
Phase 1 - find and verify superblock... Phase 2 - using internal log - zero log... ALERT: The filesystem has valuable metadata changes in a log which is being destroyed because the -L option was used. - scan filesystem freespace and inode maps... agi unlinked bucket 4 is 2164932 in ag 1 (inode=1075906756) agi unlinked bucket 7 is 2164935 in ag 1 (inode=1075906759) agf_freeblks 56476472, counted 56476470 in ag 0 agi unlinked bucket 20 is 2011348 in ag 0 (inode=2011348) agi unlinked bucket 28 is 1254556 in ag 0 (inode=1254556) sb_ifree 502, counted 595 sb_fdblocks 228710581, counted 228715521 - found root inode chunk Phase 3 - for each AG... - scan and clear agi unlinked lists... - process known inodes and perform inode discovery... - agno = 0 data fork in ino 43450214 claims free block 6363218 data fork in ino 43450214 claims free block 6363219 imap claims a free inode 43450215 is in use, correcting imap and clearing inode cleared inode 43450215 Metadata corruption detected at xfs_dir3_block block 0x14b71c8/0x1000 corrupt block 0 in directory inode 58326652 will junk block no . entry for directory 58326652 no .. entry for directory 58326652 problem with directory contents in inode 58326652 cleared inode 58326652 - agno = 1 - agno = 2 - agno = 3 - process newly discovered inodes... Phase 4 - check for duplicate blocks... - setting up duplicate extent list... - check for inodes claiming duplicate blocks... - agno = 0 - agno = 1 - agno = 2 entry ".." at block 0 offset 32 in directory inode 58326656 references free inode 58326652 - agno = 3 entry ".idea" in shortform directory 3328138473 references free inode 58326652 junking entry ".idea" in directory inode 3328138473 Phase 5 - rebuild AG headers and trees... - reset superblock... Phase 6 - check inode connectivity... - resetting contents of realtime bitmap and summary inodes - traversing filesystem ... entry ".." in directory inode 58326656 points to free inode 58326652 bad hash table for directory inode 58326656 (no data entry): rebuilding rebuilding directory inode 58326656 - traversal finished ... - moving disconnected inodes to lost+found ... disconnected inode 1254556, moving to lost+found disconnected inode 2011348, moving to lost+found disconnected inode 43450214, moving to lost+found disconnected inode 58326654, moving to lost+found disconnected dir inode 58326656, moving to lost+found disconnected inode 58326657, moving to lost+found disconnected inode 101773608, moving to lost+found disconnected inode 101827014, moving to lost+found disconnected inode 101874234, moving to lost+found disconnected inode 1075906756, moving to lost+found disconnected inode 1075906759, moving to lost+found disconnected inode 1075906772, moving to lost+found disconnected dir inode 1141030705, moving to lost+found disconnected dir inode 3328200787, moving to lost+found Phase 7 - verify and correct link counts... resetting inode 1254512 nlinks from 2 to 5 resetting inode 3328138473 nlinks from 5 to 4 done
6)從新掛載/dev/centos/home到/home
# mount -t xfs /dev/centos/home /home/
參考:http://www.mamicode.com/info-detail-669354.html
4六、分詞
mmse4j
public static String doAndFilter(String words) { // ParaConfiguration paraConfiguration = ParaConfiguration.getInstance(); // String result = ""; // if (null != words && !words.equals("")) { // Seg seg = new MaxWordSeg(dic); // MMSeg mmSeg = new MMSeg(new StringReader(words), seg); // try { // Word word; // while ((word = mmSeg.next()) != null) { // // System.out.print(word + " "); // if (word.getLength() > 1) { // result += word + " "; // } // } // // System.out.println(); // } catch (Exception e) { // e.printStackTrace(); // } // } // return result; // }
IKAnalyzer
IKSegmenter ik = new IKSegmenter(new StringReader(words), false); //true粗粒度false細粒度 Lexeme lex = null; try { while ((lex = ik.next()) != null) { System.out.print(lex.getLexemeText() + "|"); } } catch (IOException e) { e.printStackTrace(); }
4七、CentOS安裝SBT
# curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo
# yum install sbt
4八、ES 5.4.2啓動報錯
ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] [2017-06-22T14:43:25,884][INFO ][o.e.n.Node ] [yTEiH2w] stopping ... [2017-06-22T14:43:25,918][INFO ][o.e.n.Node ] [yTEiH2w] stopped [2017-06-22T14:43:25,919][INFO ][o.e.n.Node ] [yTEiH2w] closing ... [2017-06-22T14:43:25,932][INFO ][o.e.n.Node ] [yTEiH2w] closed
解決問題1:
$ sudo vi /etc/security/limits.conf
修改/etc/security/limits.conf文件,添加或修改:
* hard nofile 65536 * soft nofile 65536
或者
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
解決問題2:
$ sudo sysctl -w vm.max_map_count=262144
或者修改 /etc/sysctl.conf 文件,添加 「vm.max_map_count」設置
$ sysctl -a
參考 http://blog.csdn.net/kongxx/article/details/52993057
4九、安裝RabbitMQ
1)安裝erlang yum install erlang 2)導入公共簽名密鑰 rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc 3)下載rabbitmq安裝包 wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-3.6.10-1.el7.noarch.rpm 4)安裝rabbitmq yum install rabbitmq-server-3.6.10-1.el7.noarch.rpm 5)啓動 service rabbitmq-server start /bin/systemctl start rabbitmq-server.service
50、EPEL源
# yum install -y epel-release.noarch
# yum repolist
# yum install -y epel-release.noarch
5一、CURL
$ curl -i -X POST -H "Content-Type:application/json" -d "{ \"firstName\" : \"Frodo\", \"lastName\" : \"Baggins\" }" http://localhost:8080/people HTTP/1.1 201 Created Server: Apache-Coyote/1.1 Location: http://localhost:8080/people/53149b8e3004990b1af9f229 Content-Length: 0 Date: Mon, 03 Mar 2014 15:08:46 GMT
-i ensures you can see the response message including the headers. The URI of the newly created Person is shown -X POST signals this a POST used to create a new entry -H "Content-Type:application/json" sets the content type so the application knows the payload contains a JSON object -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' is the data being sent
5二、CentOS 7安裝sbt
curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo sudo yum install sbt
5三、MongoDB Document 與JSON互轉
# Document 轉 對象
Document doc = new Document(); Employee emp = new Gson().fromJson(document.toJson(), Employee.class); # 對象 轉 Document Customer customer = new Customer(); Document doc = Document.parse(new Gson().toJson(customer));
<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.0</version> </dependency>
5四、安裝nodejs
Node.js 8 curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash - sudo yum -y install nodejs
參考:https://nodejs.org/en/download/package-manager/
5五、hadoop/spark切換端口
若是ssh端口不是操做系統默認的22端口,在這裏假設ssh端口號爲16922
在hadoop裏面修改hadoop-env.sh,增長
export HADOOP_SSH_OPTS="-p 16922"
在spark裏面修改spark-env.sh,增長
export SPARK_SSH_OPTS="-p 16922"
5六、系統可用的處理器個數
Runtime.getRuntime().availableProcessors()
5七、centOS7下安裝GUI圖形界面
1)在命令行下 輸入下面的命令來安裝Gnome包。
# yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
2)更新系統的運行級別。
# ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
3)重啓機器。啓動默認進入圖形界面。
# reboot
http://www.cnblogs.com/c-xiaohai/p/6509641.html
5八、多線程
ExecutorService executorService = Executors.newCachedThreadPool(); AtomicInteger temp = new AtomicInteger(); Dao.findAll().forEach( score -> { // Lambda Runnable executorService.submit(() -> { temp.incrementAndGet(); writeToMySQL(score.getId(), score.Id()); temp.decrementAndGet(); }); } ); while (true) { System.out.println(temp.get()); if (temp.get() == 0) { break; } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); System.out.println("ExecutorService Stop ERROR"); break; } }
5九、CentOS安裝sbt
curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo sudo yum install sbt
60、SVN沒法clean up
step1:到sqlite官網(http://www.sqlite.org/download.html)下載sqlite3.exe;找到PrecompiledBinariesforWindows,點擊sqlite-shell-win32-x86-3080500.zip下載,300KB左右.
step2:將下載到的sqlite3.exe放到某文件目錄(我這裏是F:\devTools\sqlite3)
step3:而後設置svn源代碼文件夾及文件顯示全部文件(包括隱藏文件),會發現.svn/wc.db文件,將其複製到step2的目錄下
step4:開始->運行->打開cmd命令,跳轉到setp2的文件目錄中,執行打開wc.db的操做,而後刪除裏面work_queue表的數據便可,具體見圖:
step5:將wc.db覆蓋到svn源代碼目錄的.svn目錄下(替換原來的wc.db)。
step6:再次對svn目錄進行clean操做,便可cleanUp成功。
http://blog.csdn.net/u012049463/article/details/41517343
6一、MongoDB 中文排序
默認狀況下,中文字段會被當作一個普通的二機制字符串來對比。MongoDB 3.4支持指定collation使用中文排序。
https://docs.mongodb.com/manual/reference/collation/
http://www.mongoing.com/archives/3912
6二、IDEA SBT
vi ~/.sbt/repositories
[repositories] local ui:http://uk.maven.org/maven2/ ui-ivy:http://uk.maven.org/maven2/,[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext] typesafe:http://repo.typesafe.com/typesafe/releases/ typesafe-ivy: http://repo.typesafe.com/typesafe/ivy-releases/,[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly sbt-plugin: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/ sonatype: http://oss.sonatype.org/content/repositories/snapshots repo2: http://repo2.maven.org/maven2/
6三、Spring data mongodb排序有三種方式
1)一個字段的排序
query.with(new Sort(Direction.ASC,"onumber"));
2)多個字段時同時升序或者降序時
query.with(new Sort(Direction.ASC,"a","b","c"));
3)不一樣的字段按照不一樣的排序
List<Sort.Order>orders=new ArrayList<Sort.Order>(); orders.add(newSort.Order(Direction.ASC, "a")); orders.add(newSort.Order(Direction.DESC, "b")); query.with(newSort(orders ));
6四、map排序
// sort //將map.entrySet()轉換成list List<Map.Entry<String, Double>> list = new ArrayList<>(Map.entrySet()); //而後經過比較器來實現排序// With lambdas Collections.sort(list, (Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) -> { double temp = o2.getValue() - o1.getValue(); if (temp > 0) { return 1; } else if (temp == 0) { return 0; } else { return -1; } });
6五、查看CPU信息
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
查看內存信息
cat /proc/meminfo
6六、修改系統文件數限制、進程限制
*** [WARN] *** Your open file limit is currently 1024. It should be set to 65000 to avoid operational disruption. If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh *** [WARN] *** Your Max Processes Limit is currently 4096. It should be set to 65000 to avoid operational disruption. If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'.
修改/etc/security/limits.conf文件,在最後添加
* hard nofile 65000 * soft nofile 65000 * hard nproc 65000 * soft nproc 65000
6七、vim經常使用命令
i 切換到輸入模式,以輸入字符 ESC,退出輸入模式,切換到命令模式 0 或功能鍵[Home] 這是數字『 0 』:移動到這一行的最前面字符處 $ 或功能鍵[End] 移動到這一行的最後面字符處 G 移動到這個檔案的最後一行 /word 向光標之下尋找一個名稱爲 word 的字符串。例如要在檔案內搜尋 vbird 這個字符串,就輸入 /vbird 便可! (經常使用) x, X 在一行字當中,x 爲向後刪除一個字符 (至關於 [del] 按鍵), X 爲向前刪除一個字符(至關於 [backspace] 亦便是退格鍵) (經常使用) dd 刪除遊標所在的那一整行(經常使用) ndd n 爲數字。刪除光標所在的向下 n 行,例如 20dd 則是刪除 20 行 (經常使用) yy 複製遊標所在的那一行(經常使用) nyy n 爲數字。複製光標所在的向下 n 行,例如 20yy 則是複製 20 行(經常使用) p, P p 爲將已複製的數據在光標下一行貼上,P 則爲貼在遊標上一行! 舉例來講,我目前光標在第 20 行,且已經複製了 10 行數據。則按下 p 後, 那 10 行數據會貼在本來的 20 行以後,亦即由 21 行開始貼。
但若是是按下 P 呢? 那麼本來的第 20 行會被推到變成 30 行。 (經常使用) u 復原前一個動做。(經常使用) [Ctrl]+r 重作上一個動做。(經常使用)
i, I 進入輸入模式(Insert mode):
i 爲『從目前光標所在處輸入』, I 爲『在目前所在行的第一個非空格符處開始輸入』。 (經常使用)
a, A 進入輸入模式(Insert mode):
a 爲『從目前光標所在的下一個字符處開始輸入』, A 爲『從光標所在行的最後一個字符處開始輸入』。(經常使用)
o, O 進入輸入模式(Insert mode):
這是英文字母 o 的大小寫。o 爲『在目前光標所在的下一行處輸入新的一行』; O 爲在目前光標所在處的上一行輸入新的一行!(經常使用)
r, R 進入取代模式(Replace mode):
r 只會取代光標所在的那一個字符一次;R會一直取代光標所在的文字,直到按下 ESC 爲止;(經常使用)
6八、Maven設置國內鏡像地址
在maven的conf目錄下的settings.xml文件的<mirrors>標籤中增長如下內容
<mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </mirror>
6九、設置阿里雲maven倉庫
<!-- 阿里雲maven倉庫 --> <repositories> <repository> <id>public</id> <name>aliyun nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>aliyun nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories>
70、Tomcat設定時區
JAVA_OPTS="-Xms512m -Xmx900m -Duser.timezone=GMT+08"
7一、年月日
public void judgeTime() throws ParseException { SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTime(datetimeFormat.parse("2018-10-12 12:00:00")); calendar.setMinimalDaysInFirstWeek(7); //取得當前時間 String currentTime = datetimeFormat.format(calendar.getTime()); calendar.add(Calendar.DAY_OF_MONTH, -1); //前一天 String beforeDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()); int year = calendar.get(Calendar.YEAR);//年 int month = calendar.get(Calendar.MONTH) + 1;//0-11月 int quarter = DateUtil.getQuarter(month);//季度 int week = calendar.get(Calendar.WEEK_OF_YEAR);//周 String startTime, endTime, timeRange, pushDate;//開始時間/結束時間/時間範圍/推送日期 //-------------------------------- 日統計:天天凌晨1點,統計前一天(工做日)數據 ----------------------------------// // -------------------判斷是不是工做日 int workingDay = statisticsMapper.judgeWorkingDay(beforeDate); System.out.println("統計的日期:" + beforeDate + "\t" + (workingDay == 0 ? "工做日" : "非工做日")); if (workingDay == 0) {//工做日 startTime = beforeDate + " 00:00:00"; endTime = beforeDate + " 23:59:59"; timeRange = year + "年" + month + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日"; pushDate = statisticsMapper.getNextWorkingDayAfterDate(beforeDate); //日期的下一個工做日 System.out.println("日統計:\t時間範圍=" + timeRange + "\t開始時間=" + startTime + "\t結束時間=" + endTime + "\t推送日期=" + pushDate ); } //--------------------------------- 周統計:每週一凌晨1點,統計上一週數據 ----------------------------------// if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(calendar.getTime()); calendar1.add(Calendar.DAY_OF_MONTH, -6); startTime = datetimeFormat.format(calendar1.getTime()); endTime = beforeDate + " 23:59:59"; timeRange = year + "年第" + week + "周次"; pushDate = statisticsMapper.getNextWorkingDayAfterDate(beforeDate); //本週第一個工做日 System.out.println("周統計:\t時間範圍=" + timeRange + "\t開始時間=" + startTime + "\t結束時間=" + endTime + "\t推送日期=" + pushDate ); } //-------------------------------- 月度統計:每個月度第一天凌晨1點,統計上一月度數據 ---------------------------------// if (currentTime.substring(8, 10).equals("01")) {//1日 startTime = DateUtil.getStartTimeOfMonth(month); endTime = DateUtil.getEndTimeOfMonth(month); timeRange = year + "年第" + month + "月度"; pushDate = statisticsMapper.getFirstWorkingDayOfMonth(currentTime.substring(0, 7));//本月第一個工做日 System.out.println("月度統計:\t時間範圍=" + timeRange + "\t開始時間=" + startTime + "\t結束時間=" + endTime + "\t推送日期=" + pushDate ); //------------------------------- 季度統計:每季度第一天凌晨1點,統計上一個季度數據 --------------------------------// if (currentTime.substring(5, 7).equals("01") || currentTime.substring(5, 7).equals("04") || currentTime.substring(5, 7).equals("07") || currentTime.substring(5, 7).equals("10")) {//1月1日,4月1日,7月1日,10月1日 startTime = DateUtil.getStartTimeOfQuarter(quarter); endTime = DateUtil.getEndTimeOfQuarter(quarter); timeRange = year + "年第" + quarter + "季度"; System.out.println("季度統計:\t時間範圍=" + timeRange + "\t開始時間=" + startTime + "\t結束時間=" + endTime + "\t推送日期=" + pushDate ); //-------------------------------- 年度統計:每一年度第一天凌晨1點,統計上一年度數據 ---------------------------------// if (currentTime.substring(5, 7).equals("01")) {//1月1日 startTime = DateUtil.getStartTimeOfYear(year); endTime = DateUtil.getEndTimeOfYear(year); timeRange = year + "年度"; System.out.println("年度統計:\t時間範圍=" + timeRange + "\t開始時間=" + startTime + "\t結束時間=" + endTime + "\t推送日期=" + pushDate ); } } } }
7二、Restful API防止重複提交
後端根據請求的uriPath+userId+MD5(JsonString(全部參數))做爲key,來肯定惟一。採用redis分佈式鎖
採用計數器:每次request進來則新建一個以orderId爲key的計數器,而後+1。
若是>1(不能得到鎖): 說明有操做在進行,刪除。 若是=1(得到鎖): 能夠操做。
操做結束(刪除鎖):刪除這個計數器。
7三、warning: LF will be replaced by CRLF in src/xx.java.
提交檢出均不轉換
git config core.autocrlf false
7四、Spring boot應用指定profile
1)application.properties
#使用的環境名稱
spring.profiles.active=dev
2)application.yml
#須要使用的配置文件
spring:
profiles:
active: prod
3)Program arguments
在IDE的Program arguments中配置參數
--spring.profiles.active=dev
4)虛擬機的方式
在VM options下使用命令:-Dspring.profiles.active=prod
-Dspring.profiles.active=prod
5)命令行
將項目打包成jar包,切換到命令行的界面下使用命令: java -jar application.jar --spring.profiles.active=prod進行打包。
java -jar application.jar --spring.profiles.active=prod
7五、
Mysql服務器的三種時區設置
1)系統時區 - 保存在系統變量system_time_zone
2)服務器時區 - 保存在全局系統變量global.time_zone
3)每一個客戶端鏈接的時區 - 保存在會話變量session.time_zone
MySQL查看時區
show global variables like'%time_zone%';
flush privileges;
7六、查看域名的HTTPS到期時間
# echo | openssl s_client -servername www.XX.cn -connect www.XX.cn:443 2>/dev/null | openssl x509 -noout -dates
7七、文件替換彈框
rz -y
7八、查看Nginx安裝了哪些模塊
nginx -V
查看Nginx版本信息
nginx -v
從新載入配置文件
nginx -s reload
重啓 Nginx
nginx -s reopen
中止 Nginx
nginx -s stop
7九、MySQL導出函數
mysqldump -hlocalhost -uroot -ntd -R hqgr > hqgr.sql
其中的 -ntd 是表示導出存儲過程;-R是表示導出函數