smniuhe

春风十里,不如你...


  • Home

  • About

  • Tags

  • Categories

  • Archives

  • Schedule

  • Search

redis 简单部署

Posted on 2018-02-13 | Edited on 2019-02-02 | In NoSQL
redis 官网
官网地址
redis 部署概括
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ wget http://download.redis.io/releases/redis-4.0.8.tar.gz
$ tar xzf redis-4.0.8.tar.gz
$ cd redis-4.0.8
$ make

<!-- more -->

## redis-server前端启动
$ src/redis-server

## redis-cli 启动
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
redis 实际部署
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# pwd
/usr/local/redis

## 下载redis解压包
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# wget http://download.redis.io/releases/redis-4.0.8.tar.gz
--2018-02-13 14:12:36-- http://download.redis.io/releases/redis-4.0.8.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 109.74.203.151
正在连接 download.redis.io (download.redis.io)|109.74.203.151|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1729973 (1.6M) [application/x-gzip]
正在保存至: “redis-4.0.8.tar.gz”

100%[=================================================================================================================================>] 1,729,973 973KB/s 用时 1.7s

2018-02-13 14:12:39 (973 KB/s) - 已保存 “redis-4.0.8.tar.gz” [1729973/1729973])

[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# ll
总用量 1692
-rw-r--r-- 1 root root 1729973 2月 3 00:40 redis-4.0.8.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# tar xzf redis-4.0.8.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# ll
总用量 1696
drwxrwxr-x 6 root root 4096 2月 3 00:39 redis-4.0.8
-rw-r--r-- 1 root root 1729973 2月 3 00:40 redis-4.0.8.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# cd redis-4.0.8

## 自动配置
[root@iZuf6iq8e7ya9v3ix71k0pZ redis-4.0.8]# make
cd src && make all
make[1]: 进入目录“/usr/local/redis/redis-4.0.8/src”
​ CC Makefile.dep
make[1]: 离开目录“/usr/local/redis/redis-4.0.8/src”
make[1]: 进入目录“/usr/local/redis/redis-4.0.8/src”
​ ...
​ ...
​ ...
​ CC redis-benchmark.o
​ LINK redis-benchmark
​ INSTALL redis-check-rdb
​ INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/usr/local/redis/redis-4.0.8/src”
[root@iZuf6iq8e7ya9v3ix71k0pZ redis-4.0.8]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README.md runtest runtest-sentinel src utils
BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests
[root@iZuf6iq8e7ya9v3ix71k0pZ redis-4.0.8]# ll
总用量 296
-rw-rw-r-- 1 root root 150927 2月 3 00:39 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 2月 3 00:39 BUGS
-rw-rw-r-- 1 root root 1815 2月 3 00:39 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 2月 3 00:39 COPYING
drwxrwxr-x 6 root root 4096 2月 13 14:14 deps
-rw-rw-r-- 1 root root 11 2月 3 00:39 INSTALL
-rw-rw-r-- 1 root root 151 2月 3 00:39 Makefile
-rw-rw-r-- 1 root root 4223 2月 3 00:39 MANIFESTO
-rw-rw-r-- 1 root root 20543 2月 3 00:39 README.md
-rw-rw-r-- 1 root root 58353 2月 3 00:39 redis.conf
-rwxrwxr-x 1 root root 271 2月 3 00:39 runtest
-rwxrwxr-x 1 root root 280 2月 3 00:39 runtest-cluster
-rwxrwxr-x 1 root root 281 2月 3 00:39 runtest-sentinel
-rw-rw-r-- 1 root root 7606 2月 3 00:39 sentinel.conf
drwxrwxr-x 3 root root 4096 2月 13 14:15 src
drwxrwxr-x 10 root root 4096 2月 3 00:39 tests
drwxrwxr-x 8 root root 4096 2月 3 00:39 utils

## 将启动目录配置到父目录同级下
[root@iZuf6iq8e7ya9v3ix71k0pZ redis-4.0.8]# make PREFIX=/usr/local/redis install
cd src && make install
make[1]: 进入目录“/usr/local/redis/redis-4.0.8/src”
​ CC Makefile.dep
make[1]: 离开目录“/usr/local/redis/redis-4.0.8/src”
make[1]: 进入目录“/usr/local/redis/redis-4.0.8/src”

Hint: It's a good idea to run 'make test' ;)

INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: 离开目录“/usr/local/redis/redis-4.0.8/src”
[root@iZuf6iq8e7ya9v3ix71k0pZ redis-4.0.8]# cd ..
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# ll
总用量 1700
drwxr-xr-x 2 root root 4096 2月 13 14:23 bin
drwxrwxr-x 6 root root 4096 2月 3 00:39 redis-4.0.8
-rw-r--r-- 1 root root 1729973 2月 3 00:40 redis-4.0.8.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ redis]# cd bin
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ll
总用量 21836
-rwxr-xr-x 1 root root 2450960 2月 13 14:23 redis-benchmark
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-aof
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-rdb
-rwxr-xr-x 1 root root 2616128 2月 13 14:23 redis-cli
lrwxrwxrwx 1 root root 12 2月 13 14:23 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-server

## 前端启动(关闭窗口,则服务关闭)
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ./redis-server
21156:C 13 Feb 14:25:25.281 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21156:C 13 Feb 14:25:25.281 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=21156, just started
21156:C 13 Feb 14:25:25.281 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
​ _._
​ _.-``__ ''-._
​ _.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 21156
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
​ `-._ `-.__.-' _.-'
​ `-._ _.-'
​ `-.__.-'

21156:M 13 Feb 14:25:25.283 # Server initialized
21156:M 13 Feb 14:25:25.283 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
21156:M 13 Feb 14:25:25.283 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
21156:M 13 Feb 14:25:25.283 * Ready to accept connections
^C21156:signal-handler (1518503420) Received SIGINT scheduling shutdown...
21156:M 13 Feb 14:30:20.926 # User requested shutdown...
21156:M 13 Feb 14:30:20.926 * Saving the final RDB snapshot before exiting.
21156:M 13 Feb 14:30:20.928 * DB saved on disk
21156:M 13 Feb 14:30:20.929 # Redis is now ready to exit, bye bye...

## 配置后端启动(可以关闭窗口)
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# cp ../redis-4.0.8/redis.conf
cp: 在"../redis-4.0.8/redis.conf" 后缺少了要操作的目标文件
Try 'cp --help' for more information.
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# cp ../redis-4.0.8/redis.conf /usr/local/redis/bin/
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ll
总用量 21900
-rw-r--r-- 1 root root 92 2月 13 14:30 dump.rdb
-rwxr-xr-x 1 root root 2450960 2月 13 14:23 redis-benchmark
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-aof
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-rdb
-rwxr-xr-x 1 root root 2616128 2月 13 14:23 redis-cli
-rw-r--r-- 1 root root 58353 2月 13 14:31 redis.conf
lrwxrwxrwx 1 root root 12 2月 13 14:23 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-server
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# chmod 777 redis.conf
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ll
总用量 21900
-rw-r--r-- 1 root root 92 2月 13 14:30 dump.rdb
-rwxr-xr-x 1 root root 2450960 2月 13 14:23 redis-benchmark
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-aof
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-rdb
-rwxr-xr-x 1 root root 2616128 2月 13 14:23 redis-cli
-rwxrwxrwx 1 root root 58353 2月 13 14:31 redis.conf
lrwxrwxrwx 1 root root 12 2月 13 14:23 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-server
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# vim redis.conf
...
...
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
...
...
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ./redis-server redis.conf
21167:C 13 Feb 14:34:45.321 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21167:C 13 Feb 14:34:45.321 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=21167, just started
21167:C 13 Feb 14:34:45.321 # Configuration loaded
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ps aux|grep redis
root 21168 0.0 0.1 145252 7556 ? Ssl 14:34 0:00 ./redis-server 127.0.0.1:6379
root 21173 0.0 0.0 112664 976 pts/0 S+ 14:35 0:00 grep --color=auto redis

## 启动 redis 实例,并简单set,get
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ./redis-cli
127.0.0.1:6379> set name niuhe
OK
127.0.0.1:6379> get name
"niuhe"
127.0.0.1:6379>
jedis 客户端操作
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
​	@Test
​ public void testJedis() {

/**
* redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
at redis.clients.jedis.Connection.connect(Connection.java:207)
解决:
vim redis.conf
# bind 127.0.0.0.1

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because
protected mode is enabled, no bind address was specified, no authentication password is requested to clients.
In this mode connections are only accepted from the loopback interface. If you want to connect from external
computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the
command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host
the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use
CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by
editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the
server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option
. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order
for the server to start accepting connections from the outside.
解决:
vim redis.conf
protected-mode yes 改成
protected-mode no
*/
Jedis jedis = new Jedis("smniuhe.com", 6379);
jedis.set("name", "smniuhe");
System.out.println(jedis.get("name"));
jedis.close();
}
两种持久化方案
  • rdb(默认)
    • 可以设置间隔多长时间保存一次(Redis不用任何配置默认的持久化方案)
      有点:让redis的数据存取速度变快
      缺点:服务器断电时会丢失部分数据(数据的完整性得不到保
  • aop
    • 可以设置实时保存
      优点:持久化良好,能包装数据的完整性
      缺点:大大降低了redis系统的存取速度
    • 设置为 aop 策略
      修改 redis.conf 配置文件 appendonly yes
主从复制
  • 模拟 redis 集群(从服务器只能读取)
    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
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ll
    总用量 21900
    -rw-r--r-- 1 root root 197 2月 14 18:19 dump.rdb
    -rwxr-xr-x 1 root root 2450960 2月 13 14:23 redis-benchmark
    -rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-aof
    -rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-check-rdb
    -rwxr-xr-x 1 root root 2616128 2月 13 14:23 redis-cli
    -rwxrwxrwx 1 root root 58356 2月 13 16:04 redis.conf
    lrwxrwxrwx 1 root root 12 2月 13 14:23 redis-sentinel -> redis-server
    -rwxr-xr-x 1 root root 5762432 2月 13 14:23 redis-server
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin]# rm -rf dump.rdb
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ../
    [root@iZuf6iq8e7ya9v3ix71k0pZ redis]# mkdir bin2
    [root@iZuf6iq8e7ya9v3ix71k0pZ redis]# cp bin/* bin2/
    [root@iZuf6iq8e7ya9v3ix71k0pZ redis]# cp bin2
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# vim redis.conf
    修改 redis-cli 启动的端口号
    port = 6380
    # 设置主的端口 ip port
    # slaveof <masterip> <masterport>
    slaveof 106.15.191.27 6379
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ./redis-server redis.conf
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ./redis-server redis.conf
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ./redis-server redis.conf
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ps -aux|grep redis
    root 21266 0.0 0.2 147300 9768 ? Ssl 2月13 1:10 ./redis-server *:6379
    root 21847 0.0 0.2 147300 9688 ? Ssl 18:16 0:00 ./redis-server *:6380
    root 21853 0.0 0.0 112664 976 pts/0 S+ 18:16 0:00 grep --color=auto redis
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ./redis-cli
    127.0.0.1:6379> set name smniuhe79
    OK
    127.0.0.1:6379> get name
    "smniuhe79"
    127.0.0.1:6379>
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin]# cd ../bin
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ./redis-cli shutdown
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ./redis-cli -p 6380
    127.0.0.1:6380> get name
    "smniuhe79"
    127.0.0.1:6380>

    # 指定ip地址和port
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ./redis-cli -h ip -p 6380
    106.15.191.27:6380> get name

    # 指定校验密码
    [root@iZuf6iq8e7ya9v3ix71k0pZ bin2]# ./redis-cli -h ip -p port -a authpassword
    106.15.191.27:6380> get name

    # 正常关闭实例
    106.15.191.27:6380> shutdown

solr 7.2 + tomcat 的部署

Posted on 2018-02-11 | Edited on 2019-02-02 | In server
官网下载
solr7.2.1
目录结构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
➜  solr-7.2.1 ll
total 2896
-rw-r--r--@ 1 niuhesm staff 737K 1 10 05:32 CHANGES.txt
-rw-r--r--@ 1 niuhesm staff 12K 1 10 05:26 LICENSE.txt
-rw-r--r--@ 1 niuhesm staff 652K 1 10 05:32 LUCENE_CHANGES.txt
-rw-r--r--@ 1 niuhesm staff 24K 1 10 05:26 NOTICE.txt
-rw-r--r--@ 1 niuhesm staff 7.3K 1 10 05:26 README.txt
drwxr-xr-x@ 12 niuhesm staff 408B 2 11 22:44 bin # 生成core实例
drwxr-xr-x@ 11 niuhesm staff 374B 1 10 08:54 contrib
drwxr-xr-x@ 18 niuhesm staff 612B 2 11 12:30 dist
drwxr-xr-x@ 4 niuhesm staff 136B 2 11 12:28 docs
drwxr-xr-x@ 9 niuhesm staff 306B 2 11 12:30 example
drwxr-xr-x@ 535 niuhesm staff 18K 1 10 05:32 licenses
drwxr-xr-x@ 14 niuhesm staff 476B 2 11 22:43 server
Read more »

从未注意的分隔符问题

Posted on 2018-02-09 | Edited on 2019-02-02 | In charset
Git Commit Failed
1
2
3
4
上午10:32	Commit failed with error
​ 0 files committed, 4 files failed to commit: 1.更新分词器配置文件
​ warning: CRLF will be replaced by LF in src/main/resources/IKAnalyzer.cfg.xml.
​ The file will have its original line endings in your working directory.

大概是意思是说 xml 文件有它原始的行编码格式 CRLF,CRLF 并将替换成 LF 的行编码格式,可能是转换的时候出错啦,导致整个 Commit failed

Read more »

macOS 中 Java 版本管理的好帮手 jEnv

Posted on 2018-02-02 | Edited on 2019-02-02 | In VC
困恼

在开发的时候每个人配置 Java 环境都不一样, 或者开发者都有多个版本的 jdk,比如:

1
2
3
4
5
6
7
8
9
10
11
12
# 当前版本
➜ ~ 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)

# 所有的版本
➜ ~ ll /Library/Java/JavaVirtualMachines
total 0
drwxr-xr-x 3 root wheel 102B 6 3 2017 jdk1.7.0_80.jdk
drwxr-xr-x 3 root wheel 102B 4 12 2017 jdk1.8.0_121.jdk
➜ ~

jEnv 介绍

Java 生态中包含大量的你可能想使用的工具,包括 Java 本身到一些构建工具,如 Maven 和 Gradle,以及第三方应用如 ActiveMQ 和 Tomcat 等。经常你会需要同时使用这些工具的不同版本,用于不同的项目,或者想对一个项目在不同版本的环境中做兼容性测试。

管理这些不同版本的工具是一项非常复杂的任务。每个工具有各自不同的获取方式,如果安装,如何控制都是很成问题的。

值得庆幸的是,jenv 可以帮你轻松搞定这个复杂的工作(请注意该工具不同于 jEnv, 这是用来设置 JAVA_HOME 环境变量的)。jenv 支持 Windows、Mac 和 Linux – 可以轻松管理大量基于 Java 开发的工具的多个版本。目前已经支持超过 200 个不同的工具。

jenv 介绍官网
jEnv 安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
➜  ~ brew install jenv
# bash
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
# zsh
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc

# 查看版本
➜ ~ jenv versions
* system (set by /Users/niuhesm/.jenv/version)
➜ ~ bash
bash-3.2$ jenv versions
* system (set by /Users/niuhesm/.jenv/version)
bash-3.2$ zsh
➜ ~ open ~/.bash_profile

它只找到了系统默认的Java,即使我已经下载了其他版本的Java。*表示当前选择的版本。

添加 Java 版本
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
➜  ~ jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
oracle64-1.7.0.80 added
1.7.0.80 added
1.7 added
➜ ~ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/
oracle64-1.8.0.121 added
1.8.0.121 added
1.8 added

# 重新查看版本
➜ ~ jenv versions
* system (set by /Users/niuhesm/.jenv/version)
1.7
1.7.0.80
1.8
1.8.0.121
oracle64-1.7.0.80
oracle64-1.8.0.121

# 只保留一个版本
➜ ~ ....
➜ ~ jenv remove oracle64-1.7.0.80
JDK oracle64-1.7.0.80 removed
➜ ~ jenv remove oracle64-1.8.0.121
JDK oracle64-1.8.0.121 removed
➜ ~ jenv versions
* system (set by /Users/niuhesm/.jenv/version)
1.7.0.80
1.8.0.121
➜ ~

# 指定版本
➜ ~ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
➜ ~ jenv local 1.8.0.121 # 指定当前的运行版本
➜ ~ 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)
➜ ~ jenv which java # 显示可执行的Java的完整路径
/Users/niuhesm/.jenv/versions/1.8.0.121/bin/java
➜ ~

这当然不是真实的路径,而是一个硬链接。你可以找到 /Users/kmyhy/.jenv/versions/ 目录,发现所有的 java 版本都被列在了这里,这些硬链接(相当于 windows 的快捷方式)都指向了对应的 java 安装目录。
你还可以指定一个全局的版本

1
➜  ~ jenv global 1.7.0_80

这样,默认的 java 版本就是 1.7.0_80 了。如果你想在某个项目中使用 1.7.0_80 版本,可以在项目文件夹下新建一个.java-version 文件,将文件内容编辑为 1.7.0_80 保存。这样,你进入这个文件夹时 jenv 会自动使用 1.7.0_80 作为当前版本(即 local 版本)。

CentOS 上搭建 gitlab

Posted on 2018-02-01 | Edited on 2019-02-02 | In VC
GitLab 介绍

最近DevOps非常火, 而GitLab作为其中重要一环, 也越来越受重视, 与SVN相比, GitLab同样提供完美的用户权限管理, 与Git相比, 除了涵盖Git所有功能, 同时又提供方便的后台管理, 非常适合企业使用

殷临风简书
GitLab 安装
1
2
3
4
5
6
7
8
9
10
11
# 1. 安装相关依赖
yum install curl policycoreutils openssh-server openssh-clients -y
# 确保sshd启动(正常情况下, sshd是启动的)
systemctl enable sshd
systemctl start sshd

# 2. 引入yum源, 并安装gitlab
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install gitlab-ce -y
# 配置并启动
gitlab-ctl reconfigure
修改 Nginx 相关配置

由于我用的是阿里云的 ESC,所以默认情况下防火墙的没有关闭的,且 GitLab 内置的 Nginx 默认端口是80,为了不占用这个特殊的端口,我们使用82端口,unicorn 端口也由8080改成8082,即nginx监听的rails端口,类似php-fpm,同样改成8082

  • 配置 Nginx 的默认端口
    1
    2
    3
    4
    5
    6
    vim /etc/gitlab/gitlab.rb
    # nginx['listen_port'] = nil 默认值即80
    nginx['listen_port'] = 82
    vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
    # 默认值listen *:80;
    listen *:82;
  • 修改 unicorn 的默认端口和 Nginx 监听的 rails 端口

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    vim /etc/gitlab/gitlab.rb
    # 原值unicorn['port'] = 8080
    unicorn['port'] = 8082
    vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
    #原值listen "127.0.0.1:8080", :tcp_nopush => true
    listen "127.0.0.1:8082", :tcp_nopush => true

    # 重新加载配置、启动
    gitlab-ctl reconfigure
    gitlab-ctl restart
  • 重新加载配置、启动

    1
    2
    gitlab-ctl reconfigure
    gitlab-ctl restart
测试

由于我的服务器地址配置了域名解析,浏览器上输入 domain:82/ip地址:82,第一次会出现让你注册的界面,直接注册就行,下次输入地址会直接登录


注意事项
  1. GitLab 上需要配置本地的秘钥公约
  2. 新建仓库生成的url 都改成你服务器的 domain:82/ip地址:82,否则会访问失败
  3. git,yum 相关的安装和命令都可以参看 runoob.com 网站

5.7之sql_model

Posted on 2018-01-29 | Edited on 2019-02-02 | In sql
问题发生背景

今天在部署项目的时候发现,测试后台接口,直接报 500,仔细一看原来是操作数据库的时候报错了,在本地测试的时候是没遇到类似的问题,数据库的版本是一样的,后面查找资料,说是 MySQL 5.7 默认的 sql_model 配置是有 only_full_group_by,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 分组查询报错
[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'leping.township_info.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

# 查看当前MySQL sql_mode 配置
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.18 |
+-----------+
1 row in set (0.00 sec)

mysql> select @@sql_mode;
+--------------------------------------------+
| @@sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)

only_full_group_by :使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行

解决的办法就是将这个 sql_model 的 only_full_group_by 参数去除
1
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
  • window server 服务器,直接找到 my.ini 配置文件,如果配置中没有对应的配置,先添加 sql_model ,有则直接移除 only_full_group_by
  • mac vim /etc/my.cof
  • centos 7 vim /etc/my.cof

geotools解析Shapefile文件

Posted on 2018-01-05 | Edited on 2019-02-02 | In GEO
交代背景

前段工程师给了我 gis 相关的一些文件,想让我解析里面的数据,简单点就是解析 Shapefile 文件,由于地理信息相关的数据都是 GeoJson 的数据格式;也是第一次接触 gis,所以先简单的了解了下这些专用的名词。

Shapefile

一个Shapefile文件最少包括三个文件:
主文件(.shp)、–存储地理要素的几何图形的文件。
索引文件(
.shx)、–存储图形要素与属性信息索引的文件。
dBASE表文件(.dbf),–存储要素信息属性的dBase表文件。
除此之外还有可选的文件包括:
空间参考文件(
.prj)、
几何体的空间索引文件(.sbn 和 .sbx)、
只读的Shapefiles的几何体的空间索引文件(.fbn 和.fbx)、
列表中活动字段的属性索引(.ain 和 .aih)、
可读写Shapefile文件的地理编码索引(.ixs)、
可读写Shapefile文件的地理编码索引(.mxs)、
dbf文件的属性索引(
.atx)、
以XML格式保存元数据(.shp.xml)、
用于描述.dbf文件的代码页,指明其使用的字符编码的描述文件(
.cpg)。

Shapefile百度百科地址
Geotools

GeoTools 是英国利兹大学(University of Leeds)的James Macgll 从1996 年开始研发的一个操作和显示地图的开源Java 代码库,[1] 提供了一系列符合规范的操作地理空间数据的方法,例如可以用它来实现一个地理信息系统(GIS)。GeoTools库在开发时执行OGC规范。目前GeoTools的最新版本是 GeoTools 17 Releases。

GeoTools官网地址
Geojson

要素组合的数据格式如下:

简书brandonxiang
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
{ "type": "FeatureCollection",
​ "features": [
​ { "type": "Feature",
​ "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
​ "properties": {"prop0": "value0"}
​ },
​ { "type": "Feature",
​ "geometry": {
​ "type": "LineString",
​ "coordinates": [
​ [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
​ ]
​ },
​ "properties": {
​ "prop0": "value0",
​ "prop1": 0.0
​ }
​ },
​ { "type": "Feature",
​ "geometry": {
​ "type": "Polygon",
​ "coordinates": [
​ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
​ [100.0, 1.0], [100.0, 0.0] ]
​ ]
​ },
​ "properties": {
​ "prop0": "value0",
​ "prop1": {"this": "that"}
​ }
​ }
​ ]
}
核心代码

github-demo 传送门

dozer设计通用的自定义转换器

Posted on 2017-12-29 | Edited on 2019-02-02 | In JavaBean
场景

做国土项目的时候遇到了个类似头疼的问题,就是展现数据
由于要计算统计土地的面积,精度要求,所以 pojo 中用的 BigDecimal 类型,但是在展示的时候类似于表格的形式,没有数据默认就是不填,想来想去还是第三种样式比较方便,前端也好处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
​ "applyLandArea": 14.6121,
​ "xxxLandArea": null,
​ "xxxLandArea": null
}
{
​ "applyLandArea": 14.6121,
​ "xxxLandArea": 0,
​ "xxxLandArea": 0
}
{
​ "applyLandArea": 14.6121,
​ "xxxLandArea": “”,
​ "xxxLandArea": “”
}

dozer 也是最近接触的,以前老是自己手动转换,当属性的数量多起来,伴随着大量的 set 方法,dozer 解决了这部分问题,当你转换的属性比较多并且类型不等的时候,这个时候就需要自己定义转换器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//类级别
<mappings>
<mapping relationship-type="non-cumulative">
​ <!-- 省略 -->
</mapping>
</mappings>

//属性级别
<field relationship-type="cumulative">
<a>hintList</a>
<b>hintList</b>
<a-hint>org.dozer.vo.TheFirstSubClass</a-hint>
<b-hint>org.dozer.vo.TheFirstSubClassPrime</b-hint>
</field>
核心代码

自定义转换器必须实现 CustomConverter 接口
重写 convert 方法

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
public class LandActualConverter implements CustomConverter {

@Override
public Object convert(Object destination, Object source, Class<?> destinationClass, Class<?> sourceClass) {

// 如果满足条件,进行转换
final String emptyStr = "";
boolean havevalue = source instanceof LandActual && Objects.equals(destinationClass, LandActualVm.class);
if (havevalue) {
destination = new LandActualVm();
Field[] fields = source.getClass().getDeclaredFields();
for (Field field : fields) {
Class<?> type = field.getType();
String fieldName = field.getName();
Object value = BeanConverter.invokeGet(source, fieldName);
String baseValue = value + emptyStr;

// 如果为不为null,全部正常处理
if (value != null) {
if (Objects.equals(type, Short.class)) {
BeanConverter.invokeSet(destination, fieldName, new Short(baseValue));
}
if (Objects.equals(type, String.class)) {
BeanConverter.invokeSet(destination, fieldName, baseValue);
}
if (Objects.equals(type, Date.class)) {
BeanConverter.invokeSet(destination, fieldName, DateUtils.parse(baseValue));
}
if (Objects.equals(type, BigDecimal.class)) {
BeanConverter.invokeSet(destination, fieldName, baseValue);
}
// 如果为null,将空值转变成""
} else {
if (Objects.equals(type, Short.class)) {
}
if (Objects.equals(type, String.class)) {
}
if (Objects.equals(type, Date.class)) {
}
if (Objects.equals(type, BigDecimal.class)) {
BeanConverter.invokeSet(destination, fieldName, emptyStr);
}
}
}
return destination;
} else {
return new LandActualVm();
}

}

反射实现通用性
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
public class BeanConverter {

/**
* java反射bean的get方法
*
* @param objectClass
* @param fieldName
* @return
*/
@SuppressWarnings("unchecked")
public static Method getGetMethod(Class objectClass, String fieldName) {
StringBuffer sb = new StringBuffer();
sb.append("get");
sb.append(fieldName.substring(0, 1).toUpperCase());
sb.append(fieldName.substring(1));
try {
return objectClass.getMethod(sb.toString());
} catch (Exception e) {
}
return null;
}

/**
* java反射bean的set方法
*
* @param objectClass
* @param fieldName
* @return
*/
@SuppressWarnings("unchecked")
public static Method getSetMethod(Class objectClass, String fieldName) {
try {
Class[] parameterTypes = new Class[1];
Field field = objectClass.getDeclaredField(fieldName);
parameterTypes[0] = field.getType();
StringBuffer sb = new StringBuffer();
sb.append("set");
sb.append(fieldName.substring(0, 1).toUpperCase());
sb.append(fieldName.substring(1));
Method method = objectClass.getMethod(sb.toString(), parameterTypes);
return method;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

/**
* 执行set方法
*
* @param o
* 执行对象
* @param fieldName
* 属性
* @param value
* 值
*/
public static void invokeSet(Object o, String fieldName, Object value) {
Method method = getSetMethod(o.getClass(), fieldName);
try {
method.invoke(o, new Object[] { value });
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 执行get方法
*
* @param o
* 执行对象
* @param fieldName
* 属性
*/
public static Object invokeGet(Object o, String fieldName) {
Method method = getGetMethod(o.getClass(), fieldName);
try {
return method.invoke(o, new Object[0]);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

4楼图书馆的爱情延时

Posted on 2017-10-19 | Edited on 2019-02-02 | In 生活杂谈

王逸,我的图书馆好友

故事的两位主人公刚好都认识,都是图书馆工作的好友,王逸这名字总让我想得到现在的外交部长,也成了我们之间刚认识加深关系的基带,作为图书馆管理图书的,当然我们经常一起读书了,刚开始我看文学作品,他喜欢看地理,后来我读 c、Java,他读防雷工程;有时候一起吃鸡,必须变态辣,我感觉自己吃辣很厉害了,他比我还厉害,毕竟都是江西人,说实话,他身上有种人格,是我比较喜欢的,随性不受任何约束,相反,我是一个比较有危机感的一个人,看到他会比较安心。今早看到他发的 “思念”,文字太暖,是我很向往的一种爱情,所以打算分享给自己的好友;回想最后一次见面是去年的10月份,返校采集信息,当时在大礼堂拿表,他叫了我,我看了半天,没找到人,发现他原来在身穿一身白的制服(应该是海军制服吧,一直让我很困惑的是,这家伙的专业是防雷,为啥老是打着海军的旗号,..姑娘..,后面省略好多字)的队列中,由于但是大家都在排队,于是简单寒暄了几句,就离开了,下面是他和他 “爱人” 的故事(保留原文不变,略改格式)。

“有空的话进来听听我的故事吧”

时间是让人措不及防的东西
一晃自己都参加工作十个月了
晴时有风阴时有雨
争不过朝夕
又念着往昔
偷走了青丝却留住了一个你
12月28踏上火车的那一刻
从此对故乡的记忆定格在那个冬天
他们有家人送行
我有你
转身上车瞬间哭成个泪人
带着整个车厢的人都跟着哭起来
你问我何时归故里
故里又是何年
哭的更凶了
脚踩在北国的土地上
顿时就如入冰箱一样
给我一南方的汉子下马威,
眼前的一切都是新生和未知的
从最简单的吃饭睡觉学起
不知接下来是什么样的生活
也不知自己选的路对不对
更不知什么时候才能向你道声早
道声晚安
自己在你那仿佛人间蒸发一样
一点消息都没了
就好像我从来就没出现在你的世界一般
留下的最后一条短信
下个季节见

下个季节见

半个月后终于办了张公共电话卡
拨通了早已在心中拨了无数遍的号码
电话那头没有惊喜没有惊讶
一句平平淡淡的恩
我知道你是开心的
只是不善言辞的你
此时更加语塞了
什么都想说
又不知道说什么好
从此电话吧总是少不了我和啊涛的影子
一入话吧深似海
从此队长是大傻
我们约好中午见
晚上见
哪怕熄灯前一分钟
我都会跑下楼去和你道声晚安
因为电话那头那个她在等我尼
中间也因打电话出过篓子
没少挨练
不过听到你的声音后一切都是值得的
后面要上山拉练
又的失联一礼拜了
五天四夜
晚上零下十几度
泼水成冰
只所以提前下山
还是因为大雪封山
也是在北方见的初雪
按耐住迫切告诉你的心情
蓝色大海的传说里初雪的约定
裹着大衣拆帐篷
抬帐篷下山
车已经上不来了
五秒就五秒地上就有积雪了
上山下山不知道多少躺
最后也不知道自己这么上的大巴
又冷又饿又困的睡过去
头一次晕车
下车后忙去电话吧告诉你我下山了
接着恢复以前的生活
训练训练训练
跑圈跑圈跑圈
午休时偷摸进话吧
晚点名后混进话吧
拿着一月880的津贴
打着三毛钱一分钟的长途
这是我在青岛做过最奢侈的事了
想你说的
整个话吧就靠我养活的一样
到了月末把吃蛋炒饭的钱换成泡面
就想多和你通一会电话
可气的死电话卡还被人盗过
心疼了我一阵子
三个月说长不长说短不短
反正我熬过来了
之所以说这么多我
是因为这三个月对我来说太不寻常了
是自己最迷茫
最无助
又最无可奈何的三月
谢谢你

谢谢你陪我伴我左右

做了三个月的电话情人
煲了三个月的电话粥
当了三个月的树洞
打着哈欠陪我聊天到深夜的你
心里回荡着一句话
不能辜负的girl
其实有时候真的怕耽误了你
自己貌似什么都给不了你
除了承诺
可这年代承诺是最廉价的吧
而你却将我的话深信不疑
在后面默默的付出着
茫茫红尘中
经历万千风浪
庆幸得以遇见你
想驻扎进我生命的那道绝世风光
绝世风光
不想你去羡慕任何一个人
只想尽自己最大的努力
让你成为朋友中最让人羡慕的人

今后

拌嘴可以但不能当真
生气可以但不能生闷气
出门在外要交待
约法四章依然有效
最后谢谢你的勇敢与坚强
谢谢你能来看我
如果可以以后让我来
哪怕等的时间长点也好
熬过异地就结婚吧
最后的最后
祝我家傻梦
永远十八
那年十八美如画

Untitled

Posted on 2017-08-15 | Edited on 2019-09-10
1…456

smniuhe

大家好,我是牛河
56 posts
37 categories
83 tags
GitHub E-Mail
Links
  • 阿里中间件
  • 美团技术团队
  • Mercy Ma
  • CoolShell
  • 当然我在扯淡
  • 周立
  • 芋道源码
  • 程序猿DD
  • 梁桂钊
  • 纯洁的微笑
© 2020 smniuhe
Powered by Hexo v3.8.0
|
Theme – NexT.Muse v7.0.1