Q's blog

一些个人文档笔记

使用log-rotate

nginx命令和信号控制

  1. nginx -s stop 快速关闭,不管有没有正在处理的请求 nginx -s quit 优雅关闭方式,推出前完成已经接受的连接请求
  2. nginx -c nginx配置文件地址 启动
  3. nginx -s reload 重启
  4. nginx -s reopen 重新打开日志
  5. nginx -t 检查配置文件是否正确
  6. kill -INT pid 表示快速关闭
  7. kill -HUP pid表示重启
  8. 通过信号控制的方式实现和命令相同的功能

nginx内置变量

阅读全文 »

为ingress配置增加注解(annotations):nginx.ingress.kubernetes.io/ssl-redirect: ‘true’ 就可以实现http强制跳转至https

不过默认情况ingress是通过308重定向跳转到https, ie浏览器不一定支持308状态, 可以通过如下方式修改ingress配置,让ingress通过301跳转到https

阅读全文 »

YAML中多行字符串的配置方法

有时候我们会在配置文件中配置一段文字说明,这种时候通常会出现两种需求:

  1. 文字中可能出现段落,希望在配置中按段落方式编写,显示打印的时候也能出现段落换行。
  2. 文字很长,为方便编辑,可能在配置文件中分段写,但是显示的时候不喜欢出现配置中的段落换行。

简单的说,就是:

  1. 配置与显示,都严格按段落展示
  2. 配置按段落,显示不需要按段落

假设,我们需要配置这样一段文字:

1
I am a coder.My blog is didispace.com.

下面,就针对上面的两种情况来看看可以怎么来实现:

阅读全文 »

Linux系统下终端proxy代理配置

工作中有时会遇到需要翻墙下载软件的问题,这个时候就用到了正向代理。

变量的设置方法
1、在 /etc/profile文件
2、在 ~/.bashrc
3、在 /etc/profile.d/文件夹下新建一个文件xxx.sh

  • 写入如下配置:
1
2
3
4
5
export proxy="http://10.20.56.32:8000"
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy
export no_proxy="localhost, 127.0.0.1, ::1"
  • 取消设置的方法
1
2
3
4
unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy
1
2
3
4
5
6
7
8
socket_proxy=http://test:password@47.88.222.74:12345
export proxy=http://47.88.222.74:12345/
export socket_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy
export no_proxy="localhost, 127.0.0.1, ::1"
export proxy_username=test
export proxy_password=password

镜像初始化

1
2
3
4
5
6
7
8
cat Dockerfile 
FROM jenkins/jenkins:2.277.1-lts-centos7
USER root
RUN sed -i '/jenkins/d' /etc/passwd
&& sed -i 's#/root#/var/jenkins_home#' /etc/passwd
&& cp -a /root/.bash_profile /var/jenkins_home/
&& cp -a /root/.bashrc /var/jenkins_home/
&& cp -a /root/.cshrc /var/jenkins_home/

修改插件源

由于默认插件源在国外服务器,大多数网络无法顺利下载,需修改国内插件源地址:

1
2
3
cd jenkins_home/updates && \
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && \
sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

yaml

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
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-v1
namespace: devops
spec:
selector:
matchLabels:
app: jenkins-v1
template:
metadata:
labels:
app: jenkins-v1
spec:
terminationGracePeriodSeconds: 10
serviceAccountName: jenkins
containers:
- name: jenkins
image: registry.cn-hangzhou.aliyuncs.com/xqbl-share/jenkins_root:2.235.2-lts-centos7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: web
protocol: TCP
- containerPort: 50000
name: agent
protocol: TCP
volumeMounts:
- mountPath: /var/jenkins_home
name: jenkinshome
- mountPath: /var/run/docker.sock
name: dockersock
- mountPath: /usr/bin/docker
name: dockercmd
- name: kubectl


resources:
{}
env:
- name: JAVA_OPTS
value: -Xmx3048m -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai -Dfile.encoding=utf-8
volumes:
- name: jenkinshome
persistentVolumeClaim:
claimName: jenkinsdatafile
- name: dockersock
hostPath:
path: /var/run/docker.sock
- name: dockercmd
hostPath:
path: /usr/bin/docker
- name: kubectl
hostPath:
path: /usr/bin/kubectl

环境

  • java
  • jdk
  • Gradle

安装jdk

1
2
3
4
5
6
7
8
9
wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
tar -xf android-sdk_r24.4.1-linux.tgz
cd android-sdk-linux/
# 显示所有的sdk版本
./tools/android list sdk --all
# 然后选择想要更新的版本的编号:
./tools/android update sdk -u -a -t <package no.>
# 如:
./tools/android update sdk -u -a -t 1,2,3,4

image-20200718194105751

image-20200718194157735

阅读全文 »

externalTrafficPolicy 简介

如果服务需要将外部流量路由到 本地节点或者集群级别的端点,即service type 为LoadBalancer或NodePort,那么需要指明该参数。存在两种选项:”Cluster”(默认)和 “Local”。 “Cluster” 隐藏源 IP 地址,可能会导致第二跳(second hop)到其他节点,但是全局负载效果较好。”Local” 保留客户端源 IP 地址,避免 LoadBalancer 和 NodePort 类型服务的第二跳,但是可能会导致负载不平衡。

在实际的业务中,诸多业务是需要保留客户端源 IP,所以需要通过将服务的配置文件中的 externalTrafficPolicy 参数设置为 “Local” 来激活这个特性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "example-service",
},
"spec": {
"ports": [{
"port": 8765,
"targetPort": 9376
}],
"selector": {
"app": "example"
},
"type": "LoadBalancer",
"externalTrafficPolicy": "Local"
}
}
阅读全文 »

搭建

服务器

安装OpenLDAP的相关

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
$ yum -y install openldap compat-openldap openldap-clients openldap-servers openldap-servers-sql openldap-devel migrationtools

#ldap用户
$ tail -n 1 /etc/passwd
ldap:x:55:55:LDAP User:/var/lib/ldap:/sbin/nologin

#可以通过rpm -qa |grep openldap查看安装了哪些包:
$ rpm -qa | grep openldap
openldap-servers-2.4.44-22.el7.x86_64
openldap-servers-sql-2.4.44-22.el7.x86_64
compat-openldap-2.3.43-5.el7.x86_64
openldap-2.4.44-22.el7.x86_64
openldap-devel-2.4.44-22.el7.x86_64
openldap-clients-2.4.44-22.el7.x86_64

#查看OpenLDAP版本,使用:slapd -VV
$ slapd -VV
@(#) $OpenLDAP: slapd 2.4.44 (Sep 30 2020 17:16:39) $
mockbuild@x86-02.bsys.centos.org:/builddir/build/BUILD/openldap-2.4.44/openldap-2.4.44/servers/slapd

#penLDAP的相关配置文件信息
/etc/openldap/slapd.conf # OpenLDAP的主配置文件,记录根域信息,管理员名称,密码,日志,权限等
/etc/openldap/slapd.d/* # 这下面是slapd.conf配置信息生成的文件,每修改一次配置信息,这里的东西就要重新生成
/etc/openldap/schema/* # OpenLDAP的schema存放的地方
/var/lib/ldap/* # OpenLDAP的数据文件
/usr/share/openldap-servers/slapd.conf.obsolete # 模板配置文件
/usr/share/openldap-servers/DB_CONFIG.example # 模板数据库配置文件

#penLDAP监听的端口:
默认监听端口:389(明文数据传输)
加密监听端口:636(密文数据传输)

#初始化OpenLDAP的配置
chown ldap:ldap /var/lib/ldap/DB_CONFIG

#改配置文件
OpenLDAP 2.3之后的版本取消了/etc/openldap/slapd.conf的配置方式,使用ldif文件动态配置,目前网上的文档五花八门而且缺胳膊少腿,以下参考官方文档及slapd-config(5)
http://www.openldap.org/doc/admin24/slapdconf2.html
http://www.openldap.org/doc/admin24/quickstart.html
$ slappasswd -s 123456
{SSHA}cQb7UUcz2x6p6rB1gm9EmsVcM8Rrfp6h
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
#将所需模块注释去掉,olcSuffix和olcRootDN按照实际情况修改,如不需要TLS,将相应内容注释
#vim /usr/share/openldap-servers/slapd.ldif

#
# See slapd-config(5) for details on configuration options.
# This file should NOT be world readable.
#

dn: cn=config
objectClass: olcGlobal
cn: config
olcArgsFile: /var/run/openldap/slapd.args
olcPidFile: /var/run/openldap/slapd.pid
#
# TLS settings
#
#olcTLSCACertificatePath: /etc/openldap/certs
#olcTLSCertificateFile: "OpenLDAP Server"
#olcTLSCertificateKeyFile: /etc/openldap/certs/password
#
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#
#olcReferral: ldap://root.openldap.org
#
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 64-bit encryption for simple bind
#
#olcSecurity: ssf=1 update_ssf=112 simple_bind=64


#
# Load dynamic backend modules:
# - modulepath is architecture dependent value (32/64-bit system)
# - back_sql.la backend requires openldap-servers-sql package
# - dyngroup.la and dynlist.la cannot be used at the same time
#

dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
# olcModulepath: /usr/lib/openldap
olcModulepath: /usr/lib64/openldap
olcModuleload: accesslog.la
olcModuleload: auditlog.la
olcModuleload: back_dnssrv.la
olcModuleload: back_ldap.la
olcModuleload: back_mdb.la
olcModuleload: back_meta.la
olcModuleload: back_null.la
olcModuleload: back_passwd.la
olcModuleload: back_relay.la
olcModuleload: back_shell.la
olcModuleload: back_sock.la
olcModuleload: collect.la
olcModuleload: constraint.la
olcModuleload: dds.la
olcModuleload: deref.la
# olcModuleload: dyngroup.la
olcModuleload: dynlist.la
olcModuleload: memberof.la
olcModuleload: pcache.la
olcModuleload: ppolicy.la
olcModuleload: refint.la
olcModuleload: retcode.la
olcModuleload: rwm.la
olcModuleload: seqmod.la
olcModuleload: smbk5pwd.la
olcModuleload: sssvlv.la
olcModuleload: syncprov.la
olcModuleload: translucent.la
olcModuleload: unique.la
olcModuleload: valsort.la


#
# Schema settings
#

dn: cn=schema,cn=config
objectClass: olcSchemaConfig
cn: schema

include: file:///etc/openldap/schema/core.ldif

#
# Frontend settings
#

dn: olcDatabase=frontend,cn=config
objectClass: olcDatabaseConfig
objectClass: olcFrontendConfig
olcDatabase: frontend
#
# Sample global access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
#
#olcAccess: to dn.base="" by * read
#olcAccess: to dn.base="cn=Subschema" by * read
#olcAccess: to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!
#

#
# Configuration database
#

dn: olcDatabase=config,cn=config
objectClass: olcDatabaseConfig
olcDatabase: config
olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c
n=auth" manage by * none

#
# Server status monitoring
#

dn: olcDatabase=monitor,cn=config
objectClass: olcDatabaseConfig
olcDatabase: monitor
olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c
n=auth" read by dn.base="cn=root,dc=quhui,dc=com" read by * none #修改cn,dc

#
# Backend database definitions
#

dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: hdb
olcSuffix: dc=quhui,dc=com #修改dc
olcRootDN: cn=root,dc=quhui,dc=com #修改cn,dc
olcRootPW: {SSHA}cQb7UUcz2x6p6rB1gm9EmsVcM8Rrfp6h #初始化便更新密码,初始化后手动修改配置会报错,但没事
olcDbDirectory: /var/lib/ldap
olcDbIndex: objectClass eq,pres
olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub

导入DB_CONFIG、重新生成配置、修改目录权限并启动服务

1
2
3
4
5
6
7
8
9
10
rm -rf /etc/openldap/slapd.d/* #删除旧配置
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG     # copy数据库文件
slapadd -n 0 -F /etc/openldap/slapd.d -l /usr/share/openldap-servers/slapd.ldif #导入配置
#修改目录权限
chown -R ldap.ldap /etc/openldap/slapd.d/*
chown -R ldap.ldap /var/lib/ldap/*
#导入schema
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif

启动

1
systemctl restart slapd

执行ldapsearch -x检查是否有如下输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ ldapsearch -x -b '' -s base'(objectclass=*)'
# extended LDIF
#
# LDAPv3
# base <> with scope baseObject
# filter: (objectclass=*)
# requesting: ALL
#

#
dn:
objectClass: top
objectClass: OpenLDAProotDSE

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
$ ldapsearch -x -b "cn=root,dc=quhui,dc=com"

验证用户密码

1
2
3
4
5
$ ldapwhoami -D "cn=root,dc=quhui,dc=com" -W -H ldap://127.0.0.1 -v
ldap_initialize( ldap://127.0.0.1:389/??base )
Enter LDAP Password:
dn:cn=root,dc=quhui,dc=com
Result: Success (0)

docker

server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
docker run -d --restart always \
-p 389:389 -p 636:636 \
--name ldap-server \
--env LDAP_TLS=false \
--env LDAP_ORGANISATION="flashwhale" \
--env LDAP_DOMAIN="flashwhale.com" \
--env LDAP_ADMIN_PASSWORD="djadmin" \
--env LDAP_CONFIG_PASSWORD="djadmin" \
-v /data/ldap/ldap:/var/lib/ldap \
-v /data/ldap/slapd.d:/etc/ldap/slapd.d \
osixia/openldap:1.4.0

#默认配置(不加变量)
dn dc=example,dc=org
admin admin,dc=example,dc=org
password admin
阅读全文 »
0%