系统服务管理命令systemctl
systemctl start sshd // 开启一个服务
systemctl stop sshd // 关闭一个服务
systemctl status sshd // 查看一个服务的状态
systemctl restart sshd // 重启一个服务
systemctl enable sshd // 设定一个服务开机启动
systemctl disable sshd // 设定服务开机不启动
systemctl reload sshd // 重新加载服务的配置文件
systemctl mask sshd // 锁定服务
systemctl unmask sshd // 解锁服务
// systemctl set-default graphical.target // 开机启动图形
// systemctl set-default multi-user.target // 开机不启动图形
登录服务器命令
ssh root@172.254.23.xxx // ssh命令可以远程登录主机
// root :是登录主机所属用户
// 172.254.23.xxx:主机的ip地址
ssh -v 192.168.0.x -p 3306 // 查看端口是否可访问
// 在登录之前,主机要执行以下服务
systemctl stop firewalls.service // 关闭防火墙
systemctl start sshd // 开启ssh服务
Linux查看服务运行状态
systemctl list-unit-files // 查看所有服务
systemctl status mariadb.service // 查看mariadb数据库的状态
systemctl start mariadb.service // 启动
tar命令-打包操作
当 tar 命令用于打包操作时,该命令的基本格式为:
[root@localhost ~]#tar [选项] 源文件或目录
| 选项 | 含义 |
|---|---|
| -c | 将多个文件或目录进行打包。 |
| -A | 追加 tar 文件到归档文件。 |
| -f 包名 | 指定包的文件名。包的扩展名是用来给管理员识别格式的,所以一定要正确指定扩展名; |
| -v | 显示打包文件过程; |
在使用 tar 命令指定选项时可以不在选项前面输入“-”。例如,使用“cvf”选项和 “-cvf”起到的作用一样。
【例 1】打包文件和目录
[root@localhost ~]# tar -cvf anaconda-ks.cfg.tar anaconda-ks.cfg
// 把anacondehks.cfg 打包为 anacondehks.cfg.tar文件
选项 "-cvf" 习惯用法,打包时需要指定打包之后的文件名,而且要 ".tar" 作为扩展名;
【例 2】打包并压缩目录
打包目录:
[root@localhost ~]# ll -d test/
drwxr-xr-x 2 root root 4096 6月 17 21:09 test/
// test是我们之前的测试目录
[root@localhost ~]# tar -cvf test.tar test/
test/
test/test3
test/test2
test/test1
// 把目录打包为test.tar文件
tar命令也可以打包多个文件或目录,只要用空格分开即可。例如:
[root@localhost ~]# tar -cvf ana.tar anaconda-ks.cfg /tmp/
// 把anaconda-ks.cfg文件和/tmp目录打包成ana.tar文件包
压缩目录:
声明一点,压缩命令不能直接压缩目录,必须先用 tar 命令将目录打包,然后才能用 gzip 命令或 bzip2 命令对打包文件进行压缩
[root@localhost ~]#ll -d test test.tar
drwxr-xr-x 2 root root 4096 6月 17 21:09 test
-rw-r--r-- 1 root root 10240 6月 18 01:06 test.tar
// 我们之前已经把test目录打包成test.tar文件
[root@localhost ~]# gzip test.tar
[root@localhost ~]# ll test.tar.gz
-rw-r--r-- 1 root root 176 6月 18 01:06 test.tar.gz
// gzip命令会把test.tar压缩成test.tar.gz
tar命令-解打包操作
命令的基本格式如下:
[root@localhost ~]#tar [选项] 压缩包
常用的选项与含义所示:
| 选项 | 含义 |
|---|---|
| -x | 对 tar 包做解打包操作。 |
| -f | 指定要解压的 tar 包的包名。 |
| -t | 只查看 tar 包中有哪些文件或目录,不对 tar 包做解打包操作。 |
| -C 目录 | 指定解打包位置。 |
| -v | 显示解打包的具体过程。 |
解打包和打包相比,只是把打包选项 "-cvf" 更换为 "-xvf":
[root@localhost ~]# tar -xvf anaconda-ks.cfg.tar
// 解打包到当前目录下
如果使用 "-xvf" 选项,则会把包中的文件解压到当前目录下。如果想要指定解压位置,则需要使用 "-C(大写)" 选项
[root@localhost ~]# tar -xvf test.tar -C /tmp
// 把文件包test.tar解打包到/tmp/目录下
如果只想查看文件包中有哪些文件,则可以把解打包选项 "-x" 更换为测试选项 "-t"
[root@localhost ~]# tar -tvf test.tar
drwxr-xr-x root/root 0 2016-06-17 21:09 test/
-rw-r-r- root/root 0 2016-06-17 17:51 test/test3
-rw-r-r- root/root 0 2016-06-17 17:51 test/test2
-rw-r-r- root/root 0 2016-06-17 17:51 test/test1
// 格式显示test.tar文件包中文件的详细信息
当 tar 命令同时做打包压缩的操作时,其基本格式如下:
[root@localhost ~]#tar [选项] 压缩包 源文件或目录
常用的选项有以下 2 个:
- -z:压缩和解压缩 ".tar.gz" 格式;
- -j:压缩和解压缩 ".tar.bz2"格式。
【例 1】压缩与解压缩 ".tar.gz"格式:
[root@localhost ~]# tar -zcvf tmp.tar.gz /tmp/
// 把/temp/目录直接打包压缩为".tar.gz"格式,通过"-z"来识别格式,"-cvf"和打包选项一致
解压缩也只是在解打包选项 "-xvf" 前面加了一个 "-z" 选项
[root@localhost ~]# tar -zxvf tmp.tar.gz
// 解压缩与解打包".tar.gz"格式
前面选项 "-C" 用于指定解压位置、"-t" 用于查看压缩包内容,在这里同样适用
【例 2】压缩与解压缩 ".tar.bz2" 格式
[root@localhost ~]# tar -jcvf tmp.tar.bz2 /tmp/
// 打包压缩为".tar.bz2"格式,注意压缩包文件名
[root@localhost ~]# tar -jxvf tmp.tar.bz2
// 解压缩与解打包".tar.bz2"格式