linux自建證書全流程分享
前言:本文記錄一下在項(xiàng)目開發(fā)過程中,minio配置https證書的過程
1.生成私鑰:(minio是自定義的名字)
openssl genrsa -des3 -out minio.key 2048 輸入完這個(gè)命令會(huì)讓輸入兩次密碼,密碼自定義就可以,兩次輸入需要一致

2.消除私鑰key的密碼
就是把上面那個(gè)文件的密碼消除掉
openssl rsa -in minio.key -out minio.key 輸入完命令讓輸入密碼確認(rèn),這里輸入第一步的密碼

3.生成pem文件(這里的minio.key,是上面創(chuàng)建的文件)
openssl req -utf8 -x509 -new -nodes -key minio.key -sha256 -days 825 -out minio.pem 輸入完命令會(huì)讓輸入以下幾個(gè)信息: Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []:

4.創(chuàng)建CA簽名證書
生成私鑰(server.key自定義名稱)
openssl genrsa -out minio_server.key 2048
5.創(chuàng)建證書簽名請(qǐng)求(server.key這個(gè)是第四步創(chuàng)建的文件)
openssl req -new -key minio_server.key -out minio_server.csr 輸入完命令會(huì)讓輸入以下幾個(gè)信息: Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:

6.創(chuàng)建一個(gè)配置文件
vim minio_server.ext
authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = xx.xx.xxx.xxx IP.1 = xx.xx.xxx.xxx
7.創(chuàng)建簽名證書
openssl x509 -req -in minio_server.csr -CA minio.pem -CAkey minio.key -CAcreateserial -out minio_server.crt -days 3650 -sha256 -extfile minio_server.ext

8.得到所需證書文件
minio_server.crt
9.將上面生成的minio_server.key重命名為private.key
將上一步生成的minio_server.crt重命名為public.crt

10.配置證書
minio啟動(dòng)命令,將上面重命名后的private.key和public.crt放到/minio/config這個(gè)目錄下 sudo docker run -p 9000:9000 -p 9001:9001 -d --name minio -v /minio/data:/data -v /minio/config:/root/.minio/certs -e "MINIO_ROOT_USER=admin" -e "MINIO_ROOT_PASSWORD=Minio@2024#qwe" minio/minio server /data --console-address ":9001"
最后:配置完https證書后,本地開發(fā)使用minio會(huì)報(bào)錯(cuò),是因?yàn)樽C書不受信任的原因
解決方法:
1.配置證書到自己本地庫(kù):
cmd進(jìn)本地jre的/lib/security/下
執(zhí)行命令:
keytool -import -alias public -keystore cacerts -file D://public.crt(自己的路徑,文件為上面生成的證書文件)
密鑰口令輸入:changeit
是否信任此證書:Y
以上添加完之后可解決本地上傳圖片報(bào)錯(cuò)的問題
2.繞過https證書驗(yàn)證:
public OssClient(String configKey, OssProperties ossProperties) {
this.configKey = configKey;
this.properties = ossProperties;
try {
AwsClientBuilder.EndpointConfiguration endpointConfig =
new AwsClientBuilder.EndpointConfiguration(properties.getEndpoint(), properties.getRegion());
AWSCredentials credentials = new BasicAWSCredentials(properties.getAccessKey(), properties.getSecretKey());
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
ClientConfiguration clientConfig = new ClientConfiguration();
if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
clientConfig.setProtocol(Protocol.HTTPS);
// 繞過https證書驗(yàn)證
TrustStrategy trustStrategy =(X509Certificate[] chain, String authType) ->true;
SSLContext sslContext =new SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
SSLConnectionSocketFactory sslsf =new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1.2"}, null, NoopHostnameVerifier.INSTANCE);
clientConfig.getApacheHttpClientConfig().setSslSocketFactory(sslsf);
} else {
clientConfig.setProtocol(Protocol.HTTP);
}
AmazonS3ClientBuilder build = AmazonS3Client.builder()
.withEndpointConfiguration(endpointConfig)
.withClientConfiguration(clientConfig)
.withCredentials(credentialsProvider)
.disableChunkedEncoding();
if (!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)) {
// minio 使用https限制使用域名訪問 需要此配置 站點(diǎn)填域名
build.enablePathStyleAccess();
}
this.client = build.build();
createBucket();
} catch (Exception e) {
if (e instanceof OssException) {
throw e;
}
throw new OssException("配置錯(cuò)誤! 請(qǐng)檢查系統(tǒng)配置");
}
}
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
apache與iis下讓html格式的頁(yè)面也同樣具有shtml的動(dòng)態(tài)解析
apache下讓html格式的頁(yè)面也同樣具有shtml的動(dòng)態(tài)解析,方便有此需要的朋友。2011-03-03
詳解Linux動(dòng)態(tài)庫(kù)生成與使用指南
這篇文章主要介紹了詳解Linux動(dòng)態(tài)庫(kù)生成與使用指南,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
Linux部署python爬蟲腳本,并設(shè)置定時(shí)任務(wù)的方法
今天小編就為大家分享一篇Linux部署python爬蟲腳本,并設(shè)置定時(shí)任務(wù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-06-06
ubuntu20.04不顯示wifi圖標(biāo)的問題及解決
文章主要介紹了在Ubuntu 20.04系統(tǒng)中安裝WiFi網(wǎng)卡驅(qū)動(dòng)的方法,包括通過軟件和更新、更換軟件源、激活BCM無(wú)線網(wǎng)卡等步驟2026-03-03

