一、初步接触
1.网卡开机自动启动:
查询IP地址后,可以转远程连接进行相关命令编辑
- 命令语句
vi /etc/sysconfig/network-scripts/ifcfg-ens33
- 相关配置中将ONBOOT=on改为ONBOOT="yes",执行保存并退出
补充知识:在世纪工作网卡名称根据实际情况进行更改。
2.时间配置
date查询时间配置情况,当当前时间不符要求,根据配置需要进行相关配置
- 如果无时间服务器需要先进行相关程序安装
[root@localhost ~]# yum install nepdate
- 在配置结束后,可以同步相应服务器的时间如
[root@localhost ~]# ntpdate time.windows.com
- 阿里云时间
[root@localhost ~]# ntpdate ntp.aliyun.com
如果需要自己手动设置时间,则
[root@localhost ~]# hwclock --set --date "2020-01-01 12:12:12"
[root@localhost ~]# hwclock -r
2020年01月01日 星期三 12时16分25秒 -0.896742 秒
更改结束依然使用:wq进行设置保存
扩展:
[root@localhost ~]# hwclock --systohc 系统时间同步硬件
[root@localhost ~]# hwclcck --hctosys 硬件时间同步系统
3.关闭防火墙
- 确认网络连接情况(Ctrl键+c终止任何查询)
[root@localhost ~]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=128 time=27.5 ms
- 关闭防火墙
[root@localhost ~]# systemctl stop firewalld
- 确认防火墙关闭情况
ystemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 二 2024-03-26 21:00:13 CST; 2min 18s ago
Docs: man:firewalld(1)
Process: 705 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 705 (code=exited, status=0/SUCCESS)
3月 26 19:44:55 localhost.localdomain systemd[1]: ...
3月 26 19:44:56 localhost.localdomain systemd[1]: ...
3月 26 19:44:57 localhost.localdomain firewalld[705]: ...
3月 26 21:00:12 localhost.localdomain systemd[1]: ...
3月 26 21:00:13 localhost.localdomain systemd[1]: ...
Hint: Some lines were ellipsized, use -l to show in full.
- 开启防火墙
systemctl start firewalld [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since 二 2024-03-26 21:04:38 CST; 1min 7s ago Docs: man:firewalld(1) Main PID: 9130 (firewalld) CGroup: /system.slice/firewalld.service └─9130 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid 3月 26 21:04:38 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewal..... 3月 26 21:04:38 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall...n. 3月 26 21:04:38 localhost.localdomain firewalld[9130]: WARNING: AllowZoneDrifting is en.... Hint: Some lines were ellipsized, use -l to show in full.
- 取消防火墙开机自动启动设置
[root@localhost ~]# systemctl disable firewalld
- 临时关闭防火墙
[root@localhost ~]# setenforce 0 [root@localhost ~]# setenforce 1
- 永久关闭防火墙
-
[root@localhost ~]# vi /etc/selinux/config bled # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted ~ ~ ~ ~ :wq
- 查看状态
[root@localhost ~]# getenforce
4.快照
- 在虚拟服务器中进行对应时间的快照操作
如果出现问题,可以通过恢复前面的快照,恢复快照时的指令
5.路径-目录的创建
- Ls 查看当前路径
- Ls /中国 查看路径下中国文件
- CD切换目录
- Cd .. 返回上一级目录
- Cd . 当前目录
- Cd ../.././点点数量返回次数,比如在西安,通过此返回到西安。
- Cd -返回上一次进入的目录
- CD /中国 切换到中国的路径
- Pwd 查看当前所在目录(查看绝对路径,即/中国/陕西)
- Mkdir 创建目录
- Mkdir /a 在根下创建的目录
- Mkdir a 在所在目中创建的一个小小根
- Mkdir -p 直接在用户名下指定根下创建目录
- Mkdir -p /01/01/{01,02}
- Mkdir-v查看创建过程
- Yum install tree 安装tree
[root@localhost /]# ls 01 boot etc lib media proc run srv tmp var 学习 bin dev home lib64 mnt root sbin sys usr zhongguo 中国 [root@localhost /]# [root@localhost /]# mkdir -p /opt/a/b/c [root@localhost /]# tree /opt /opt └── a └── b └── c 3 directories, 0 files
touch 创建文本
-
[root@localhost home]# touch /opt/file.txt [root@localhost home]# tree /opt /opt ├── a └── file.txt 1 directory, 1 file
查找小知识:当yum关闭,执行rm -f /var/run/yum.pid后正常进行yum安装的内容
终端连接到服务器重要使用IP进行连接,使用的是ssh进行协议连接,ssh root @192.168.42.125(端口号22位)
6.文件拷备
拷贝主要使用命令词cp
[root@localhost /]# cp -r /opt/a /tmp
[root@localhost /]# cd /tmp
[root@localhost tmp]# ls
a
ks-script-6_CVQf
systemd-private-21884cc5cf934fa897803901bc0c5010-chronyd.service-9VXlBi
systemd-private-278a64b471014c7c9e06255891e9db60-chronyd.service-V6LscI
systemd-private-4ba49a680b2143acad4b4f22972a738d-chronyd.service-cpie7T
systemd-private-7700d0306cf04fa7974aded2a5b4163b-chronyd.service-hqtM4M
systemd-private-7d007bbf789a46f98aae0f9ce4b79c59-chronyd.service-EpYhNT
systemd-private-90d6be988e1a4f04a156c442b76d1669-chronyd.service-Mo5Xuj
systemd-private-a03007a2665542b192b481f04ec40f07-chronyd.service-0fQMtS
systemd-private-d2783f5906cf4b6ba77272eed962d29f-chronyd.service-xaDnqE
systemd-private-f86f9439466540fe8135d13c42f5605b-chronyd.service-VB5RIR
yum.log
扩展:在复制中,可以对复制的内容进行重命名 (cp -r /otp/a /tmp/a-1)
7.文件移动
拷贝主要使用命令词mv
[root@localhost opt]# cd /home
[root@localhost home]# ls
etc ifcfg-ens33 passwd tt yun
8.文件删除
拷贝主要使用命令词rm
[root@localhost c]# rm -rf /opt/a/b
[root@localhost opt]# tree /opt/a
/opt/a
0 directories, 0 files
[root@localhost opt]# tree /opt
/opt
└── a
1 directory, 0 files
9.绝对路径与相对路径
相对路径
[root@localhost tmp]# cd
[root@localhost ~]# cd /
[root@localhost /]# cd opt
[root@localhost opt]# cd a
[root@localhost a]# cd b
[root@localhost b]# cd c
[root@localhost c]# cd ..
[root@localhost b]# cd ../../..
[root@localhost /]# cd otp
-bash: cd: otp: 没有那个文件或目录
[root@localhost /]# cd opt
[root@localhost opt]# tree
.
└── a
└── b
└── c
3 directories, 0 files
绝对路径
[root@localhost ~]# cd /opt/a/b/c
[root@localhost c]#
10.查看各个指定路径下的文件
使用代码 tree
[root@localhost home]# tree /etc/sysconfig
/etc/sysconfig
├── anaconda
├── authconfig
├── cbq
│ ├── avpkt
│ └── cbq-0000.example
├── chronyd
├── console
├── cpupower
├── crond
├── ebtables-config
├── firewalld
├── grub -> ../default/grub
├── init
├── ip6tables-config
├── iptables-config
├── irqbalance
├── kdump
├── kernel
├── man-db
├── modules
├── netconsole
├── network
├── network-scripts
│ ├── ifcfg-lo
│ ├── ifdown -> ../../../usr/sbin/ifdown
│ ├── ifdown-bnep
│ ├── ifdown-eth
│ ├── ifdown-ippp
│ ├── ifdown-ipv6
│ ├── ifdown-isdn -> ifdown-ippp
│ ├── ifdown-post
│ ├── ifdown-ppp
│ ├── ifdown-routes
│ ├── ifdown-sit
│ ├── ifdown-Team
│ ├── ifdown-TeamPort
│ ├── ifdown-tunnel
│ ├── ifup -> ../../../usr/sbin/ifup
│ ├── ifup-aliases
│ ├── ifup-bnep
│ ├── ifup-eth
│ ├── ifup-ippp
│ ├── ifup-ipv6
│ ├── ifup-isdn -> ifup-ippp
│ ├── ifup-plip
│ ├── ifup-plusb
│ ├── ifup-post
│ ├── ifup-ppp
│ ├── ifup-routes
│ ├── ifup-sit
│ ├── ifup-Team
│ ├── ifup-TeamPort
│ ├── ifup-tunnel
│ ├── ifup-wireless
│ ├── init.ipv6-global
│ ├── network-functions
│ └── network-functions-ipv6
├── ntpdate
├── rdisc
├── readonly-root
├── rsyslog
├── run-parts
├── selinux -> ../selinux/config
├── sshd
└── wpa_supplicant
4 directories, 61 files
二、指令汇总
1. cp
2. mv
3. rm
4. ls
5. cd
6. pwd
7. date
8. mkdir
9. touch
10. clear / ctrl + L
11. hwclock
12. ntpdate
13. getenforce
14. setenforce
15. systemctl [status|start|stop|disable|enable|restart] $service_name
16. tree
17. ifup
18. ifdown
19. ip a
20. ssh
21. ctrl + c
22. exit/ ctrl + d
23. reboot
24. table /
25. vi/
三、作业
3.27
8、rm /opt/a/
9、rm /opt/file1.txt
10、mv /opt/a/ /home/
11、mv /opt/a/file1.txt /home
12、cp /opt/a/ /home/b/
13、cp /opt/a/file.txt /home/hhhh.txt
8.删除内容文件中含有子文件,删除不成功,需要使用rm -r 或者rm -rf进行删除操作,前者需要确认,后者强制删除。
9.删除指定文件夹下文本内容,使用rm /opt/file1.txt,可以正常删除
10.移动文件夹,如果不含子文件夹,使用语句能够成功,如果含有子文件夹,则需要使用MV -r 进行操作
11.可以操作成功
12.操作不成功
13.可以操作成功 将根下文本file复制到HOME中且重新命名为hhh