015 Linux 系统操作相关
2025/5/22约 1391 字大约 5 分钟
Linux系统代理
# openEuler系统设置临时代理
export http_proxy=http://peulerosci:EulerOS_123@proxycn2.huawei.com:8080
export https_proxy=https://peulerosci:EulerOS_123@proxycn2.huawei.com:8080Linux操作系统
Centos
说明:
- centos 发行版是 Redhat 的社区免费版,和 Redhat 一样,只是缺少商业支持
- centos-linux 为稳定版本,更新较慢,系统和软件稳定
- centos-stream 为滚动版本,和 Redhat 开发版本一样,更新频繁,系统和软件不太稳定
- 可下载完整版的 iso 文件,然后在安装界面可选择安装模式。如完整模式和 mini 命令行模式。
下载链接:
分 centos-linux 和 centos-stream 版本
- 官网:https://www.centos.org/
- 清华镜像站:https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/BaseOS/x86_64/iso/
Centos-stream 发行版
说明:官方已经不维护 centos 系统,自2021年年底,最后一版 centos 8 系统正式停止维护。之后使用 centos-stream 滚动发行版作为 Redhat 上游开发社区版。
阿里镜像源:
# AppStream.repo:这个源提供了CentOS Stream的应用程序流软件包
# Extras.repo:这个源提供了CentOS Stream的额外软件包
# BaseOS.repo:这个源提供了CentOS Stream的基本操作系统软件包
# CentOS-stream-9-Base.repo aliyun
[Centos-stream-9-base]
name=CentOS-stream-9 - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/$basearch/os/
http://mirrors.aliyuncs.com/centos-stream/9-stream/BaseOS/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-stream/9-stream/BaseOS/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-9-stream - AppStream - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-stream/9-stream/AppStream/$basearch/os/
http://mirrors.aliyuncs.com/centos-stream/9-stream/AppStream/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-stream/9-stream/AppStream/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
[extras]
name=CentOS-9-stream - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-stream/9-stream/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos-stream/9-stream/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-stream/9-stream/extras/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
[centosplus]
name=CentOS-9-stream - Plus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-stream/9-stream/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos-stream/9-stream/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-stream/9-stream/centosplus/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-9-stream - PowerTools - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-stream/9-stream/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos-stream/9-stream/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-stream/9-stream/PowerTools/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-stream/RPM-GPG-KEY-CentOS-OfficialopenEuler发行版
说明:openEuler 发行版包含多个分支版本
开发各分支每日构建源:http://121.36.84.172/dailybuild/
社区组件源码:https://gitee.com/organizations/src-openeuler/projects
官方源:
# 官方 22.03-LTS-SP1 源
[22.03-LTS-SP1]
name=22.03-LTS-SP1
baseurl=http://121.36.84.172/dailybuild/EBS-openEuler-22.03-LTS-SP1/EBS-openEuler-22.03-LTS-SP1/everything/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://121.36.84.172/dailybuild/EBS-openEuler-22.03-LTS-SP1/EBS-openEuler-22.03-LTS-SP1/everything/x86_64/RPM-GPG-KEY-openEulerAnolis Linux-龙蜥发行版
# 官方源网址
https://mirrors.openanolis.cn/anolis/F-Droid 安卓自由开源软件
# 首页
https://f-droid.org
# 软件下载页面
https://f-droid.org/zh_Hans/packages/安卓模拟Windows
# 和 OOB文件 下载网址
https://winlator.com/download/
# Winlator 源代码首页
https://github.com/brunodev85/winlatorfedoras/rpm Linux系统发行版语言设置
# 1. 查看当前语言设置
echo $LANG
# 2. 列出系统支持的语言
localectl list-locales
# 3. 安装相关语言包
yum install -y langpacks-zh-CN
# 4. 查看语言、键盘等环境设置
localectl status
# 5. 设置、更改语言
localectl set-locale LANG=zh_CN.UTF-8初始化 rpmbuild 及其子目录
- 安装
rpmdevtools软件包 - 执行
rpmdev-setuptree命令
修改Linux启动问候语
vim /etc/motdalias修改别名
- 安装
bash软件包,alias命令由它提供 - 编辑
/etc/profile.d/alias.sh文件
Linux环境端口管理
iptables
下载组件
iptables编辑端口管理文件
vim /etc/sysconfig/iptables# 开通端口22,用于ssh协议流量 -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
netstat
- 查看所有已开启端口状态:
netstat -tulnp
firewall - 开启/关闭 端口
# 开启防火墙
systemctl start firewalld
# 永久开启 80 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重载配置
firewall-cmd --reloadLinux终端快捷键
每个 Linux 发行版的终端不一样,但基于 bash 的终端快捷键大差不差。此处主要记录常用的 bash Shell 的快捷键
# 删除光标 前/后 的字符
Ctrl + u/kLinux系统安装宝塔面板
此处以 Centos-stream-9 发行版为例
直接运行命令:其实是下载 安装脚本 执行
yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484becLinux系统语言环境配置
此处以 EulerOS 操作系统为例,其基于 RedHat 系 Linux 操作系统
# 查看当前语言状态
localectl status
# 显示当前系统可用的所有语言环境
localectl list-locales
# root 用户下,设置系统语言环境
localectl set-locale LANG=zh_CN.UTF-8
# 或者直接编辑 语言文件
vim /etc/locale.confLinux系统 日期与时区配置
此处以 EulerOS 操作系统为例,其基于 RedHat 系 Linux 操作系统
# 显示当前系统日期与时间
timedatectl
# root 用户下,修改当前系统时间
timedatectl set-time 15:57:24
# root 用户下,修改当前系统日期
timedatectl set-time '2015-08-14'
# 显示当前系统所有可用时区
timedatectl list-timezones
# root 用户下,修改当前系统时区为 Asia/Shanghai
timedatectl set-timezone Asia/Shanghai
# 启动 NTP 远程服务器,以自动同步系统时钟
timedatectl set-ntp yes程序/日志调试相关
1. coredumpctl
- coredump 日志文件路径 - /var/lib/systemd/coredump/
# 查看 coredump 是否开启(0:未开启,unlimited:已开启)
ulimit -c
# 列出系统上的所有coredump日志
coredumpctl
# 或
coredumpctl list
# 在日志文件存在的情况下,使用gdb查看日志文件
coredumpctl gdb 42127[PID]
# 使用gdb打开日志后,键入 bt 查看栈调用网络报错、异常
启动容器后报错
WARNING: IPv4 forwarding is disabled. Networking will not work.
- 使用命令
sysctl net.ipv4.ip_forward查询,输出为1则表示IPV4转发正常,若为0,下一步。 - 编辑文件
vim /etc/sysctl.conf,找到或添加行net.ipv4.ip_forward=1,并将结果设置为1。 - 立即生效
sysctl -p,或重启网络服务systemctl restart network。