# 编译 openresty # wget -t 3 https://openresty.org/download/openresty-1.21.4.3.tar.gz -O -|tar xzf - # wget -t 3 https://zlib.net/current/zlib.tar.gz -O -|tar xzf - # yum -y install gcc gcc-c++ make readline-devel pcre-devel openssl-devel perl bzip2-devel clang zlib-devel #./configure --prefix=/home/ywgx/0/openresty --with-pcre-jit --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-http_v2_module --with-http_iconv_module --without-http_limit_req_module --without-http_limit_conn_module --without-http_split_clients_module --without-poll_module --without-select_module --without-http_fastcgi_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module --without-http_ssi_module --without-http_geo_module --without-http_empty_gif_module --without-http_browser_module --without-http_upstream_ip_hash_module --without-http_upstream_least_conn_module --without-http_upstream_zone_module --with-zlib=../zlib # nginx 跨域配置 add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,Keep-Alive,User-Agent,Content-Type' always; add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE' always; add_header 'Access-Control-Expose-Headers' 'X-Jump,X-Session-Valid' always; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,Keep-Alive,User-Agent,Content-Type' always; add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE' always; add_header 'Access-Control-Expose-Headers' 'X-Jump,X-Session-Valid' always; add_header 'Access-Control-Max-Age' 1728000; return 204; } #查询命令安装包 yum provides envsubst 或者 yum whatprovides envsubst #标准输出 /dev/stdout #标准输入 /dev/stdin #标准错误输出 /dev/stderr #nfs 依赖 yum -y install nfs-utils #sftp 可以 ftp 不行的问题,查看 getsebool allow_ftpd_full_access 如果是 off ,可以打开 setsebool allow_ftpd_full_access #pip3 install -U pip setuptools #pip3 download -d packages/ -r requirements.txt 把依赖包都下到packages文件夹里 #pip3 install --no-index --find-links=packages/ -r requirements.txt 离线安装 #pip3 freeze > requirements.txt # problem making ssl connection 先把 /etc/yum.repos.d/rdo-release.repo里的enabled=0,禁用掉 在执行yum install ca-certificates # RPM 数据库问题 'yum check' 解决方法 package-cleanup --cleandupes # module_name = shell 将默认的模块改为shell,command模块功能太弱 ansible AppGroup -m shell -a 'w' #查看域名 dns dig baidu.com +nssearch #显示连接用户信息 ss -tapo dport = :3306 #可以使用以下命令查使用内存最多的10个进程 ps -aux | sort -k4nr | head -n 10 #可以使用一下命令查使用CPU最多的10个进程 ps -aux | sort -k3nr | head -n 10 # 物理内存大小 = 物理已使用的内存 + 物理没使用的内存 total = used + free # 可用内存大小 = 物理没使用的内存 + 缓冲 + 缓存 available = free + buffers + cached # 内存使用率 = (物理内存大小 - 可用内存大小) / 物理内存大小 * 100 percent = (total - available) / total * 100 /etc 系统文件属性恢复 #restorecon -Rv /etc PATH=$PATH:$HOME/.local/bin:$HOME/bin 查看某进程的文件打开数 cat /proc//limits ls -lh /proc//fd ls -lh /proc//fd|wc -l import salt.client local = salt.client.LocalClient() print(help(local.cmd)) find . -type f | parallel -j+0 grep -i foobar 并发的grep systemctl list-unit-files --type=service|grep enabled ulimit -n # 查看当前用户可用最大句柄 sysctl -a | grep fs.file-max # 查看内核级的文件句柄最大限制值 cat /proc/sys/fs/file-nr # 查看当前已用的文件句柄数量 和 内核级的文件句柄限制的最大值 乱码转换 :set fileencoding=UTF-8 :x! TAB替换为空格: :se ts=4 :se et :%retab! 空格替换为TAB: :se ts=4 :se noet :%retab! curl 2 python: https://curl.trillworks.com au BufNewFile,BufRead *.py se ts=4 sts=4 sw=4 et k8s minikube start --driver=hyperv --memory=4096m --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers /etc/security/limits.conf (注意同时要留意 /etc/security/limits.d/下面的参数) root soft nofile 65535 root hard nofile 65535 * soft nofile 65535 * hard nofile 65535 * soft nproc 65535 * hard nproc 65535 还要追加下面一行给(/etc/pam.d/login) session required pam_limits.so usermod -aG wheel ywgx (把 ywgx 添加入wheel分组) rsync -av --progress --delete /tmp/abc ywgx@base.xabcstack.com:/tmp/ (这个会把当前主机 /tmp/abc 同步到目标机器 /tmp/ 目录下,如果没有自动创建abc目录) rsync --daemon --config=./rsyncd.conf rsync -aq --progress root@repo.xabcstack.com::salt . rsync -aq --progress --delete --exclude={"COMMIT",} /cache/sys root@172.18.10.144:/cache/ (把当前主机 /cache/sys 目录同步到目标机器 /cache/, 跳过/cache/sys/COMMIT 这个目录 ) return 301 https://$host$request_uri; awk '{ print $(NF-2) }' scp -P 12349 upload_file username@server echo "*/5 * * * * pgrep sentinel.py||/srv/zero/sentinel.py &>/var/log/xabc.log &" > /var/spool/cron/root for i in `find /root/.jenkins/jobs -maxdepth 6 -name "[0-9]*" -a -mtime +3`;do rm -rf $i;done */5 * * * * pgrep nginx||/opt/openresty/nginx/sbin/nginx netstat -aulntp nc -vuz 100.67.1.217 514 (探测主机100.67.1.217 UDP 514 端口是否打开) Influxdata 数据备份和恢复 备份: influxd backup -database database_name 数据存储位置 influxd backup -database database_name -host localhost:8088 数据存储位置 # 远程备份 恢复元数据: influxd restore -metadir /var/lib/influxdb/meta/ 元数据存储位置 influxd restore -database database_name -datadir /var/lib/influxdb/data 数据存储位置 修改权限: chown -R influxdb:influxdb /var/lib/influxdb 重启influxdb: service influxdb stop service influxdb start 磁盘挂载 1. fdisk -l 2. mkfs.ext4 /dev/vd{x} 3. mount /dev/vd{x} /media 4. vim /etc/fstab /dev/vd{x} /media ext4 defaults 0 0 时区设置 timedatectl set-timezone Asia/Shanghai timedatectl 查看时间设置 chronyc sources -v 查看时间同步状态 提示Read-only file system,执行命令 mount -o remount rw / 同步本地时间到硬件 hwclock --systohc 通过redis-cli导入数据 通过在ECS上的redis-cli,可将用户ECS上原有的数据导入到云数据库Redis版中,操作代码为: # redis-cli -h old_instance_ip -p old_instance_port config set appendonly yes # redis-cli -h aliyun_redis_instance_ip -p 6379 -a password --pipe < appendonly.aof # terraform terraform version 查看 Terraform 版本 terraform init 初始化 Terraform terraform plan Terraform 执行计划 terraform apply 应用 Terraform terraform show 检查 Terraform 状态 terraform output 查看输出变量的值 terraform graph 生成资源依赖图 terraform destroy 销毁资源 terraform workspace 管理 Terraform 工作区 terraform workspace new 新建工作区 terraform workspace list 列出工作区 terraform workspace select 切换工作区 terraform workspace delete 删除工作区 terraform get 下载或更新 Terraform 模块 terraform fmt 格式化 Terraform 代码 terraform validate 检查 Terraform 语法 terraform console Terraform 控制台 iptables -I INPUT -s xmr.crypto-pool.fr -j DROP iptables -A OUTPUT -d xmr.crypto-pool.fr -j DROP iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -t mangle -I POSTROUTING -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1024 firewall systemctl start firewalld firewall-cmd --reload firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https use mysql; update user set host = '%' where user = 'root'; FLUSH PRIVILEGES;