https://github.com/JeffLi1993/springboot-learning-example
https://github.com/ityouknow/spring-boot-examples
分类目录归档:Java开发
单点登录
https://github.com/shuzheng/zheng
https://github.com/apache/shiro
https://github.com/zhangkaitao/shiro-example
https://github.com/hs-web/hsweb-framework
https://github.com/thinkgem/jeesite
pom文件中的repositories配置
offical
Maven Official Repository
http://repo1.maven.org/maven2
false
repo2
Human Readable Name for this Mirror.
http://repo2.maven.org/maven2/
CN
OSChina Central
http://maven.oschina.net/content/groups/public/
alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
spring-milestone
https://repo.spring.io/libs-milestone
true
repository.spring.snapshot
Spring Snapshot Repository
http://repo.spring.io/snapshot
net-cn
Human Readable Name for this Mirror.
http://maven.net.cn/content/groups/public/
nexus
Team Nexus Repository
http://192.168.1.178:8081/nexus/content/groups/public
多线程测试
public class SyncTest{
private Long val = 1L;
// private Long val = new Long(1L);
private Object lock = new Object();
public void printVal(int v){
synchronized (lock){
for (int i = 0; i < 50; i++) {
System.out.print(v);
}
}
}
public void printVal2(int v){
synchronized (SyncTest.class){
for (int i = 0; i < 50; i++) {
System.out.print(v);
}
}
}
public void printVal3(int v){
synchronized (SyncTest.class) {
for (int i = 0; i < 50; i++) {
System.out.print(v);
}
}
}
public synchronized void printVal4(int v){
for (int i = 0; i < 50; i++) {
System.out.print(v);
}
}
public synchronized void printVal5(int v){
for (int i = 0; i < 50; i++) {
System.out.print(v);
}
}
public void printVal6(int v){
val = (long)v; //同为一个st对象,但在同步时琐定到不对象,故也达不到同步的目的。
synchronized (val) {
for (int i = 0; i < 50; i++) {
val++;
System.out.print(v);
}
}
}
public void printVal7(int v){
val = (long)v;
synchronized (val) {
for (int i = 0; i < 50; i++) {
val++;
System.out.print(v);
}
}
}
public void printVal8(int v){
synchronized (this) {
for (int i = 0; i < 50; i++) {
val++;
System.out.print(v);
}
}
}
public void printVal9(int v){
synchronized (this) {
for (int i = 0; i < 50; i++) {
val++;
System.out.print(v);
}
}
}
public static void main(String args[]) {
final SyncTest st = new SyncTest();
final SyncTest st2 = new SyncTest();
Thread f1 = new Thread(new Runnable() {
public void run() {
st.printVal6(1);
}
});
f1.start();
Thread f2 = new Thread(new Runnable() {
public void run() {
st.printVal7(2);
}
});
f2.start();
}
}
1.修饰函数时,相同对象互斥,不同对象等同于没有synchronized
2.Long val=1L时,多个实例间仍然是同步的。故原子类型不合适作同步变量使用。
图示:
添加第三方库并使其编译进JAR包中
添加第三方JAR包后,为了使第三方包也能打包进SpringBoot的boot-inf/lib目录。
执行打包指令:mvn package
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
com.aliyun
aliyun-java-sdk-core
3.2.3
system
${project.basedir}/libs/aliyun-java-sdk-core-3.2.3.jar
com.aliyun
aliyun-java-sdk-dysmsapi
1.0.0
system
${project.basedir}/libs/aliyun-java-sdk-dysmsapi-1.0.0.jar
com.aliyun.mns
aliyun-sdk-mns
1.1.8
system
${project.basedir}/libs/aliyun-sdk-mns-1.1.8.jar
com.aliyun
aliyun-java-sdk-dybaseapi
1.0.0
system
${project.basedir}/libs/aliyun-java-sdk-dybaseapi-1.0.0.jar
com.aliyun.alicom
alicom-mns-receive-sdk
1.0.0
system
${project.basedir}/libs/alicom-mns-receive-sdk-1.0.0.jar
org.apache.httpcomponents
httpclient
4.5.3
org.apache.httpcomponents
httpasyncclient
4.1.3
org.apache.httpcomponents
httpcore
4.4.1
org.apache.httpcomponents
httpcore-nio
4.4.1
org.apache.commons
commons-lang3
3.1
org.springframework.boot
spring-boot-maven-plugin
libs
BOOT-INF/lib/
**/*.jar
src/main/resources
BOOT-INF/classes/
elasticsearch数据持久化
elasticSearch数据持久化,默认情况不启用数据保存,故数据一般会几分钟就消失,按以下步骤保存索引数据。
#不同的集群名字不能相同。
cluster.name: es_vm_test
node.name: vmmaster
network.host: 0.0.0.0
http.port: 9200
#数据索引保存
path.data: /home/abc/elk-5.5.1/elkdata/data
path.logs: /home/abc/elk-5.5.1/elkdata/log
#关闭登录验证
xpack.security.enabled: false
logstash抓取nginx日志
以下是基于elk+lnmp开源进行测试验证。
也可以参考官网的实现方法:https://kibana.logstash.es/content/logstash/plugins/codec/json.html
https://kibana.logstash.es/content/logstash/plugins/codec/multiline.html
在官网文档中,有较多应用场景:
https://kibana.logstash.es/content/
https://kibana.logstash.es/content/logstash/examples/
1.抓取nginx日志
input {
file {
# path => ["/home/wwwlogs/h5.vim.vim.com.log", "/home/wwwlogs/h5.vim.vim.com2.log"]
path => "/home/wwwlogs/h5.vim.vim.com.log"
exclude => "*.zip"
type => "java"
add_field => [ "domain", "h5.vim.vim.com" ]
codec => multiline {
pattern => "^\s+"
what => previous
}
}
file {
# path => ["/home/wwwlogs/h5.api.vim.vim.com.log", "/home/wwwlogs/h5.api.vim.vim.com2.log"]
path => "/home/wwwlogs/h5.api.vim.vim.com.log"
exclude => ["*.zip", "*.gz"]
type => "java"
add_field => [ "domain", "h5.api.vim.vim.com" ]
codec => multiline {
pattern => "^\s+"
what => previous
}
}
}
filter {
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => ["0.0.0.0:9200"]
index => "logstash-%{domain}-%{+YYYY.MM.dd}"
}
}
2.定期清理索引
#!/bin/bash
# --------------------------------------------------------------
# This script is to delete ES indices older than specified days.
# Version: 1.0
# --------------------------------------------------------------
function usage() {
echo "Usage: `basename $0` -s ES_SERVER -d KEEP_DAYS [-w INTERVAL]"
}
PREFIX='logstash-'
WAITTIME=2
NOW=`date +%s.%3N`
LOGPATH=/apps/logs/elasticsearch
while getopts d:s:w: opt
do
case $opt in
s) SERVER="$OPTARG";;
d) KEEPDAYS="$OPTARG";;
w) WAITTIME="$OPTARG";;
*) usage;;
esac
done
if [ -z "$SERVER" -o -z "$KEEPDAYS" ]; then
usage
fi
if [ ! -d $LOGPATH ]; then
mkdir -p $LOGPATH
fi
INDICES=`curl -s $SERVER/_cat/indices?h=index | grep -P '^logstash-.*\d{4}.\d{2}.\d{2}' | sort`
for index in $INDICES
do
date=`echo $index | awk -F '-' '{print $NF}' | sed 's/\./-/g' | xargs -I{} date -d {} +%s.%3N`
delta=`echo "($NOW-$date)/86400" | bc`
if [ $delta -gt $KEEPDAYS ]; then
echo "deleting $index" | tee -a $LOGPATH/es_delete_indices.log
curl -s -XDELETE $SERVER/$index | tee -a $LOGPATH/es_delete_indices.log
echo | tee -a $LOGPATH/es_delete_indices.log
sleep $WAITTIME
fi
done
ELK的启动和停止脚本
#!/bin/sh
path_base=`pwd`
path_elastic="$path_base/elasticsearch-5.5.1/bin/elasticsearch"
path_kibana="$path_base/kibana-5.5.1/bin/kibana"
path_logstash="$path_base/logstash-5.5.1/bin/logstash"
mode=$1
kibana_process=`ps -ef | grep "kibana"| grep -v grep`
elastic_process=`ps -ef | grep "elasticsearch"| grep -v grep|grep -v controller`
case "$mode" in
'start')
echo "it's ready to start op...."
if test -n "$elastic_process"; then
echo "---the elasticsearch had already started.."
else
`$path_elastic -d`
fi
if test -n "$kibana_process"; then
echo "---the kibana had already started.."
else
`nohup $path_kibana > /dev/null 2>&1 &`
fi
echo 'success to start.'
echo '---1--you can test logstash by way bellow----'
echo 'cd logstash-5.5.1 && bin/logstash -f ./config/test.conf && cd ..'
echo 'or cd logstash-5.5.1 && bin/logstash -f ./config/h5.api.vip.com.conf && cd ..'
;;
'stop')
echo "it's ready to check process..."
if test -n "$kibana_process"; then
echo "had find kibana process.."
`echo $kibana_process | awk '{print ($2)}' | xargs kill -9`
fi
if test -n "$elastic_process"; then
echo "had find elasticsearch process.."
`echo $elastic_process | awk '{print ($2)}' | xargs kill -9`
fi
echo 'success to kill.'
;;
*)
basename=`basename "$0"`
echo "Usage: $basename {start|stop} [ ELK server options ]"
exit 1
;;
esac
exit 1
数据库性能压测
mysqltest]$ mysqlslap -S /tmp/mysqltest/mysql.sock -uroot --create=/tmp/mysqltest/user_cart.sql --create-schema=test --query=/tmp/mysqltest/cart1.sql --concurrency=1024 --iterations=3
Benchmark
Average number of seconds to run all queries: 59.774 seconds
Minimum number of seconds to run all queries: 59.570 seconds
Maximum number of seconds to run all queries: 60.040 seconds
Number of clients running queries: 1024
Average number of queries per client: 954
QPS=16343