Skip to main content

45 posts tagged with "linux"

View All Tags

· One min read

install

apk add sqlite lua-sql-sqlite3

crud

local sqlite3 = require "luasql.sqlite3"

-- 创建一个 SQLite 环境
local env = sqlite3.sqlite3()

-- 打开内存数据库
local db = env:connect("test.db")

-- 创建一个示例表
db:execute("CREATE TABLE test (id INTEGER PRIMARY KEY, content)")
db:execute("INSERT INTO test VALUES (1, 'Hello, World!')")
db:execute("INSERT INTO test VALUES (2, 'Lua with SQLite3')")

-- 查询并输出数据
local cursor = db:execute("SELECT * FROM test")

local row = cursor:fetch({}, "a")
print(row)
while row do
print(string.format("Row %d: %s", row.id, row.content))
row = cursor:fetch(row, "a")
end

-- 关闭游标和数据库连接
cursor:close()
db:close()
env:close()

· One min read

ossfs

wget https://gosspublic.alicdn.com/ossfs/ossfs_1.91.1_ubuntu22.04_amd64.deb
dpkg -i ossfs_1.91.1_ubuntu22.04_amd64.deb

dpkg --configure -a
apt-get -f install

echo cert:key > /etc/passwd-ossfs
chmod 600 /etc/passwd-ossfs

s3fs madex-test /www/minio-oss -o passwd_file=/etc/passwd-ossfs -o url=http://oss-cn-shanghai-internal.aliyuncs.com
umount /www/minio-oss

· One min read

config

:help config

# windows
Unix ~/.config/nvim/init.vim (or init.lua)
Windows ~/AppData/Local/nvim/init.vim (or init.lua)
|$XDG_CONFIG_HOME| $XDG_CONFIG_HOME/nvim/init.vim (or init.lua)

git clone https://github.com/nshen/learn-neovim-lua.git

· One min read

cuda install

# https://developer.nvidia.com/cuda-11-6-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Debian&target_version=11&target_type=deb_local
wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-debian11-11-6-local_11.6.0-510.39.01-1_amd64.deb
dpkg -i cuda-repo-debian11-11-6-local_11.6.0-510.39.01-1_amd64.deb
apt-key add /var/cuda-repo-debian11-11-6-local/7fa2af80.pub
add-apt-repository contrib
apt-get update
apt-get -y install cuda # error

wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/update-glx_1.2.1~deb11u1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/glx-alternative-mesa_1.2.1~deb11u1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/n/nvidia-support/nvidia-installer-cleanup_20151021+13_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/glx-diversions_1.2.1~deb11u1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/glx-alternative-nvidia_1.2.1~deb11u1_amd64.deb

apt-get -y install cuda
apt-get install linux-headers-$(uname -r) # !!!
reboot # !!!

conda install

apt-get install linux-headers-$(uname -r) # !!!
curl -O https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
sh Anaconda3-2022.10-Linux-x86_64.sh
# /etc/conda
# conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
# conda install cuda -c nvidia

conda update

conda -V
conda update -n base conda
conda update --all
conda install python=3.11

uninstall

conda install anaconda-clean
rm -rf /etc/conda

apt-get remove --purge '^nvidia-.*'
apt-get remove --purge '^libnvidia-.*'
apt-get remove --purge '^cuda-.*'

apt-get install linux-headers-$(uname -r)

check tool

lspci | grep -i nvidia # 查看PCI设备

# 查看硬件信息
apt-get install lshw
lshw -numeric -C display # 没有 unclaimed

cat /proc/driver/nvidia/version # 检查驱动版本

nvidia-smi

· 5 min read

install

# https://luabinaries.sourceforge.net/download.html
apk add --no-cache lua5.4
mv /usr/bin/lua5.4 /usr/bin/lua

demo

hvac pump

--lua hvac.lua a1

--for k, v in pairs(arg) do
-- print(k, v)
--end

local name = arg[1] or "b6"

local ts = os.time()
local hour = tonumber(os.date("%H"))
local minute = tonumber(os.date("%M"))

-- 24小时等间数据
local dataArr = {
a0 = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
-- 制冷机 制冷量 (kW) 冷冻水进水温度 (摄氏度) 冷冻水出水温度(摄氏度) 冷冻水温差 (摄氏度) 散热量 (kW) 冷却水进水温度 冷却水出水温度 冷却水温差 电机功率(W)
a1 = { 0, 0, 0, 0, 208250, 833000, 2082500, 3748500, 5622750, 7288750, 7996800, 8121750, 6539050, 6247500, 7038850, 8163400, 7996800, 7580300, 6664000, 5081300, 3165400, 1999200, 999600, 208250 },
a2 = { 26.70, 26.70, 26.70, 26.70, 6.55, 6.83, 7.47, 8.35, 9.25, 10.09, 10.48, 10.59, 9.71, 9.60, 10.01, 10.57, 10.46, 10.22, 9.78, 8.97, 8.00, 7.47, 6.92, 6.59 },
a3 = { 26.70, 26.70, 26.70, 26.70, 6.44, 6.41, 6.42, 6.46, 6.41, 6.42, 6.45, 6.49, 6.41, 6.45, 6.46, 6.46, 6.43, 6.40, 6.42, 6.41, 6.41, 6.46, 6.41, 6.48 },
a4 = { 0, 0, 0, 0, 0.105, 0.42, 1.05, 1.89, 2.835, 3.675, 4.032, 4.095, 3.297, 3.15, 3.549, 4.116, 4.032, 3.822, 3.36, 2.562, 1.596, 1.008, 0.504, 0.105 },
a5 = { 0, 0, 0, 0, 260312.5, 1041250, 2603125, 4685625, 7028437.5, 8776250, 9596160, 9746100, 7846860, 7448942.308, 8342340.741, 9703664.151, 9602583.133, 9264811.111, 8250666.667, 6335941.975, 3956750, 2499000, 1249500, 260312.5 },
a6 = { 26.7, 26.7, 26.7, 26.7, 22.5, 23.1, 23.9, 24.7, 25.3, 25.7, 25.98, 26.1, 26.18, 26.3, 26.26, 26.14, 25.98, 25.78, 25.5, 25.18, 24.54, 24.02, 23.18, 22.5 },
a7 = { 26.7, 26.7, 26.7, 26.7, 22.61, 23.56, 25.04, 26.76, 28.39, 29.56, 30.20, 30.38, 29.63, 29.57, 29.93, 30.41, 30.20, 29.85, 29.13, 27.97, 26.28, 25.12, 23.73, 22.61 },
a8 = { 0, 0, 0, 0, 0.11, 0.46, 1.14, 2.06, 3.09, 3.86, 4.22, 4.28, 3.45, 3.27, 3.67, 4.27, 4.22, 4.07, 3.63, 2.79, 1.74, 1.10, 0.55, 0.11 },
a9 = { 0, 0, 0, 0, 52062.50, 208250.00, 520625.00, 937125.00, 1405687.50, 1487500.00, 1599360.00, 1624350.00, 1307810.00, 1201442.31, 1303490.74, 1540264.15, 1605783.13, 1684511.11, 1586666.67, 1254641.98, 791350.00, 499800.00, 249900.00, 52062.50 },
-- 冷冻水泵 水泵出口流量 (m3/h) 运行状态 水泵进口压力 水泵出口压力 扬程 电机功率 (W)
b1 = { 0, 0, 0, 0, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700 },
b2 = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
b3 = { 0, 0, 0, 0, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3 },
b4 = { 0, 0, 0, 0, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82 },
b5 = { 0, 0, 0, 0, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2 },
b6 = { 0.00, 0.00, 0.00, 0.00, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80 },
-- 冷却水泵 水泵出口流量 (m3/h) 运行状态 水泵进口压力 水泵出口压力 扬程 电机功率
c1 = { 0, 0, 0, 0, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950 },
c2 = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
c3 = { 0, 0, 0, 0, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34 },
c4 = { 0, 0, 0, 0, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45 },
c5 = { 0, 0, 0, 0, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1 },
c6 = { 0.00, 0.00, 0.00, 0.00, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74 },
}
local dataL = dataArr[name][hour]
local dataR = dataArr[name][hour + 1]

local ret = dataL + (dataR - dataL) * (minute / 60)
local bias = math.random(-50, 50) / 1000
ret = ret * (1 + bias)

-- 排除离散
if (name == "a0" or name == "b2" or name == "c2") then
ret = dataL
end

--print(name)
--print(hour .. ":" .. minute, "(" .. dataL .. ', ' .. dataR .. ")")
print(string.format("%.2f", ret))

· One min read

方法 1 alias

alias tfa='terraform apply --auto-approve'

方法 2 ln

ln -sf /c/Program\ Files/Notepad++/notepad++.exe .

方法 3 sh

$ cat pad
#!/bin/sh
/c/Program\ Files/Notepad++/notepad++.exe $*

· One min read

Intro

快速可自定义的虚拟机,几行命令搞定,不用再设置一堆东西。 自定义文件Vagrantfile实现环境重复利用 https://www.vagrantup.com/intro

Install

https://www.vagrantup.com/downloads
# wget https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.msi

Start

vagrant init generic/alpine312  # https://vagrantcloud.com/search

vagrant up --provider=hyperv # start
vagrant halt # stop

vagrant ssh

vagrant destroy # delete

Other

vagrant box list                # list image
vagrant global-status # list vm
vagrant destroy 1a2b3c4d

# 手动下包 wget https://app.vagrantup.com/generic/boxes/alpine312/versions/3.6.4/providers/hyperv.box
vagrant box add my/alpine312 hyperv.box

# 127.0.0.1:2222 # root vagrant

Vagrantfile

# touch Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "generic/alpine312"
end

· One min read
version: "3"

networks:
loki:

services:
loki:
image: grafana/loki:2.4.0
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
networks:
- loki

promtail:
image: grafana/promtail:2.4.0
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers
- .:/etc/promtail
command: -config.file=/etc/promtail/config.yml
networks:
- loki

grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
networks:
- loki

config.yml

server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /tmp/positions.yaml

clients:
- url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log

- job_name: containers
entry_parser: raw

static_configs:
- targets:
- localhost
labels:
job: containerlogs
__path__: /var/lib/docker/containers/*/*log

# --log-opt tag="{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
pipeline_stages:

- json:
expressions:
stream: stream
attrs: attrs
tag: attrs.tag

- regex:
expression: (?P<image_name>(?:[^|]*[^|])).(?P<container_name>(?:[^|]*[^|])).(?P<image_id>(?:[^|]*[^|])).(?P<container_id>(?:[^|]*[^|]))
source: "tag"

- labels:
tag:
stream:
image_name:
container_name:
image_id:
container_id:

· One min read

加速

# backup
cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
sed 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list

# run
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
apt-get update -y

common

apt-get install procps # top ps

apt-get install net-tools
apt-get install iputils-ping # ping
apt-get install dnsutils # nslookup

apt-get install apt-transport-https ca-certificates # https

user

adduser new_user
usermod -G sudo new_user # 将用户添加到sudo组中
su - new_user

vi bug 方向键

vi /etc/vim/vimrc.tiny
set nocompatible
set backspace=2

ubuntu 加速

cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sed 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

apt update

· One min read

ldd hehe

objdump

#显示所可用的头信息,包括符号表、重定位入口。-x 等价于-a -f -h -r -t 同时指定。
objdump -x ota
#显示文件的符号表入口
objdump -t ota

hexdump

hexdump -C config.json  # 16进制查看
xdd config.json # 二进制查看

.so func list

nm -D libSP.so
objdump -T libSP.so # --dynamic-syms 显示文件的动态符号表入口,仅仅对动态目标文件意义

strip 压缩 脱衣服

#iot-echo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
#iot-echo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), stripped
#iot-echo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
# nm iothub-echo # strip后就没有了
strip iothub-echo