-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update site at 20240118-084021, machine LiaoSirui-MBP.local
- Loading branch information
Showing
45 changed files
with
1,093 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,23 @@ helm repo add jumpserver https://jumpserver.github.io/helm-charts | |
|
||
官方文件:<https://docs.jumpserver.org/zh/master/admin-guide/authentication/openid/> | ||
|
||
### 新建超管用户 | ||
## PAM | ||
|
||
管理密码忘记了或者重置管理员密码 | ||
|
||
```bash | ||
source /opt/py3/bin/activate | ||
cd /opt/jumpserver/apps | ||
|
||
python manage.py changepassword <user_name> | ||
``` | ||
|
||
新建超级用户的命令如下命令 | ||
|
||
```bash | ||
source /opt/py3/bin/activate | ||
cd /opt/jumpserver/apps | ||
|
||
python manage.py createsuperuser --username=user [email protected] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
## fail2ban 简介 | ||
|
||
官方: | ||
|
||
- GitHub 仓库:<https://github.com/fail2ban/fail2ban> | ||
|
||
## fail2ban 自定义过滤器 | ||
|
||
- fail2ban自带了很多常见服务的过滤器,但是jumpserver不在其中,于是乎自己弄一个吧 | ||
- fai2ban支持基于正则表达式的过滤,因此可以先用正则表达式匹配一下登录失败的日志 | ||
|
||
``` | ||
fail2ban-regex /opt/koko/data/logs/koko.log 'Failed password for [A-Za-z0-9]+ from <HOST>' | ||
``` | ||
|
||
- 命令运行之后会显示结果 | ||
- `Failregex: 8234 total`代表有8234条记录被匹配 | ||
- `Date template hits`指该日志中有满足格式的日期 | ||
|
||
``` | ||
Running tests | ||
============= | ||
Use failregex line : Failed password for [A-Za-z0-9]+ from <HOST> | ||
Use log file : /opt/koko/data/logs/koko.log | ||
Use encoding : UTF-8 | ||
Results | ||
======= | ||
Failregex: 8234 total | ||
|- #) [# of hits] regular expression | ||
| 1) [8234] Failed password for [A-Za-z0-9]+ from <HOST> | ||
`- | ||
Ignoreregex: 0 total | ||
Date template hits: | ||
|- [# of hits] date format | ||
| [27451] {^LN-BEG}ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)? | ||
`- | ||
Lines: 27451 lines, 0 ignored, 8234 matched, 19217 missed | ||
[processed in 1.62 sec] | ||
Missed line(s): too many to print. Use --print-all-missed to print all 19217 lines | ||
``` | ||
|
||
- 既然正则匹配已经ok了,那么就可以配置自定义过滤器了 | ||
|
||
``` | ||
vi /etc/fail2ban/filter.d/jms-koko.conf | ||
``` | ||
|
||
- 添加如下内容 | ||
|
||
``` | ||
[Definition] | ||
failregex = Failed password for [A-Za-z0-9]+ from <HOST> | ||
ignoreregex = | ||
``` | ||
|
||
## 配置fail2ban服务 | ||
|
||
### 添加fail2ban配置 | ||
|
||
``` | ||
vim /etc/fail2ban/jail.local | ||
[DEFAULT] | ||
# 默认禁止IP地址15天,单位是秒: | ||
bantime = 1296000 | ||
# ban的动作使用iptables-multiport | ||
banaction = iptables-multiport | ||
# 忽略IP,注意加上自己的IP,不然被误封就麻烦了 | ||
ignoreip = 127.0.0.1/8 192.168.0.0/24 | ||
[jms-koko] | ||
# 直接所有协议drop包,覆盖上面的banaction | ||
action = iptables-allports[protocol=all,blocktype=DROP] | ||
enabled = true | ||
# filter指定刚才配置的自定义过滤器 | ||
filter = jms-koko | ||
# koko端口默认是2222 | ||
port = 2222 | ||
# koko的日志路径,请修改成自己的路径地址 | ||
logpath = /opt/koko/data/logs/koko.log | ||
# 最大重试次数 | ||
maxretry = 5 | ||
# 禁止12小时,这里会覆盖上面default定义的bantime | ||
bantime = 43200 | ||
``` | ||
|
||
### 检查配置 | ||
|
||
``` | ||
fail2ban-client -t | ||
``` | ||
|
||
- 输出示例 | ||
|
||
``` | ||
OK: configuration test is successful | ||
``` | ||
|
||
- 可以通过加`-v`或者`-d`输出详细日志 | ||
|
||
``` | ||
fail2ban-client -t -v | ||
fail2ban-client -t -d | ||
``` | ||
|
||
### 启动fail2ban | ||
|
||
``` | ||
systemctl enable --now fail2ban.service | ||
``` | ||
|
||
### 查看fail2ban的状态 | ||
|
||
``` | ||
fail2ban-client status jms-koko | ||
``` | ||
|
||
- 根据输出结果可以看到`172.105.86.202`已经被ban了 | ||
|
||
``` | ||
Status for the jail: jms-koko | ||
|- Filter | ||
| |- Currently failed: 1 | ||
| |- Total failed: 24 | ||
| `- File list: /opt/koko/data/logs/koko.log | ||
`- Actions | ||
|- Currently banned: 1 | ||
|- Total banned: 1 | ||
`- Banned IP list: 172.105.86.202 | ||
``` | ||
|
||
### 查看fail2ban日志 | ||
|
||
- /var/log/fail2ban.log | ||
|
||
``` | ||
2020-08-30 20:25:33,924 fail2ban.server [1346]: INFO -------------------------------------------------- | ||
2020-08-30 20:25:33,924 fail2ban.server [1346]: INFO Starting Fail2ban v0.11.1 | ||
2020-08-30 20:25:33,924 fail2ban.observer [1346]: INFO Observer start... | ||
2020-08-30 20:25:33,931 fail2ban.database [1346]: INFO Connected to fail2ban persistent database '/var/lib/fail2ban/fail2ban.sqlite3' | ||
2020-08-30 20:25:33,933 fail2ban.database [1346]: WARNING New database created. Version '4' | ||
2020-08-30 20:25:33,975 fail2ban.filter [1346]: INFO maxRetry: 5 | ||
2020-08-30 20:25:33,975 fail2ban.filter [1346]: INFO encoding: UTF-8 | ||
2020-08-30 20:25:33,976 fail2ban.filter [1346]: INFO findtime: 600 | ||
2020-08-30 20:25:33,976 fail2ban.actions [1346]: INFO banTime: 1296000 | ||
2020-08-30 20:25:33,976 fail2ban.jail [1346]: INFO Creating new jail 'jms-koko' | ||
2020-08-30 20:25:33,977 fail2ban.jail [1346]: INFO Jail 'jms-koko' uses poller {} | ||
2020-08-30 20:25:33,978 fail2ban.jail [1346]: INFO Initiated 'polling' backend | ||
2020-08-30 20:25:33,979 fail2ban.filter [1346]: INFO maxRetry: 5 | ||
2020-08-30 20:25:33,980 fail2ban.filter [1346]: INFO encoding: UTF-8 | ||
2020-08-30 20:25:33,980 fail2ban.filter [1346]: INFO findtime: 600 | ||
2020-08-30 20:25:33,980 fail2ban.actions [1346]: INFO banTime: 43200 | ||
2020-08-30 20:25:33,980 fail2ban.filter [1346]: INFO Added logfile: '/opt/koko/data/logs/koko.log' (pos = 0, hash = f52047cfc39a7880f2301858f7172d30) | ||
2020-08-30 20:25:33,987 fail2ban.jail [1346]: INFO Jail 'jms-koko' started | ||
2020-08-30 22:32:23,861 fail2ban.filter [1346]: INFO [jms-koko] Found 172.105.86.202 - 2020-08-30 22:32:23 | ||
2020-08-30 22:33:17,912 fail2ban.filter [1346]: INFO [jms-koko] Found 172.105.86.202 - 2020-08-30 22:33:17 | ||
2020-08-30 22:34:05,961 fail2ban.filter [1346]: INFO [jms-koko] Found 172.105.86.202 - 2020-08-30 22:34:05 | ||
2020-08-30 22:34:58,023 fail2ban.filter [1346]: INFO [jms-koko] Found 172.105.86.202 - 2020-08-30 22:34:57 | ||
2020-08-30 22:35:49,282 fail2ban.filter [1346]: INFO [jms-koko] Found 172.105.86.202 - 2020-08-30 22:35:49 | ||
2020-08-30 22:35:49,374 fail2ban.actions [1346]: NOTICE [jms-koko] Ban 172.105.86.202 | ||
.... | ||
``` | ||
|
||
### 查看防火墙规则 | ||
|
||
``` | ||
iptables -t filter -L -n -v | ||
``` | ||
|
||
- 输出如下 | ||
- 被ban的ip会提示端口不可达 | ||
|
||
``` | ||
Chain INPUT (policy ACCEPT 779K packets, 71M bytes) | ||
pkts bytes target prot opt in out source destination | ||
8516 498K f2b-jms-koko tcp -- * * 0.0.0.0/0 0.0.0.0/0 multiport dports 2222 | ||
<此处忽略很多行> | ||
Chain f2b-jms-koko (1 references) | ||
pkts bytes target prot opt in out source destination | ||
30 1800 REJECT all -- * * 172.105.86.202 0.0.0.0/0 reject-with icmp-port-unreachable | ||
8461 495K RETURN all -- * * 0.0.0.0/0 0.0.0.0/0 | ||
``` | ||
|
||
## 解封操作 | ||
|
||
- 说不准有时候会有倒霉蛋输错密码导致IP被ban,可以通过用`fail2ban-client`命令解封IP地址 | ||
- JumpServer账号锁定的话要在JumpServer里面解锁账号 | ||
|
||
``` | ||
fail2ban-client set jms-koko unbanip IP地址 | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
## 为什么要复权 | ||
|
||
当公司进行分红、配股、拆股、回购等操作时,公司的股本结构会发生变化,这将直接影响其股票的交易价格。股票的复权是指对股票的历史交易数据进行调整,以反映公司的所有股本变动(如股息派发、配股、拆股和回购等)对股价的影响 | ||
|
||
假设某个股东持有该公司股票 100 股,在每 10 股转增 10 股后,原来的 100 股就会变成 200 股,但以公积金转增实际并不增加公司的总市值,因此假如原来每股价值 13 元,100 股总价值 1300 元,在除权后每股价值会变为 6.5 元,200 股价值 1300 元,转增后持有的股票数量增加 1 倍,但单张股票的价值变为原来的 1/2,持有的股票总价值不变 | ||
|
||
分红也会造成股票价格下降,因为分红后公司的总资产减少,市值也应当相应减少 | ||
|
||
从上面这个例子可以看到,由于股票存在分红、配股、拆股、回购等事件,会导致股价出现较大的缺口,如果不进行复权处理,直接使用这些历史价格进行分析,可能会得到错误的结论。为了保证数据连贯性,需要使用复权的方法对价格序列进行调整 | ||
|
||
## 复权的方法及各自的优缺点 | ||
|
||
### 前复权 | ||
|
||
前复权是以最新的价格变动为基准,将所有历史数据按照这个基准进行调整 | ||
|
||
前复权的优点是最新复权价格与实际价格一致,因此很直观,也是各种行情软件默认的复权方式 | ||
|
||
但前复权也有缺点: | ||
|
||
- 由于前复权的方式在每次除权除息后,都需要根据最新的价格重新计算所有的历史数据,这会导致每次发生除权除息事件后,历史数值都会发生变化。由于需要反复调整历史数据,数据更新和维护的成本较高 | ||
|
||
- 对于有持续分红的公司来说,前复权价可能出现负值 | ||
|
||
- 前复权价格如果处理不当有使用未来数据的风险 | ||
|
||
### 后复权 | ||
|
||
后复权是以某一固定日期(通常为股票上市日期)的价格为基准,将此后的所有数据进行调整 | ||
|
||
后复权的优点是计算简单,一旦计算完成,后续的数据更新也方便,以前的后复权价格不会因为后面的除权除息事件而发生变动 | ||
|
||
但后复权价格和真实股票价格可能差别较大,尤其不适用于实盘 | ||
|
||
### 复权算法 | ||
|
||
需要注意的是,复权的算法有很多种,包括:经典算法、递归后复权法、递归前复权法、涨跌幅复权法等等,不同平台、不同数据源由于复权算法不同,导致复权数据存在差异,而且除权次数越多,差异越明显 | ||
|
||
## 如何计算复权 | ||
|
||
复权价格的计算公式为: | ||
|
||
后复权价格 = 当日不复权价格 × 当日复权因子 | ||
|
||
前复权价格 = 当日不复权价格 × 当日复权因子 / 最新复权因子 | ||
|
||
示例代码: | ||
|
||
```python | ||
# 导入需要的库 | ||
import pandas as pd | ||
import tushare as ts | ||
|
||
# 初始化数据接口并设置token,token在个人主页获取 | ||
# 注意:下面语句中的token要更换为你个人的token字符串 | ||
pro = ts.pro_api(token) | ||
|
||
# 获取平安银行(000001)不复权的行情数据,数据的时间范围从2023年6月12日至2023年6月20日 | ||
price_df = pro.daily(ts_code='000001.SZ', start_date='20230612', end_date='20230620').set_index('trade_date') | ||
|
||
# 获取平安银行(000001)的复权因子 | ||
adj_factor_df = pro.adj_factor(ts_code='000001.SZ', trade_date='').set_index('trade_date') | ||
|
||
# 将不复权的收盘价和复权因子放在一个DataFrame数据表中 | ||
df = pd.DataFrame() | ||
df['收盘价_不复权'] = price_df['close'] | ||
df['复权因子'] = adj_factor_df['adj_factor'] | ||
|
||
# 计算复权后的收盘价 | ||
df['收盘价_后复权'] = df['收盘价_不复权'] * df['复权因子'] | ||
df['收盘价_前复权'] = df['收盘价_不复权'] * df['复权因子'] / df['复权因子'].iloc[-1] | ||
``` | ||
|
||
## 在量化投资中使用哪种复权数据 | ||
|
||
在量化投资中应根据具体情况来选择复权数据: | ||
|
||
1. 进行数据存储和更新时 | ||
|
||
当需要采集和存储行情数据时,应该用前复权价格、后复权价格还是不复权价格? | ||
|
||
用前复权价格并不是一个好的方案,因为每次发生除权除息事件后否需要重新计算历史的前复权价格,数据更新和维护很麻烦 | ||
|
||
用后复权价格虽然没有重新计算历史数据的问题,但后复权价格跟实际价格往往相差巨大,也不是一个好选择 | ||
|
||
比较好的方案是存储不复权的价格,并同时存储复权因子,这样数据更新时不用修改历史数据,而且通过复权因子可以很方便的计算出前复权价格和后复权价格 | ||
|
||
2. 进行数据分析和策略回测时 | ||
|
||
在进行数据分析和策略回测时,通常使用后复权价格,这是因为: | ||
|
||
1)当回溯的时间很长时,前复权价格可能会出现负值的情况 | ||
|
||
2)如果需要对结果数据进行存储和定期更新,比如有一个需要定期更新的因子库,那么采用后复权价格更易于维护,因为前复权价格在发生除权除息时要重新计算所有历史数据,相应的因子值也要重新计算,更新和维护因子库的成本高 | ||
|
||
3)前复权价格处理不当有使用未来数据的风险 | ||
|
||
3. 在实盘时 | ||
|
||
实盘中进行数据运算时应该使用前复权价格,因为后复权价格可能跟实际价格相差巨大,不适合实盘操作 |
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.