大数据Linux必知必会 -02
source link: https://blog.51cto.com/u_15316078/5516583
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
8 网络配置
8.1 静态ip设置
-
配置文件地址:/etc/sysconfig/network-scripts/ifcfg-ens33
- reboot重启下生效
8.2 修改linux主机名
- 修改配置文件下的主机名/etc/hostname
[root@hadoop ~]# vim /etc/hostname
- 修改映射文件/etc/sysconfig/network
[root@hadoop ~]# vim /etc/sysconfig/network
- 增加ip和主机名的映射/etc/hosts
[root@hadoop ~]# vim /etc/hosts
- 重启然后ping一下
8.3 windows下通过主机名来连接虚拟机
- 修改映射文件:C:\Windows\System32\drivers\etc找到hosts文件
- 然后用windows的cmd ping看看
9 进程管理
9.1 查看进程
- 查看进程执行
- ps -aux
[root@hadoop ~]# ps -aux | more
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2 0.0 0.0 0 0 ? S 04:25 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 04:25 0:00 [ksoftirqd/0]
[root@hadoop ~]# ps -aux | grep sshd
root 9199 0.0 0.1 112756 4312 ? Ss 04:25 0:00 /usr/sbin/sshd -D
root 9771 0.0 0.1 157152 5904 ? Ss 04:33 0:00 sshd: root@pts/0
root 9795 0.0 0.0 112708 972 pts/0 R+ 04:36 0:00 grep --color=auto sshd
- 查看父进程
- ps -ef
[root@hadoop ~]# ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 2 0 0 04:25 ? 00:00:00 [kthreadd]
root 3 2 0 04:25 ? 00:00:00 [ksoftirqd/0]
- 以树状形式显示进程
- pstree -p 显示进程ID
- pstree -u 显示进程所属用户
[root@hadoop ~]# pstree -p | more
systemd(1)-+-NetworkManager(8492)-+-{NetworkManager}(8602)
| `-{NetworkManager}(8608)
|-agetty(8588)
|-anacron(9932)
|-auditd(7936)---{auditd}(7938)
|-crond(8534)
[root@hadoop ~]# pstree -u | more
systemd-+-NetworkManager---2*[{NetworkManager}]
|-agetty
|-anacron
|-auditd---{auditd}
9.2 终止进程
- kill 进程号
- kill -9 进程号
[root@hadoop ~]# yum install pstree
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 9803.
Another app is currently holding the yum lock; waiting for it to exit...
[root@hadoop ~]# kill -9 9803
[root@hadoop ~]# yum -y install psmisc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
9.3 服务管理
- 查看与修改防火墙情况
- systemctl status firewalld 查看防火墙情况 老版:service iptables status
- systemctl start status 打开防火墙 老版:service iptables restart
- systemctl stop status 关闭防火墙 老版:service iptables stop
[root@hadoop ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@hadoop ~]# systemctl start firewalld
[root@hadoop ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2022-07-26 05:36:20 CST; 32s ago
[root@hadoop ~]# systemctl stop firewalld
- (了解)用windows查看linux的端口监听情况
- firewall-cmd --list-ports
- firewall-cmd --zone=public --add-port=88/tcp --permanent
- firewall-cmd --zone=public --remove-port=88/tcp --permanent
- 使用windows telnet客户端登录,在cmd中输入:ip 端口号
- 查看自启动列表
- systemctl list-unit-files
[root@hadoop ~]# systemctl list-unit-files | more
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
9.4 监控服务
- 动态监控进程top
- top -d 秒数 没几秒就更新
[root@hadoop ~]# top
top - 06:07:15 up 1:41, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 98 total, 1 running, 97 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3861492 total, 3094872 free, 331136 used, 435484 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 3270292 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10709 root 20 0 161880 2188 1556 R 0.3 0.1 0:00.02 top
1 root 20 0 125460 3872 2604 S 0.0 0.1 0:01.12 systemd
[root@hadoop ~]# top -d 3
-
-
第一行:当前时间 开机截至运行时间 3个用户 负载均衡
-
第二行:总任务数 运行数 休眠数 停止数 僵尸进程数
-
第三行:cpu用户占用率 系统占用率 cpu空闲率
-
第四行:内存总和 内存使用 内存空闲
-
第五行:swap分区 当内存不够用了,才会用swap分区
-
输入u可以选择看哪一位用户
-
输入k终止指定的进程号
-
可以按照cpu使用率§,内存(M),PID排序(N),退出(Q)
-
- 查看系统网络情况
-
netstat -anp
-
netstat -tunlp 端口占用情况
[root@hadoop ~]# netstat -anp | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 9199/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 9510/master
tcp 0 36 192.168.60.102:22 192.168.60.1:12424 ESTABLISHED 10690/sshd: root@pt
看下内容表示:linux有个端口22在监听,是192.168.60.1通过xshell远程登陆了
[root@hadoop ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 9199/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 9510/master
tcp6 0 0 :::3306 :::* LISTEN 9301/mysqld
tcp6 0 0 :::22 :::* LISTEN 9199/sshd
tcp6 0 0 ::1:25 :::* LISTEN 9510/master
10 RPM包和YUM包管理
10.1 rpm包的管理
- rpm包的查看
-
rpm -qa 查看已安装的列表
-
rpm -qi 软件包名 查询已安装的rpm包软件的版本信息
-
rpm -ql 软件包名 查询软件包中的文件
-
rpm -qf 文件全路径 查询文件所属的哪个软件包
[root@hadoop ~]# rpm -qa | grep ssh
openssh-clients-7.4p1-16.el7.x86_64
openssh-server-7.4p1-16.el7.x86_64
libssh2-1.4.3-12.el7.x86_64
openssh-7.4p1-16.el7.x86_64
[root@hadoop ~]# rpm -qi openssh
Name : openssh
Version : 7.4p1
Release : 16.el7
[root@hadoop ~]# rpm -ql openssh
/etc/ssh
/etc/ssh/moduli
/usr/bin/ssh-keygen
/usr/libexec/openssh
[root@hadoop ~]# rpm -qf /etc/passwd
setup-2.8.71-10.el7.noarch
- rpm包的卸载
- rpm -e 软件包名
[root@hadoop ~]# rpm -e firefox
- rpm包的安装
-
rpm -lvh 包全路径名称
-
-
虚拟机:光驱挂载
-
然后挂载完成会显示再media中,查看
-
拷贝到/opt
-
安装
-
10.2 YUM包
- yum list | grep 软件名 查看yum服务器是否有需要安装的软件
- yum install xxx 下载安装
- rm -f /var/run/yum.pid 出现yum占用的解决方法
[root@hadoop ~]# yum list | more
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.dgut.edu.cn
* extras: mirrors.dgut.edu.cn
* updates: mirrors.ustc.edu.cn
Installed Packages
GeoIP.x86_64 1.5.0-13.el7 @anaconda
[root@hadoop ~]# yum install firefox
Complete!
[root@hadoop ~]# rm -f /var/run/yum.pid
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK