#python统计分析json格式的访问日志
[root@localhost ~]#yum -y install python
[root@localhost ~]#vim log.py
#!/usr/bin/env python3
#coding:utf-8
status_200= []
status_404= []
with open("/apps/nginx/logs/access_json.log") as f:
for line in f.readlines():
line = eval(line)
if line.get("status") == "200":
status_200.append(line.get)
elif line.get("status") == "404":
status_404.append(line.get)
else:
print("状态码 ERROR")
print((line.get("clientip")))
f.close()
print("状态码200的有--:",len(status_200))
print("状态码404的有--:",len(status_404))
[root@localhost ~]#python3 log.py
状态码200的有--: 1
状态码404的有--: 0
自签证书,应用https
#自签证书实现https
[root@localhost certs]#openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 3650 -out ca.crt
Generating a RSA private key
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................++++
...................................................++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:shuhong.Ltd
Organizational Unit Name (eg, section) []:SHUHONG
Common Name (eg, your name or your server's hostname) []:ca.shuhong.com
Email Address []:
[root@localhost certs]#openssl req -newkey rsa:4096 -nodes -sha256 -keyout www.shuhong.com.key -out www.shuhong.com.csr
Generating a RSA private key
..........................................................................................................................++++
..........................................................................................................................................++++
writing new private key to 'www.shuhong.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:shuhong.com
Organizational Unit Name (eg, section) []:shuhong.com
Common Name (eg, your name or your server's hostname) []:www.shuhong.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@localhost certs]#openssl x509 -req -days 3650 -in www.shuhong.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out www.shuhong.com.crt
Signature ok
subject=C = CN, ST = BeiJing, L = BeiJing, O = shuhong.com, OU = shuhong.com, CN = www.shuhong.com
Getting CA Private Key
[root@localhost certs]#openssl x509 -in www.shuhong.com.crt -noout -text
Certificate:
Data:
Version: 1 (0x0)
Serial Number:
11:74:69:da:d7:39:68:52:b3:48:21:d6:bd:88:a7:11:b6:77:b5:38
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = CN, ST = BeiJing, L = BeiJing, O = shuhong.Ltd, OU = SHUHONG, CN = ca.shuhong.com
Validity
Not Before: Sep 15 02:42:15 2022 GMT
Not After : Sep 12 02:42:15 2032 GMT
Subject: C = CN, ST = BeiJing, L = BeiJing, O = shuhong.com, OU = shuhong.com, CN = www.shuhong.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (4096 bit)
......
#nginx需要两个文件合并一起
[root@localhost certs]#cat www.shuhong.com.crt ca.crt > www.shuhong.com.pem