月度归档:2020年11月

debian 设置静态 IP

编辑配置文件:

vim /etc/network/interfaces

参考以下配置:

auto ens18                  # 添加该行
allow-hotplug ens18
iface ens18 inet static     # 改这里
address 192.168.188.40      # 添加该行和以下行
netmask 24
gateway 192.168.188.1
nameservers 114.114.114.114

sed 替换的用法

第一个aa替换为bb

sed -i 's/aa/bb/' file

所有aa替换为bb

sed -i 's/aa/bb/g' file

文件第3行的aa替换为bb

sed -i '3s/aa/bb/' file

找出包含xxx的行,并将其中的aa替换为bb

sed -i '/xxx/s/aa/bb/g' file

文件第1行,将其中的#号或是*号替换为fff

sed -i '1s/[#*]/fff/gp' file

firewall-cmd 常用操作

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --permanent --zone=public --remove-port=80/tcp

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.188.222" port protocol="tcp" port="3306" accept"
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address=" 192.168.1.100" port protocol="tcp" port="3306" accept"

firewall-cmd --reload

nginx 代理 gitlab 时的 413 问题

git push 时出现:

Counting objects: 80, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
fatal: The remote end hung up unexpectedly
Writing objects: 100% (80/80), 42.70 MiB | 12.01 MiB/s, done.
Total 80 (delta 47), reused 0 (delta 0)
error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large
fatal: The remote end hung up unexpectedly
Everything up-to-date

可以先尝试

git config --global http.postBuffer 524288000

同时检查 nginx 配置,在 nginx.confhttp 中添加:

client_max_body_size 100m;

100m 值取决于报错的大小。

linux 系统修改为中国时区

方法1

tzselect

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

验证

date -R

方法2

timedatectl set-timezone Asia/Shanghai
timedatectl status 或 timedatectl

设置硬件时区

# 设为本地时区(一般不这样)
timedatectl set-local-rtc 1
# 设为协调世界时(UTC)(通常设UTC)
timedatectl set-local-rtc 0

NTP 同步

timedatectl set-ntp true
timedatectl set-ntp false

linux 中格式化并挂载超过2T的硬盘

在需要对一个大于2T的硬盘分区时,使用fdisk不能建立分区。原因是fdisk只能建立2TB大小的分区。如果大于2T需要采用GPT磁盘模式。

使用parted工具,安装:

yum install parted
parted /dev/sdb //选择硬盘

GNUParted 2.3Using /dev/sdbWelcome to GNU Parted! Type 'help' to view a lis ofcommands。
(parted) mklabel gpt //类型GPT

Warning: The existing disk label on /dev/sdb will be destroyedand all data on this disk will be lost. Do you want to continue?
Yes/No? y //确定
(parted) mkpart prinmary 1 -1 //将硬盘分成一个分区
(parted) print //查看
(parted) quit //退出Information: You may need to update /etc/fstab.
mkfs.ext4 /dev/sdb1 //格式化文件系统为ext4

查看磁盘

blkid

添加到 fstab

echo UUID=177d63f1-b30a-40c8-b228-5dc3e18e96eb /home ext4 defaults 0 0 >> /etc/fstab