0%

记录

记录不常使用且碰到又找不到的命令以及碰到的问题和解决方案。本文会持续更新…

一条命令实现安装VM-tools

sudo apt install open-vm-tools-desktop

说明:此为开源的软件包,非VMware自家的

Linux挂载samba

mount -t cifs -o vers=3.0 //192.168.216.155/share /opt/

ubuntu22.04 php7.x编译时依赖openssl报错

错误如下

expected ‘RSA *’ {aka ‘struct rsa_st *’} but argument is of type ‘const struct rsa_st *’ 289 | RSA *rsa, int padding);

解决方案:https://github.com/phpbrew/phpbrew/issues/1263

export PKG_CONFIG_PATH=PATH/TO/OPENSSL/bin/lib/pkgconfig

Docker查看镜像制作过程

# 从下到上的过程
docker history --format {{.CreatedBy}} --no-trunc=true {IMAGE_NAME}

# 反过来
docker history --format {{.CreatedBy}} --no-trunc=true {IMAGE_NAME} | sed "s/\/bin\/sh\ -c\ \#(nop)\ //g"|sed "s/\/bin\/sh\ -c/RUN/g" | tac

记一次istio部署完成后,无法注入成功

# 修改kube-apiserver的配置
vim /etc/kubernetes/manifests/kube-apiserver.yaml

# 加一条启动参数
--enable-aggregator-routing=true

一条命令在Kubernetes中创建一个Debug Pod

kubectl run -i --tty --rm debug --image=busybox --restart=Never -- sh

也可以指定自己制作的镜像

使AWS EC2创建时无需密钥连接(测试使用)

#!/bin/bash
# 设置允许密码认证
sed -i "s/#PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config

# 修改端口
echo "Port 2314" >> /etc/ssh/sshd_config
systemctl restart sshd


# 添加新用户,并给用户设置密码以及sudo权限
useradd jadmin
echo "jadmin:j0e*Njebp.u^#j@#]6-J^RCM?:h,d-" | sudo chpasswd
sed -i "s/ec2-user/jadmin/g" /etc/sudoers.d/90-cloud-init-users

获取QuickStart中的AMI(python request)

def find_quickstart_ami():
url = "https://prod.us-west-2.qs.console.ec2.aws.dev/get_quickstart_list_zh.json"
res = requests.get(url)
quickstart_ami_json = res.json()

for ami in quickstart_ami_json["amiList"]:
# 判断是否是mac操作系统
if ami["platform"] == "x86_64_mac":
continue

# 判断是否为免费镜像
if not ami["freeTier"]:
continue

if len(ami["architectures"]) == 0:
print(f'title: {ami["title"]} | imageId:{ami["imageId64"]}')
else:
print(f'title: {ami["title"]} | imageId: {ami["architectures"][0]["imageId"]}')

AWS镜像AMI(ImageId)

Ubuntu:https://cloud-images.ubuntu.com/locator/ec2/

CentOS:https://www.centos.org/download/aws-images/

RedHat:https://access.redhat.com/solutions/15356

Windows: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/finding-an-ami.html#finding-an-ami-console

Amazon Linux: https://docs.aws.amazon.com/linux/al2023/ug/ec2.html

AWS CLI连接EC2

aws ec2-instance-connect ssh  --instance-ip 34.214.171.61 --region us-west-2  --instance-id i-0b8da26f77303ebb9 --os-user centos --connection-type direct --ssh-port 22

有时无法连接,请忍受

CloudWatch Agent高级指标监控脚本

#!/bin/bash
wget -O /tmp/amazon-cloudwatch-agent.deb https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i /tmp/amazon-cloudwatch-agent.deb
rm -rf /tmp/amazon-cloudwatch-agent.deb

wget -O /opt/aws/amazon-cloudwatch-agent/bin/config.json https://s3.us-west-2.amazonaws.com/oca.develop.bucket/config.json

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json

{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "ubuntu"
},
"metrics": {
"namespace": "Custom",
"aggregation_dimensions": [
[
"InstanceId"
]
],
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"cpu": {
"measurement": [
"cpu_usage_idle",
"cpu_usage_iowait",
"cpu_usage_user",
"cpu_usage_system"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"totalcpu": false
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"diskio": {
"measurement": [
"io_time",
"write_bytes",
"read_bytes",
"writes",
"reads"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"netstat": {
"measurement": [
"tcp_established",
"tcp_time_wait"
],
"metrics_collection_interval": 60
},
"statsd": {
"metrics_aggregation_interval": 60,
"metrics_collection_interval": 10,
"service_address": ":8125"
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}

GitHub Action Demo

reference: https://docs.github.com/zh/actions/quickstart

https://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html

.git/workflow/ci.yml

# This is test workflows
name: GitHub Actions Demo

on: [push, pull_request]


jobs:
# job1
my_job1:
name: My first job
runs-on: ubuntu-latest
steps:
- name: Print a greeting
env:
MY_VAR: Hi there! My name is
FIRST_NAME: Mona
MIDDLE_NAME: The
LAST_NAME: Octocat
run: |
echo $MY_VAR $FIRST_NAME $MIDDLE_NAME $LAST_NAME.

# job2
my_job2:
name: My second job
needs: my_job1
runs-on: ubuntu-latest
steps:
- name: Respones Message
run: |
echo "Job1 is Success."

同步外国镜像到dockerhub

# 工作流名称
name: Sync-Images-to-DockerHub-Example
# 工作流运行时显示名称
run-name: ${{ github.actor }} is Sync Images to DockerHub.
# 怎样触发工作流
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# 工作流程任务(通常含有一个或多个步骤)
jobs:
syncimages:
runs-on: ubuntu-latest
steps:
- name: Checkout Repos
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.9.1

- name: Login to Docker Hub
uses: docker/login-action@v2.2.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
logout: false

- name: Use Skopeo Tools Sync Image to Docker Hub
run: |
#!/usr/bin/env bash
skopeo copy docker://gcr.io/kaniko-project/executor:v1.13.0 docker://docker.io/jiangleiww/kaniko-executor:v1.13.0