Linux学习笔记
文件系统管理
磁盘管理
操作步骤
- 磁盘分区
- 格式化写入文件系统
- 建立挂载点并挂载
- 开机自动挂载
实例详解
添加一块新的硬盘或者格式化已有硬盘建立分区
如果格式化现有磁盘需要先使用fdisk -l查看设备号以及现有分区详情,然后使用umount命令取消挂载,最后使用mkfs格式化磁盘。
- 使用
fdisk -l命令查看磁盘设备号如/dev/sdb代表SATA接口第二块硬盘 - 使用
fdisk /dev/sdb命令新建分区,注意点:
- 主分区最多只能有4个
- 扩展分区最多只有1个
- 扩展分区包含逻辑分区
n新建分区p主分区e扩展分区l文件系统p查看分区w保存退出
[root@localhost ~]# fdisk /dev/sdb欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。Device does not contain a recognized partition table使用磁盘标识符 0xe3bd2259 创建新的 DOS 磁盘标签。命令(输入 m 获取帮助):m命令操作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)命令(输入 m 获取帮助):nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): p分区号 (1-4,默认 1):1起始 扇区 (2048-41943039,默认为 2048):将使用默认值 2048Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+5G分区 1 已设置为 Linux 类型,大小设为 5 GiB命令(输入 m 获取帮助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): e分区号 (2-4,默认 2):2起始 扇区 (10487808-41943039,默认为 10487808):将使用默认值 10487808Last 扇区, +扇区 or +size{K,M,G} (10487808-41943039,默认为 41943039):将使用默认值 41943039分区 2 已设置为 Extended 类型,大小设为 15 GiB命令(输入 m 获取帮助):nPartition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5)Select (default p): l添加逻辑分区 5起始 扇区 (10489856-41943039,默认为 10489856):将使用默认值 10489856Last 扇区, +扇区 or +size{K,M,G} (10489856-41943039,默认为 41943039):将使用默认值 41943039分区 5 已设置为 Linux 类型,大小设为 15 GiB命令(输入 m 获取帮助):p磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0xe3bd2259 设备 Boot Start End Blocks Id System/dev/sdb1 2048 10487807 5242880 83 Linux/dev/sdb2 10487808 41943039 15727616 5 Extended/dev/sdb5 10489856 41943039 15726592 83 Linux命令(输入 m 获取帮助):wThe partition table has been altered!Calling ioctl() to re-read partition table.正在同步磁盘。[root@localhost ~]#
[root@localhost ~]# mkfs -t ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013)文件系统标签=OS type: Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1310720 blocks65536 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成 [root@localhost ~]# mkfs -t ext4 /dev/sdb5mke2fs 1.42.9 (28-Dec-2013)文件系统标签=OS type: Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks983040 inodes, 3931648 blocks196582 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=2151677952120 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成 [root@localhost ~]#
[root@localhost ~]# mkdir /mnt/disk1[root@localhost ~]# mkdir /mnt/disk5[root@localhost ~]# mount /dev/sdb1 /mnt/disk1[root@localhost ~]# mount /dev/sdb5 /mnt/disk5[root@localhost ~]# [root@localhost ~]# df -h文件系统 容量 已用 可用 已用% 挂载点devtmpfs 893M 0 893M 0% /devtmpfs 910M 0 910M 0% /dev/shmtmpfs 910M 11M 900M 2% /runtmpfs 910M 0 910M 0% /sys/fs/cgroup/dev/mapper/centos-root 17G 5.1G 12G 30% //dev/sda1 1014M 185M 830M 19% /boottmpfs 182M 12K 182M 1% /run/user/42tmpfs 182M 0 182M 0% /run/user/1000/dev/sdb1 4.8G 20M 4.6G 1% /mnt/disk1/dev/sdb5 15G 41M 14G 1% /mnt/disk5[root@localhost ~]#
- 查看磁盘UUID命令
[root@localhost ~]# dumpe2fs /dev/sdb1Filesystem UUID: 88c14ee3-5a32-4a7a-b1a1-7cc2960ada1c
或者
[root@localhost ~]# ls -l /dev/disk/by-uuid/lrwxrwxrwx. 1 root root 10 3月 21 16:47 88c14ee3-5a32-4a7a-b1a1-7cc2960ada1c -> ../../sdb1lrwxrwxrwx. 1 root root 10 3月 21 16:47 ecac7767-4f99-4a5d-9d7a-02da01ed8fa1 -> ../../sdb5
或者
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot└─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP]sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part /mnt/disk1sdc 8:32 0 2G 0 disk └─sdc1 8:33 0 2G 0 part [SWAP]sr0 11:0 1 1024M 0 rom [root@localhost ~]# lsblk -fNAME FSTYPE LABEL UUID MOUNTPOINTsda ├─sda1 xfs 9a7dacf4-45c0-413a-b6f0-537e19e9c3d6 /boot└─sda2 LVM2_member Ffcj1s-CAnE-sAgl-MKE0-3cVL-jrgz-3KyGXU ├─centos-root xfs bb5c7b68-def4-4f70-baee-ebb05df528be / └─centos-swap swap 09c2c687-dcbb-401c-a393-155b43233386 [SWAP]sdb └─sdb1 ext4 1a6c90a5-3a4d-49d3-9550-1db6b4536040 /mnt/disk1sdc └─sdc1 swap 158a1eee-17e1-47a7-94dd-840c84d4d843 [SWAP]sr0
- 修改
/etc/fstab文件来实现自动挂载
[root@localhost ~]# vim /etc/fstab UUID=88c14ee3-5a32-4a7a-b1a1-7cc2960ada1c /mnt/disk1 ext4 defaults 0 0UUID=ecac7767-4f99-4a5d-9d7a-02da01ed8fa1 /mnt/disk5 ext4 defaults 0 0#第一列 设备文件名或者UUID#第二列 挂载点#第三列 文件系统#第四列 挂载选项#第五列 是否可以备份 0不备份 1每天备份 2不定期备份#第六列 是否检测磁盘fsck 0不检测 1启动时检测 2启动后检测
- 重启测试或者
mount -a重新挂载所有内容
补充对GPT分区表操作
[root@localhost ~]# parted /dev/sdb GNU Parted 3.1Using /dev/sdbWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) help align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resizepart NUMBER END resize partition NUMBER rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted(parted) print Error: /dev/sdb: unrecognised disk labelModel: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GBSector size (logical/physical): 512B/512BPartition Table: unknownDisk Flags: (parted) mklabel gpt (parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 21.5GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags(parted) mkpart Partition name? []? disk1 File system type? [ext2]? Start? 1MBEnd? 5GB(parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 21.5GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 5000MB 4999MB disk1(parted) quit[root@localhost ~]# mkfs -t ext4 /dev/sdb1[root@localhost ~]# mkdir /mnt/disk1[root@localhost ~]# mount /dev/sdb1 /mnt/disk1[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sdb1 4.5G 19M 4.2G 1% /mnt/disk1
增加swap分区
[root@localhost ~]# fdisk /dev/sdcWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0xa48a01dd.Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): First sector (2048-4194303, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): Using default value 4194303Partition 1 of type Linux and of size 2 GiB is setCommand (m for help): tSelected partition 1Hex code (type L to list all codes): 82Changed type of partition 'Linux' to 'Linux swap / Solaris'Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.Command (m for help): p Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xa48a01dd Device Boot Start End Blocks Id System/dev/sdc1 2048 4194303 2096128 82 Linux swap / Solaris
[root@localhost ~]# mkswap /dev/sdc1 Setting up swapspace version 1, size = 2096124 KiBno label, UUID=158a1eee-17e1-47a7-94dd-840c84d4d843[root@localhost ~]# free total used free shared buff/cache availableMem: 1863004 231820 1436800 9764 194384 1476888Swap: 2097148 0 2097148[root@localhost ~]# swapon /dev/sdc1 [root@localhost ~]# free total used free shared buff/cache availableMem: 1863004 233404 1435192 9764 194408 1475304Swap: 4193272 0 4193272
- 修改
/etc/fstab文件实现swap分区开机自动挂载
[root@localhost ~]# vim /etc/fstab UUID=158a1eee-17e1-47a7-94dd-840c84d4d843 swap swap defaults 0 0[root@localhost ~]# mount -a[root@localhost ~]# free total used free shared buff/cache availableMem: 1863004 233984 1432128 9764 196892 1474724Swap: 4193272 0 4193272
基本操作命令
压缩和解压缩
gzip/gunzip命令
[root@localhost ~]# gzip home.zip[root@localhost ~]# gunzip home.zip.gz
zip/unzip命令
zip [选项] [目的文件名] [源文件或目录名]zip -r home.zip /home
unzip [选项] [目的目录名] [源文件名]unzip -d /tmp/home home.zip
tar指令
| 选项 |
功能备注 |
| -z |
通过gzip指令压缩/解压缩文件,文件名后缀需为.tar.gz |
| -c |
建立新的.tar备份文件 |
| -x |
解压包.tar文件 |
| -v |
显示过程信息 |
| -f |
指定压缩后的备份文件名 |
| -C |
可用于指定目录下的压缩/解压缩操作 |
tar -zcvf [目的文件名.tar.gz] [源文件或目录名]tar -zcvf home.tar.gz cat.txt dog.txt
tar -zxvf [源文件名.tar.gz] -C [指定目录]tar -zxvf home.tar.gz -C /opt/home/
crond任务调度
crontab指令
| 选项 |
说明 |
| -e |
编辑crontab定时任务 |
| -l |
查询crontab任务 |
| -r |
删除当前用户的crontab任务 |
crontab -e* * * * * ls -l /etc/ > /tmp/etc.txt#分 时 日 月 周 执行命令
| 占位符 |
含义 |
范围 |
| minute |
一小时当中的第几分钟 |
[0-59] |
| hour |
一天当中的第几小时 |
[0-23] |
| day |
一个月当中的第几天 |
[1-31] |
| month |
一年当中的第几月 |
[1-12] |
| week |
一周当中的星期几(0&7都表示星期日) |
[0-7] |
| 特殊符号 |
含义 |
| * |
代表任何时间。例如第一个*表示一小时中每分钟都执行一次。 |
| , |
代表不连续的时间。例如0 2,4,6 * * * command表示每天2、4、6点整执行。 |
| - |
代表连续的时间范围。例如0 5 * * 0-6 command表示每天的凌晨5点整执行。 |
| */n |
代表每隔多久执行一次。例如*/10 * * * * command表示每10分钟执行一次。 |
at定时任务
检测at进程是否运行
[root@localhost ~]# ps -ef | grep atdroot 1841 1823 0 19:31 pts/0 00:00:00 grep --color=auto atd
at指令
| 选项 |
说明 |
| atq |
查看系统中的等待作业 |
| atrm/-d |
删除系统中的等待作业 |
| -f |
指定文件提交等待作业 |
参考实例
[root@localhost ~]# at now + 1 minat> /bin/ls -l > /tmp/test.txtat> <EOT>job 2 at Wed Apr 7 20:00:00 2021Can't open /var/run/atd.pid to signal atd. No atd running?[root@localhost ~]# atq1 Fri Apr 9 17:00:00 2021 a root2 Wed Apr 7 20:00:00 2021 a root[root@localhost ~]# atrm 2[root@localhost ~]# atq1 Fri Apr 9 17:00:00 2021 a root[root@localhost ~]# at -f py.sh 9pm 07/04/2021job 6 at Sun Jul 4 21:00:00 2021[root@localhost ~]# atq1 Fri Apr 9 17:00:00 2021 a root6 Sun Jul 4 21:00:00 2021 a root[root@localhost ~]#
网络配置
固定IP地址
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33BOOTPROTO="static"IPADDR=192.168.78.130NETMASK=255.255.255.0GATEWAY=192.168.78.2DNS1=223.5.5.5DNS2=119.29.29.29[root@localhost ~]# systemctl restart network
设置主机名和hosts映射
设置主机名
[root@localhost ~]# hostnamelocalhost.localdomain[root@localhost ~]# vim /etc/hostnamelocalhost.localdomain[root@localhost ~]# reboot
设置hosts映射
[root@localhost ~]# vim /etc/hosts[root@localhost ~]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.123.254 openwrt[root@localhost ~]# ping openwrtPING openwrt (192.168.123.254) 56(84) bytes of data.64 bytes from openwrt (192.168.123.254): icmp_seq=1 ttl=128 time=2.16 ms64 bytes from openwrt (192.168.123.254): icmp_seq=2 ttl=128 time=2.84 ms64 bytes from openwrt (192.168.123.254): icmp_seq=3 ttl=128 time=2.69 ms64 bytes from openwrt (192.168.123.254): icmp_seq=4 ttl=128 time=2.88 ms^C--- openwrt ping statistics ---4 packets transmitted, 4 received, 0% packet loss, time 3032msrtt min/avg/max/mdev = 2.165/2.648/2.883/0.287 ms[root@localhost ~]#
进程管理(重点)
查看进程:ps指令
| 选项 |
说明 |
| -a |
显示所有终端机下执行的程序,除阶段作业领导者 |
| -u |
列出属于该用户的程序的状况 |
| -x |
显示所有程序,不以终端机来区分 |
| -e |
显示所有程序 |
| -f |
显示UID,PPIP,C与STIME栏位 |
参考实例
[root@localhost ~]# ps -auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.3 128168 6800 ? Ss 19:30 0:04 /usr/lib/systemd/systemd[root@localhost ~]# ps -aux | grep sshdroot 1205 0.0 0.2 112936 4320 ? Ss 19:30 0:00 /usr/sbin/sshd -Droot 1731 0.0 0.2 158940 5532 ? Ss 19:31 0:00 sshd: luci [priv]luci 1781 0.0 0.1 158940 2460 ? S 19:31 0:01 sshd: luci@pts/0root 1782 0.0 0.2 158940 5508 ? Ss 19:31 0:00 sshd: luci [priv]luci 1803 0.0 0.1 158940 2324 ? S 19:31 0:00 sshd: luci@nottyroot 10735 0.0 0.0 112812 976 pts/0 R+ 23:39 0:00 grep --color=auto sshd
[root@localhost ~]# ps -efUID PID PPID C STIME TTY TIME CMDroot 1 0 0 19:30 ? 00:00:04 /usr/lib/systemd/systemd[root@localhost ~]# ps -ef | grep sshdroot 1205 1 0 19:30 ? 00:00:00 /usr/sbin/sshd -Droot 1731 1205 0 19:31 ? 00:00:00 sshd: luci [priv]luci 1781 1731 0 19:31 ? 00:00:01 sshd: luci@pts/0root 1782 1205 0 19:31 ? 00:00:00 sshd: luci [priv]luci 1803 1782 0 19:31 ? 00:00:00 sshd: luci@nottyroot 10783 1823 0 23:40 pts/0 00:00:00 grep --color=auto sshd
查看进程树:pstree指令
| 选项 |
说明 |
| -p |
显示进程的PID |
| -u |
显示进程的所属用户 |
[root@localhost ~]# yum install -y psmisc[root@localhost ~]# pstreesystemd─┬─NetworkManager───2*[{NetworkManager}] ├─VGAuthService ├─agetty ├─atd ├─auditd───{auditd} ├─crond ├─dbus-daemon───{dbus-daemon} ├─firewalld───{firewalld} ├─lvmetad ├─master─┬─pickup │ └─qmgr ├─polkitd───6*[{polkitd}] ├─rsyslogd───2*[{rsyslogd}] ├─sshd─┬─sshd───sshd───bash───sudo───bash───pstree │ └─sshd───sshd───sftp-server ├─systemd-journal ├─systemd-logind ├─systemd-udevd ├─tuned───4*[{tuned}] └─vmtoolsd───{vmtoolsd}[root@localhost ~]# pstree -pusystemd(1)─┬─NetworkManager(907)─┬─{NetworkManager}(924) │ └─{NetworkManager}(927) ├─VGAuthService(863) ├─agetty(736) ├─atd(1912) ├─auditd(659)───{auditd}(660) ├─crond(728) ├─dbus-daemon(688,dbus)───{dbus-daemon}(727) ├─firewalld(741)───{firewalld}(1030) ├─lvmetad(508) ├─master(1430)─┬─pickup(8378,postfix) │ └─qmgr(1432,postfix) ├─polkitd(681,polkitd)─┬─{polkitd}(731) │ ├─{polkitd}(732) │ ├─{polkitd}(734) │ ├─{polkitd}(737) │ ├─{polkitd}(738) │ └─{polkitd}(739) ├─rsyslogd(1208)─┬─{rsyslogd}(1247) │ └─{rsyslogd}(1248) ├─sshd(1205)─┬─sshd(1731)───sshd(1781,luci)───bash(1783)───sudo(1819+ │ └─sshd(1782)───sshd(1803,luci)───sftp-server(1808) ├─systemd-journal(485) ├─systemd-logind(685) ├─systemd-udevd(507) ├─tuned(1204)─┬─{tuned}(1625) │ ├─{tuned}(1626) │ ├─{tuned}(1630) │ └─{tuned}(1634) └─vmtoolsd(810)───{vmtoolsd}(875)
终止进程:kill/killall指令
kill [选项] 进程号kill -9 10101killall 进程名称killall gedit
服务管理
systemctl指令
- systemctl管理服务的默认路径
/usr/lib/systemd/system
systemctl [start | stop | restart | status] ServiceName
systemctl list-unit-files [ | grep ServiceName ]#查看服务开机启动状态,可选grep进行过滤systemctl is-enabled ServiceName#查看服务是否开机自启动systemctl enable ServiceName#设置服务开机自启systemctl disable ServiceName#关闭服务开机自启
service指令
- service管理服务的默认路径
/etc/init.d
service ServiceName [start | stop | restart | reload | status]
服务的运行级别(runlevel):
Linux系统7种运行级别,常用的级别为3和5
- 运行级别3:完全的多用户状态(有NFS),登录后进入控制台命令行模式
- 运行级别5:X11控制台,登录后进入图形GUI模式
开机流程
开机 -> BIOS -> /boot -> systemd -> 运行级别 -> 运行级别对应服务
设置运行级别
cat /etc/inittab#运行级别的默认文件systemctl get-default#查看默认的运行级别systemctl set-default [multi-user.target | graphical.target]#设置默认的运行级别为[多用户3/图形化5]
chkconfig指令
chkconfig --list [ | grep ServiceName ]#查看服务运行级别chkconfig --level [0-6] ServiceName [on | off]#修改服务运行级别reboot#重启生效
firewall指令
防火墙管理
firewall-cmd --query-port=[端口号/协议类型]#查询端口是否开放firewall-cmd --permanent --add-port=3306/tcpfirewall-cmd --permanent --remove-port=3306/tcp#打开或关闭端口firewall-cmd --reload#重载使之生效
动态监控进程
top指令
| 选项 |
说明 |
| -d |
指定刷新时间。默认3秒 |
| -i |
不显示任何闲置或者僵死进程 |
| -p |
指定进程ID监控某个进程的状态 |
交互操作说明
| 操作 |
功能 |
| P |
以CPU的使用率排序(默认) |
| M |
以内存的使用率排序 |
| N |
以PID排序 |
| u |
监视特定用户 |
| q |
退出top |
| k |
根据PID杀死进程 |
netstat指令
| 选项 |
说明 |
| -an |
按一定顺序排列输出 |
| -p |
显示哪个进程在调用 |
[root@localhost ~]# netstat -anp | grep sshdtcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1205/sshd tcp 0 0 192.168.78.130:22 192.168.78.1:11698 ESTABLISHED 1785/sshd: luci [pr tcp 0 36 192.168.78.130:22 192.168.78.1:11697 ESTABLISHED 1779/sshd: luci [pr tcp6 0 0 :::22 :::* LISTEN 1205/sshd unix 3 [ ] STREAM CONNECTED 23537 1785/sshd: luci [pr unix 3 [ ] STREAM CONNECTED 23389 1779/sshd: luci [pr unix 2 [ ] DGRAM 23533 1785/sshd: luci [pr unix 3 [ ] STREAM CONNECTED 21632 1205/sshd unix 3 [ ] STREAM CONNECTED 23388 1783/sshd: luci@pts unix 3 [ ] STREAM CONNECTED 23536 1808/sshd: luci@not unix 2 [ ] DGRAM 23385 1779/sshd: luci [pr
软件包或源管理
rpm包管理
rpm包的查询指令
rpm -qa#查询安装的rpm软件包rpm -qa | grep PackageName#过滤查询rpm软件包rpm -qi PackageName#查看rpm软件包详细信息rpm -ql PackageName#查询软件包中的文件位置rpm -qf /FilePath#查询文件所属rpm软件包
rpm包的卸载指令
rpm -e PackageNamerpm -e --nodeps PackageName#强制卸载忽略依提示
rpm包的安装指令
rpm -ivh /Path/PackageName#i=install 安装#v=verbose 提示#h=hash 进度
yum软件源管理
查询yum软件源中的rpm包
yum list | grep PackageName
安装指定的软件包
yum install PackageName
JavaEE开发环境部署
安装配置JDK
su -c "yum install java-1.8.0-openjdk-devel"
[root@localhost ~]# mkdir /usr/local/java[root@localhost ~]# tar -zxvf jdk-8u281-linux-x64.tar.gz -C /usr/local/java/[root@localhost ~]# cat >> /etc/profile <<EOF> export JAVA_HOME=/usr/local/java/jdk1.8.0_281> export CLASSPATH=.:${JAVA_HOME}/lib> export PATH=${JAVA_HOME}/bin:$PATH> EOF[root@localhost ~]# source /etc/profile[root@localhost ~]# javac -versionjavac 1.8.0_281[root@localhost ~]# java -versionjava version "1.8.0_281"Java(TM) SE Runtime Environment (build 1.8.0_281-b09)Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)[root@localhost ~]# javac hello.java [root@localhost ~]# java helloHello,World~
安装配置tomcat
[root@localhost ~]# wget https://apache.website-solution.net/tomcat/tomcat-8/v8.5.65/bin/apache-tomcat-8.5.65.tar.gz[root@localhost ~]# tar -zxvf apache-tomcat-8.5.65.tar.gz[root@localhost ~]# mv apache-tomcat-8.5.65 /usr/local/tomcat[root@localhost ~]# /usr/local/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcatUsing CATALINA_HOME: /usr/local/tomcatUsing CATALINA_TMPDIR: /usr/local/tomcat/tempUsing JRE_HOME: /usr/local/java/jdk1.8.0_281Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarUsing CATALINA_OPTS: Tomcat started.[root@localhost ~]# firewall-cmd --permanent --add-port=8080/tcp[root@localhost ~]# firewall-cmd --reload[root@localhost ~]# firewall-cmd --query-port=8080/tcpyes