systemctl
linux的服务使用 systemctl 来操作
查询出系统的服务: systemctl list-units --all , 可以用grep快速筛选要找的服务。
systemctl list-units |grep redis
启动/停止/重启/状态
systemctl [start/stop/restart] 服务名
[root@VM-12-9-opencloudos ~]# systemctl stop redis
[root@VM-12-9-opencloudos ~]# systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: inactive (dead)
May 12 15:20:23 VM-12-9-opencloudos systemd[1]: Stopping Redis persistent key-value database...
May 12 15:20:23 VM-12-9-opencloudos systemd[1]: redis.service: Succeeded.
May 12 15:20:23 VM-12-9-opencloudos systemd[1]: Stopped Redis persistent key-value database.
[root@VM-12-9-opencloudos ~]# systemctl restart redis
[root@VM-12-9-opencloudos ~]# systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: active (running) since Sun 2024-05-12 15:20:35 CST; 1s ago
Main PID: 2868959 (redis-server)
Tasks: 4 (limit: 10800)
Memory: 6.6M
CGroup: /system.slice/redis.service
└─2868959 /usr/bin/redis-server 127.0.0.1:6379
May 12 15:20:35 VM-12-9-opencloudos systemd[1]: Starting Redis persistent key-value database...
May 12 15:20:35 VM-12-9-opencloudos systemd[1]: Started Redis persistent key-value database.
yum
yum( Yellow dog Updater, Modified)是一个在 Fedora 和 RedHat 以及 SUSE 中的 Shell 前端软件包管理器。
基于 RPM 包管理,能够从指定的服务器自动下载 RPM 包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
yum 语法
yum [options] [command] [package ...]
1.options:可选,选项包括-h(帮助),-y(当安装过程提示选择全部为 "yes"),-q(不显示安装的过程)等等。
2.command:要进行的操作。
3.package:安装的包名。
常用命令
查看软件信息:yum info <package_name>
列出所有可更新的软件清单命令:yum check-update
更新所有软件命令:yum update
仅安装指定的软件命令:yum install <package_name>
仅更新指定的软件命令:yum update <package_name>
[root@VM-12-9-opencloudos yum.repos.d]# yum update redis
Last metadata expiration check: 0:20:53 ago on Sun 12 May 2024 06:39:57 PM CST.
Dependencies resolved.
Nothing to do.
Complete!
- 列出所有可安裝的软件清单命令:yum list
--all show all packages (default)
--available show only available packages
--installed show only installed packages
--extras show only extras packages
--updates show only upgrades packages
--upgrades show only upgrades packages
--autoremove show only autoremove packages
--recent show only recently changed packages
[root@VM-12-9-opencloudos yum.repos.d]# yum list zlib-static.x86_64
Last metadata expiration check: 0:17:12 ago on Sun 12 May 2024 06:39:57 PM CST.
Installed Packages
zlib-static.x86_64 1.2.11-21.oc8 @PowerTools
Available Packages
zlib-static.x86_64 1.2.11-25.oc8 PowerTools
删除软件包命令:yum remove <package_name>
查找软件包命令:yum search <keyword>
清除缓存命令:
yum clean packages: 清除缓存目录下的软件包
yum clean headers: 清除缓存目录下的 headers
yum clean oldheaders: 清除缓存目录下旧的 headers
yum clean, yum clean all (= yum clean packages; yum clean oldheaders) :清除缓存目录下的软件包及旧的 headers
yum源(可以修改成别的)
[root@VM-12-9-opencloudos yum.repos.d]# yum repolist enabled
repo id repo name
AppStream OpenCloudOS 8 - AppStream
BaseOS OpenCloudOS 8 - Base
Extras OpenCloudOS 8 - Extras
HighAvailability OpenCloudOS 8 - HighAvailability
PowerTools OpenCloudOS 8 - PowerTools
ResilientStorage OpenCloudOS 8 - ResilientStorage
docker-ce-stable Docker CE Stable - x86_64
或者
[root@VM-12-9-opencloudos yum.repos.d]# pwd
/etc/yum.repos.d
[root@VM-12-9-opencloudos yum.repos.d]# ls -ahlFS
total 40K
drwxr-xr-x. 109 root root 12K May 12 20:52 ../
drwxr-xr-x. 2 root root 4.0K Mar 26 2023 ./
-rw-r--r-- 1 root root 2.5K Feb 20 2023 OpenCloudOS-Debuginfo.repo
-rw-r--r-- 1 root root 2.1K Mar 26 2023 docker-ce.repo
-rw-r--r--. 1 root root 1.9K Sep 9 2022 OpenCloudOS-Sources.repo
-rw-r--r--. 1 root root 1.9K Sep 9 2022 OpenCloudOS.repo
-rw-r--r--. 1 root root 1.7K Jan 13 2023 OpenCloudOS-Sources.repo.rpmnew
-rw-r--r--. 1 root root 1.6K Jan 13 2023 OpenCloudOS.repo.rpmnew
apt
apt(Advanced Packaging Tool)是一个在 Debian 和 Ubuntu 中的 Shell 前端软件包管理器。apt 命令执行需要超级管理员权限(root)。
列出所有可更新的软件清单命令:sudo apt update
升级软件包:sudo apt upgrade
列出可更新的软件包及版本信息:apt list --upgradeable
升级软件包,升级前先删除需要更新软件包:sudo apt full-upgrade
安装指定的软件命令:sudo apt install <package_name>
安装多个软件包:sudo apt install <package_1> <package_2> <package_3>
更新指定的软件命令:sudo apt update <package_name>
显示软件包具体信息,例如:版本号,安装大小,依赖关系等等:sudo apt show <package_name>
删除软件包命令:sudo apt remove <package_name>
清理不再使用的依赖和库文件: sudo apt autoremove
移除软件包及配置文件: sudo apt purge <package_name>
查找软件包命令: sudo apt search <keyword>
列出所有已安装的包:apt list --installed
列出所有已安装的包的版本信息:apt list --all-versions
防火墙
systemctl status firewalld # 检查 firewalld 服务状态
firewall-cmd --state # 检查防火墙是否启用
systemctl start firewalld # 启动防火墙
systemctl stop firewalld # 停止防火墙
systemctl restart firewalld # 重启防火墙
systemctl enable firewalld # 开机自启动防火墙
systemctl disable firewalld # 禁止开机自启动防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent # 打开80端口,添加永久规则, 完成后要重载防火墙
firewall-cmd --zone=public --remove-port=80/tcp --permanent # 关闭80端口,移除永久规则
firewall-cmd --zone=public --add-service=http --permanent # 打开http服务,添加永久规则
firewall-cmd --zone=public --remove-service=http --permanent # 关闭http服务,移除永久规则
firewall-cmd --query-port=80/tcp #查询80端口是否开启
firewall-cmd --reload #重载防火墙