linux课程笔记2

222 阅读2分钟


rpm包

  • rmp -i   vim-enhanced-7.4.rpm
  • rpm -e vim-enhanced.rpm

yum命令常用选项

    wget  -o     拉取repo文件覆盖当前文件

    yum install

    yum remove

    yum upgrade

源代码编译安装

示例程序

  • wget https://openresty.org/download/openresty-11.5.8.tar.gz
  • tar -zxf openresty-11.5.8.tar.gz
  • cd openresty-VERSION
  • ./configure --prefix=/usr/local/openresty
  • make -j2
  • make  install


进程管理

进程---运行中的程序

  • 查看进程命令
    • ps
      • ps -ef | more
    • pstree
    • top  动态查看进程信息
      • top -p 18888

进程优先级

  • nice -n 10 ./a.sh 
  • renice -n 15 19888  &

进程通信

信号

  • kill -l 查看所有信号
  • kill -9 229876
  • pkill 

守护进程

  • 使用nohup与& 符号配合运行一个命令
    • nohup命令使进程忽略hangup(刮起)信号
  • 守护进程daemon
  • screen命令

服务管理工具systemctl

服务:常见功能的守护进程

  • service  服务
  • systemctl
    • systemctl start | stop | restart | reload | enable | disable 服务名称
    • 软件包安装的服务单元  /usr/lib/systemd/system/


内存和磁盘管理

内存查看

  • free
    • free -m
  • top

磁盘使使用率

  • fdisk
    • fdisk -l

常见的文件系统

linux常见的多种文件系统

  • ext4
  • xfs
  • NTFS

Shell--命令解释器

linux启动过程

BIOS-MBR-BootLoader(grub)-kernel-systemd-系统初始化-shell

UNIX的哲学:一条命令只做一件事


重定向符号

  • 输入重定向 “<”
  • 输出充电向“>” ">>" "2>" "&>"
  • 输入输出组合重定向
    • cat > /path/to/a/file <<EOF
    • i am $USER
    • EOF

变量

变量的引用

  • ${变量名}  对变量的引用
  • echo ${变量名}  查看变量的值
  • ${变量名} 在部分情况下可以省略 $变量名


环境变量

配置文件

  • /etc/profile
  • /etc/profile.d/
  • ~/.bash_proflie
  • ~/.bashrc
  • /etc/bashrc

etc 下所有用户通用配置文件。

~ 用户家目录,特定用户,单独使用。

profile    su区分

bashrc    su -  切换用户是会执行


source   /etc/bashrc     重新运行加载配置文件


捕获信号

  • kill  默认发送15号信号
  • ctrl+c  发送2号信号
  • 9 号信号不可阻塞


计划任务-定时任务

  • 一次性任务 at
  • 周期性任务crontab
    • crontab -e 配置一个任务
    • crontab -l 看任务列表
  • flock  为脚本加锁


扩展元字符

  • +
  • |


文件查找命令

find

  • find 路径 查找条件
    • eg:find  /etc -name   passwd*
    • eg:find  /etc -regex   .*wd

grep


sed和awk介绍

行编辑器

  • sed 一般用于对文本内容做替换
    • sed   's/oldstring/newstring/' filename   
    • sed -e  's/oldstring/newstring/'  -e  's/oldstring/newstring/'  filename 替换多个
    • sed -i  's/oldstring/newstring1/'  's/oldstring/newstring2/'  filename
  • awk 一般用于对文本内容进行统计
    • awk中,使用$1 $2 ... $n 标识每一个字段
    • awk -f:'/'


服务管理

  • iptables 的表和链
  • iptables 的filter表
  • iptables 的nat 表
  • iptables 配置文件
  • firewallD 服务 (底层是使用netfilter)
    • 支持zone的概念
    • firewall-cmd
  • systemctl  start | stop | entable| disable | status   firewalld.service


ssh服务

telnet的问题,传输明文

  1. grep telnet /etc/services
  2. iptables -I INPUT -p tcp --dport 23 -j ACCEPT
  3. firewall-cmd --permanent --add-port=23/tcp
  4. firewall-cmd --list-all

配置文件sshd_config  默认端口:22


SSH公钥认证

常用命令

  • ssh-keygen  -t   rsa
  • ssh-copy-id        拷贝公钥到服务器
    • scp   kpi.txt   root@10.211.5.3:/destdirectory/
    • scp   root@10.211.5.3:/root/dest/kpi.txt         /tmp/k.txt


FTP服务

文件传输协议

yum install vsftpd ftp

systemctl start vsftpd.service


vsftpd配置文件

  • /etc/vsftpd/vsftpd.conf
  • /etc/vsftpd/ftpusers
  • /etc/vsftpd/user_list


NFS服务

linux 之间文件共享

  • /etc/exports
    • /data/share  *(rw,sync,all_squash)
  • showmount -e localhost
  • 客户端使用挂载方式访问
    • mount -t nfs localhost:/data/share/ent
  • 启动NFS服务
    • systemctl start | stop nfs.service



nginx和web服务协议

openResty是基于Nginx和Lua实现的web应用网关,集成了大量的第三方模块

  • service openresty start | stop | restart | reload
  • /usr/local/openresty/nginx/conf/nginx.conf


LNMP

lamp环境: ( linux + apache + mysql + php)

lnmp (apache -> Nginx)


mysql -> mariadb