CentOS 7 是目前廣泛使用的 Linux 操作系統之一,也是運行 web 服務或應用程序的主要系統之一。在使用 CentOS 7 系統時,熟練掌握常用命令可以幫助我們更有效地管理和維護伺服器。本文將介紹 CentOS 7 常用命令,幫助您更輕鬆地管理、維護伺服器。
一、基本操作命令
1、登錄伺服器
ssh username@hostname
其中,`username` 是您的用戶名,`hostname` 是伺服器的主機名或 IP 地址。
2、退出登錄
exit
3、重啟伺服器
reboot
4、關機
poweroff
5、查看系統版本
cat /etc/redhat-release
二、文件操作命令
1、查看當前目錄下的文件和文件夾
ls
2、查看指定目錄下的文件和文件夾
ls /path/to/directory
3、創建新目錄
mkdir directory_name
4、刪除空目錄
rmdir directory_name
5、複製文件
cp /path/to/source_file /path/to/destination_directory
6、移動文件或重命名文件
mv /path/to/source_file /path/to/destination_file
7、刪除文件
rm file_name
三、常用服務命令
1、Apache(HTTP 伺服器)
啟動 Apache:
systemctl start httpd
停止 Apache:
systemctl stop httpd
重啟 Apache:
systemctl restart httpd
查看 Apache 狀態:
systemctl status httpd
2、Nginx(HTTP 伺服器)
啟動 Nginx:
systemctl start nginx
停止 Nginx:
systemctl stop nginx
重啟 Nginx:
systemctl restart nginx
查看 Nginx 狀態:
systemctl status nginx
3、MySQL(資料庫)
啟動 MySQL:
systemctl start mysqld
停止 MySQL:
systemctl stop mysqld
重啟 MySQL:
systemctl restart mysqld
查看 MySQL 狀態:
systemctl status mysqld
四、網路相關命令
1、查看 IP 地址
ip addr
2、查看網路狀態
systemctl status network
3、修改網路配置
編輯網路配置文件:
vi /etc/sysconfig/network-script/ifcg-eth0
其中,`eth0` 是網路介面名稱。根據實際情況更改配置文件內容,保存並退出。
重新啟動網路服務:
systemctl restart network
五、用戶和許可權相關命令
1、創建新用戶
useradd new_username
2、修改用戶密碼
passwd username
3、修改用戶許可權
修改文件或目錄許可權:
chmod [options] mode file
其中,`options` 是選項,`mode` 是許可權模式(如 `777`),`file` 是文件或目錄名稱。
修改文件或目錄所有者:
chown [options] owner:group file
其中,`options` 是選項,`owner` 是所有者,`group` 是組,`file` 是文件或目錄名稱。
以上就是 CentOS 7 常用命令的介紹。熟練掌握這些命令可以幫助我們更有效地管理和維護伺服器。
原創文章,作者:WPDP,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/141952.html