post { success { emailext ( subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] 更新正常", body: """ 內容: SUCCESSFUL: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] 狀態:${env.JOB_NAME} jenkins 更新執行正常 URL :${env.BUILD_URL} 項目 :${env.JOB_NAME} 項目更新进度:${env.BUILD_NUMBER} """, to: USER_MAIL, recipientProviders: [[$class: 'DevelopersRecipientProvider']] ) } failure { emailext ( subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] 更新失敗", body: """ 內容: FAILED: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] 狀態:${env.JOB_NAME} jenkins 執行失敗 URL :${env.BUILD_URL} 項目 :${env.JOB_NAME} 項目更新進度:${env.BUILD_NUMBER} ERROR_CODE: ${ERROR_CODE} """, to: USER_MAIL, recipientProviders: [[$class: 'DevelopersRecipientProvider']] ) } }
Where Josh!!
不懂就看書,再不懂google幫幫忙,還是不懂吃吃飯睡睡覺,明天繼續。
SHOWcode
2021年1月6日 星期三
Jenkins-mail
2020年12月29日 星期二
Kubeadm
Install Kubernetes Cluster using kubeadm
*Verify the MAC address and product_uuid are unique for every node
3個ubuntu 環境都是分別裝起來 避免 kubeadm 不必要的衝突
環境:
Oracle VM VirtualBox 6.1
master-ubuntu-desktop 20.04 LTS版
node01-ubuntu-desktop 20.04 LTS版
node02-ubuntu-desktop 20.04 LTS版
Role | IP(根據分到的IP) | OS | RAM | CPU |
---|---|---|---|---|
Master | 192.168.11.136 | Ubuntu 20.04 | 2G | 2 |
node01 | 192.168.11.138 | Ubuntu 20.04 | 2G | 2 |
node02 | 192.168.11.139 | Ubuntu 20.04 | 2G | 2 |
工具版本
docker-ce=5:19.03.10~3-0~ubuntu-focal //apt-cache madison docker-ce 會查到其他版本資訊
kubeadm=1.18.5-00
kubelet=1.18.5-00
kubectl=1.18.5-00
Oracle VM VirtualBox 6.1 主要設定:
網路 介面卡
附加到: 橋接介面卡(模擬真實主機狀態)
*使用root 權限
$ sudo -i
1.關掉防火牆(ufw disable)
$ ufw disable
2.關閉虛擬記憶體(Disable swap)
$ swapoff -a
$ sed -i '/swap/d' /etc/fstab
3.更新 Kubernetes network 系統設定
cat >>/etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
4.安裝 Docker engine (Install docker engine)
$ apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
$ add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ apt update
$ apt install -y docker-ce=5:19.03.10~3-0~ubuntu-focal containerd.io
Kubernetes Setup
5.Add Apt repository
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
$ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
6.Install Kubernetes components
$ apt update && apt install -y kubeadm=1.18.5-00 kubelet=1.18.5-00 kubectl=1.18.5-00
$ apt-mark hold kubelet kubeadm kubectl
**以上是所有機器需要做的事情
On Master-(只有Master 主機需要安裝)
Initialize Kubernetes Cluster
1.Update the below command with the ip address of master
$ sudo kubeadm init --apiserver-advertise-address=192.168.11.136 --pod-network-cidr=192.168.0.0/16 --ignore-preflight-errors=all
CNI Plugin: (主要基本功能提供 Pod x Pod 連線 )
Calico CNI (Container Network Interface):192.168.0.0/16 (本次使用)
Calico=>除了基本功能,還有提供其他功能
Flannel CNI:10.244.0.0/16
2.Deploy Calico network
$ sudo kubectl --kubeconfig=/etc/kubernetes/admin.conf create -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
3.Cluster join command -如果忘記紀錄 Join master 指令 可以輸入這段找回
$ sudo kubeadm token create --print-join-command
4. To be able to run kubectl commands as non-root user
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
NODE-(其他節點加入Master)
將節點加入 Master
指令是 Master 產生 貼在ubuntu-NODE 執行
$ kubeadm join 192.168.11.136:6443 --token aujovi.2ewddfc9ypkqfbp0 --discovery-token-ca-cert-hash sha256:d70c148ac96428574fa146ccf90bf8a3fdb806fdba4bc3766509065f3645b57a
如果沒記錄到在ubuntu-Master 輸入以下指令找回:
$ sudo kubeadm token create --print-join-command
完成圖:
測試:
kubeadm 預設Master是不執行Pod工作,如果需要可以下指令一起分安工作
//所有主伺服器都安排 pod
$ kubectl taint nodes --all node-role.kubernetes.io/master-
//指定節點 master 伺服器都安排 pod
$ kubectl taint nodes <master-hostname> node-role.kubernetes.io/master-
ex:kubectl taint nodes master node-role.kubernetes.io/master-
deployment-test:
kubectl create deployment nginx --image=nginx:1.7.9
如圖:
Master-
node01-docker 會看到 deploument 的 nginx
其他設定:
將 node01 & node02 ROLES 標記 worker
$ kubectl label node <node_name> node-role.kubernetes.io/worker=worker
node/<node_name> labeled
EX:
$ kubectl label node node01 node-role.kubernetes.io/worker=worker
node/node01 labeled
$ kubectl label node node02 node-role.kubernetes.io/worker=worker
node/node02 labeled
如果 worker節點加入 master 時配置有問題可以在 worker節點上使用 kubeadm reset 重置配置再使用 kubeadm join 命令重新加入即可。
$ kubeadm reset
希望在 master 節點刪除 node ,可以使用 kubeadm delete nodes 刪除。
$ kubeadm delete nodes
2020年9月30日 星期三
Google cloud port 無法連線
2020年5月19日 星期二
C#.NET datatable distinct
在C# 將 DataTable 裡的資料進行 Distinct
DataTable Dt_data = NEW DataTable(); Dt_data = mySource.DefaultView.ToTable(true, new string[]{ "欄位" });
2020年4月1日 星期三
C# 檔案操作法
C# 檔案操作方法
Directory.Exists(FILENAME); //是否有檔案 Directory.Delete(FILENAME); //刪除檔案 Directory.CreateDirectory(FILENAME); //創建檔案 System.IO.File.Move(FILENAME, FILENAME); //移動檔案
文字檔.txt String.Split(';') 轉陣列
文字檔.txt String.Split(';') 轉陣列
string_str.txt = aaa;bbb;ccc;ddd
try{ System.IO.StreamReader sr = new System.IO.StreamReader("string_str.txt"); string[] connect_string = sr.ReadToEnd().Split(';'); string01 = connect_string[0].ToString(); string02= connect_string[1].ToString(); string03= connect_string[2].ToString(); string04= connect_string[3].ToString(); sr.Close(); }catch { MessageBox.Show("Error"); }
C# DataRow[] TO String
#region 輸入的VALUES string str_values = ""; DataTable data_pigname = survive_data.DefaultView.ToTable(true, new string[] { "類別" }); for (int i = 0; i < data_pigname.Rows.Count; i++){ string str_mydata = ""; str_values += " { name: '" + data_pigname.Rows[i][0] + "', data: ["; for (int j = 1; j <= 12; j++){ string str_my = ddl_time.SelectedItem.Text.Trim() + "/" + j.ToString().PadLeft(2, '0'); //.PadLeft(補0) DataRow[] data_pignow = survive_data.Select("年月 = '" + str_my + "'and 類別 = '" + data_pigname.Rows[i][0] + "'"); if (data_pignow.Length != 0){ str_mydata += data_pignow[0]["本月結存數"].ToString() + ","; }else{ str_mydata += "0,"; } } str_values += str_mydata.Substring(0, str_mydata.Length - 1) + "] },"; } survive_actual = str_values.Substring(0, str_values.Length - 1); #endregion
MySQL獲取所有分類和每個分類的前N條記錄
原址:https://www.itread01.com/p/1133452.html
SELECT A1.*
FROM tb_sensor_values AS A1
INNER JOIN (
SELECT A.m_no,A.d_time
FROM tb_sensor_values AS A
LEFT JOIN tb_sensor_values AS B
ON A.m_no = B.m_no
AND A.d_time <= B.d_time
GROUP BY A.m_no,A.d_time
HAVING COUNT(B.d_time) <= 3
) AS B1
ON A1.m_no = B1.m_no
AND A1.d_time = B1.d_time
ORDER BY A1.m_no,A1.d_time DESC
2020年3月13日 星期五
2020年2月23日 星期日
DOT NET CORE_API_L1 DB連線?
來源參考:https://www.youtube.com/watch?v=_SprpIlxug8
~appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
//連線字串
"ConnectionStrings":{
"DefaultConnection":"Data Source=127.0.0.1;Initial Catalog=DBJosh;User ID=Josh;Password=123456"
},
"AllowedHosts": "*"
}
-----------------------------------------
~Startup.cs
using *;
//**************手動補上 命名空間
using Microsoft.Extensions.Configuration; //ConfigurationBuilder 會用到
using System.IO; //Directory 會用到
using System.Data.SqlClient; //SQL
using System.Text.Encodings.Web; //HtmlEcoder會用到(處理中文編碼)
//**************************END
namespace webapi
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Run(async (context) =>
{
// await context.Response.WriteAsync("Hello World!");
//連線字串在appsetting.json 裡
var configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
IConfiguration config = configurationBuilder.Build();
string connectionString = config["ConnectionStrings:DefaultConnection"];
var Conn = new SqlConnection(connectionString);
Conn.Open();
var Com = new SqlCommand("SELECT u_area FROM tb_User WHERE u_no = @u_no", Conn);
Com.Parameters.AddWithValue("u_no", 1);
using (SqlDataReader dr = Com.ExecuteReader()) {
while (dr.Read()) {
//1.中文亂解決--瀏覽器改UTF8
var title = dr["u_area"];
await context.Response.WriteAsync("<br />"+ title +"<hr />");
//2.中文亂碼解決 -- 不用修改瀏覽器--請加入 using System.Text.Encodings.Web;
var title2 = HtmlEncoder.Default.Encode(dr["u_area"].ToString());
await context.Response.WriteAsync("<br />" + title2+ "<hr />");
}
}
Conn.Close();
});
}
}
}
Jenkins-mail
參考:http://www.linuxea.com/1767.html 前置作業略過~有空再補 Mailer Plugin post { success { emailext ( subject: &...
-
ASP.NET刷新頁面的六種方法 第一: private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToSt...
-
foreach (string fname in System.IO.Directory.GetFileSystemEntries(@"C:\Users\joshs")) { //if (fn...