Board logo

标题: CentOS8基本命令 [打印本页]

作者: admin    时间: 2020-2-18 10:11     标题: CentOS8基本命令

笺注:这是在 CentOS8编译安装Zabbix4.4.5 的基础上进行的。 检测防火墙服务firewalld是否运行中: 方法一:(要按“q”键退出) systemctl status firewalld 图片1.png 方法二: [root@centos8 ~]# systemctl | grep firewalld firewalld.service loaded active running firewalld - dynamic firewall daemon [root@centos8 ~]# [root@centos8 ~]# echo $? 0 注释:返回值为0时,才代表True 方法三: [root@centos8 ~]# ps -ef |grep firewalld root 970 1 0 17:16 ? 00:00:00 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid root 2249 2189 0 17:27 pts/1 00:00:00 grep --color=auto firewalld [root@centos8 ~]# [root@centos8 ~]# echo $? 0 [root@centos8 ~]# ps -ef |grep firewalld |grep -v grep root 970 1 0 17:16 ? 00:00:00 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid [root@centos8 ~]# [root@centos8 ~]# echo $? 0 停止服务firewalld: [root@centos8 ~]# systemctl stop firewalld 服务firewalld停止后的效果: 图片2.png [root@centos8 ~]# systemctl | grep firewalld [root@centos8 ~]# [root@centos8 ~]# echo $? 1 [root@centos8 ~]# ps -ef |grep firewalld root 2338 2189 0 17:30 pts/1 00:00:00 grep --color=auto firewalld [root@centos8 ~]# echo $? 0 [root@centos8 ~]# [root@centos8 ~]# ps -ef |grep firewalld |grep -v grep [root@centos8 ~]# [root@centos8 ~]# echo $? 1 启动服务firewalld: [root@centos8 ~]# systemctl start firewalld 重启服务firewalld: [root@centos8 ~]# systemctl restart firewalld 查看服务firewalld是否开机自动启动:(服务firewalld默认就是开机自动启动) [root@centos8 ~]# systemctl is-enabled firewalld enabled 查看开机自动启动的服务的列表:(截图有省略) systemctl list-unit-files|grep enabled 图片3.png 禁止开机时自动启动服务firewalld: [root@centos8 ~]# systemctl disable firewalld Removed /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@centos8 ~]# systemctl is-enabled firewalld disabled 查看开机时不可自动启动的服务的列表:(截图有省略) systemctl list-unit-files|grep disabled 图片4.png 开机时自动启动服务firewalld: [root@centos8 ~]# systemctl enable firewalld Created symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service → /usr/lib/systemd/system/firewalld.service. Created symlink /etc/systemd/system/multi-user.target.wants/firewalld.service → /usr/lib/systemd/system/firewalld.service. ###### 使用命令netstat检测本机的某个端口是否运行中 检测TCP 80端口是否运行中: [root@centos8 ~]# netstat -anp | grep 80 -bash: netstat: 未找到命令 注释:最小化安装是没有命令netstat 安装相关软件包: [root@centos8 ~]# dnf -y install net-tools 图片5.png 启动MariaDB: [root@centos8 ~]# systemctl start mysqld 检测TCP 3306端口是否运行中: [root@centos8 ~]# netstat -anp | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 1103/mysqld [root@centos8 ~]# echo $? 0 注释:返回值为0时,才代表True 命令netstat也可以检测服务是否在运行中: netstat -anp | grep mysqld 图片6.png [root@centos8 ~]# netstat -anp | grep mysqld > /dev/null [root@centos8 ~]# echo $? 0 关闭MariaDB: [root@centos8 ~]# systemctl stop mysqld [root@centos8 ~]# netstat -anp | grep 3306 [root@centos8 ~]# [root@centos8 ~]# echo $? 1 [root@centos8 ~]# netstat -anp | grep mysqld [root@centos8 ~]# [root@centos8 ~]# echo $? 1 ###### 开机自动执行某些命令: [root@centos8 ~]# vi /etc/rc.local 在末尾追加自定义的命令:(服务器重启后,无论系统用户root登录与否,命令都会执行) echo 'Welcome to zhuohua' > /zhuohua.txt 如下图: cat /etc/rc.local 图片7.png cat /etc/rc.d/rc.local 图片8.png [root@centos8 ~]# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 4月 24 2020 /etc/rc.local -> rc.d/rc.local 笺注: /etc/rc.local 是/etc/rc.d/rc.local的链接文件; /etc/rc.local  的默认权限是777 /etc/rc.d/rc.local  的默认权限是644 若不先给予/etc/rc.d/rc.local执行的权限,CentOS7/8不会开机自动执行/etc/rc.local里的命令: [root@centos8 ~]# chmod a+x /etc/rc.d/rc.local [root@centos8 ~]# ll /etc/rc.d/rc.local -rwxr-xr-x. 1 root root 590 1月 17 21:55 /etc/rc.d/rc.local CentOS8重启系统: [root@centos8 ~]# which init /usr/sbin/init [root@centos8 ~]# [root@centos8 ~]# init 6 服务器重启后,文件自动创建了: [root@centos8 ~]# ll /*.txt -rw-r--r-- 1 root root 19 1月 17 22:05 /zhuohua.txt [root@centos8 ~]# cat /zhuohua.txt Welcome to zhuohua CentOS8关闭系统: [root@centos8 ~]# init 0 相关文章: 最小化安装CentOS8 PuTTY远程管理CentOS8 Xshell4远程管理CentOS8 CentOS8使用计划任务 CentOS8使用命令ftp/lftp/scp

图片附件: 图片1.png (2021-1-17 22:34, 105.4 KB) / 下载次数 136
http://blog.zhuohua.store/attachment.php?aid=14836&k=63a27ba79c61c4bbe240642efaadb35b&t=1714245211&sid=4uZ4Wh



图片附件: 图片2.png (2021-1-17 22:35, 121.36 KB) / 下载次数 142
http://blog.zhuohua.store/attachment.php?aid=14837&k=a8c0cb0d9a35cbfec834ff3b88eafeaf&t=1714245211&sid=4uZ4Wh



图片附件: 图片3.png (2021-1-17 22:37, 80.95 KB) / 下载次数 123
http://blog.zhuohua.store/attachment.php?aid=14838&k=7f5fc0e2f7d1384f1c5f6f43cdf23079&t=1714245211&sid=4uZ4Wh



图片附件: 图片4.png (2021-1-17 22:38, 59.28 KB) / 下载次数 121
http://blog.zhuohua.store/attachment.php?aid=14839&k=fe4e5b1e0aa5cccfd7adce7ee8119eeb&t=1714245211&sid=4uZ4Wh



图片附件: 图片5.png (2021-1-17 22:39, 41.09 KB) / 下载次数 119
http://blog.zhuohua.store/attachment.php?aid=14840&k=46f5568c44c18fc1ac79a41378f851ba&t=1714245211&sid=4uZ4Wh



图片附件: 图片6.png (2021-1-17 22:40, 48.37 KB) / 下载次数 126
http://blog.zhuohua.store/attachment.php?aid=14841&k=8713035a2aea143921dcfeed415bcf68&t=1714245211&sid=4uZ4Wh



图片附件: 图片7.png (2021-1-17 22:41, 78.35 KB) / 下载次数 121
http://blog.zhuohua.store/attachment.php?aid=14842&k=5f8497c6c897c9702ed7874ceace128b&t=1714245211&sid=4uZ4Wh



图片附件: 图片8.png (2021-1-17 22:41, 78.66 KB) / 下载次数 123
http://blog.zhuohua.store/attachment.php?aid=14843&k=052bc3cc5247af6aaa2da82ab7ba11e1&t=1714245211&sid=4uZ4Wh






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2