Linux基础使用

Linux中,日志所在的位置:

  /var/log/messages     系统默认的日志

  /var/log/secure         记录用户的登录信息

查看日志的方法有很多 :head     tail    less

  推荐使用:less (一页一页查看文件内容) 数据量大时,使用less查看

    less的使用方法:   空格  : 表示下一页                b :上一页               q:退出

   重启命令: reboot

使用Linux时,上传和下载文件需要   安装包    yum install   lrzsz -y    (-y 表示不提示)

备注:  上传文件(Windows-->Linux): rz 然后按  enter 回车   选择文件                   下载文件(Linux-->Windows):    sz   文件名

查看安装的包:除了使用yum   ,也可以使用  rpm  -qa   [包名(可选)]

复制文件到其他机台的那个位置:    scp    文件路径     对应机台的ip : 路径

  比如:  scp  /etc/hosts     10.0.0.200:/opt     然后提示yes/no    然后输入密码即可

The authenticity of host '10.0.0.200 (10.0.0.200)' can't be established.
RSA key fingerprint is 9e:24:14:84:15:0a:00:b2:18:97:f6:b9:99:8d:5a:38.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.200' (RSA) to the list of known hosts.
root@10.0.0.200's password:
hosts        

Linux三剑客补充:(grep / sed /awk)  都支持正则表达式   grep通常使用egrep (对grep的扩展)

  egrep  常用来过滤文件中的想要的内容              sed  用于替换         awk   常用于取列和统计

用法:比如      ip a s eth0 | egrep  --color  '正则'             ip a s eth0 | awk 'NR==3{print $2}'

  备注:--color  表示匹配结果带颜色             

          awk的用法   '条件{动作}'           NR  表示哪一行         $2 表示哪一列

  多列:$2 $3   即可,中间可以加逗号(,)间隔每列的数值 或者使用("  ")

  awk 也可以指定分隔符        -F  分隔符    awk  -F "[/ ]+" 'NR==2{print $2}'    说明:中括号中代表以什么分隔符分割   +  表示多个

nginx不能通过yum 直接下载  需要编译安装

nginx编译安装三部曲

1、  ./configure       #指定安装位置   指定用户   指定模块

  指定用户:   先添加用户    命令:   useradd   -s/sbin/nologin   -M   aaaa(用户名)

执行命令:./configure  --prefix=指定路径   --user=指定用户     -- with-http_stub_status_module    --with-http_ssl_module

报错:#./configure: error: the HTTP rewrite module requires the PCRE library.
解决方法:yum install pcre-devel  -y

#报错2
#./configure: error: SSL modules require the OpenSSL library.
yum install openssl-devel  -y

2、make

3、make install     

备注:echo $?  表示上一个命令的执行结果是否正确(正确为0)

启动nginx

  查看配置文件是否故障     :  /指定路径/sbin/nginx -t   

  启动nginx:/指定路径/sbin/nginx        比如: /app/nginx-1.14.0/sbin/nginx

备注:使用命令:    lsof  -i:80  查看nginx的启动情况

启动后,访问当前ip查看页面

出现这个页面表示正常

如果无法访问页面,则检查是否关闭了防火墙和selinux

 关闭防火墙和selinux

 关闭防火墙

  临时:    /etc/init.d/iptables stop             永久(关闭开机自启动):chkconfig iptables off

检查是否关闭防火墙

  临时关闭: /etc/init.d/iptables status         永久关闭:  chkconfig | grep ipt

关闭selinux

  ##永久修改-重启服务器之后生效   (修改selinux配置文件)

  查看selinux配置文件
  [root@oldboyedu50-lnb nginx-1.14.0]# cat /etc/selinux/config

  # 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=disabled     #######   修改此行    enforcing(表示开启) ---->  disabled(表示彻底关闭)
  # SELINUXTYPE= can take one of these two values:
  #     targeted - Targeted processes are protected,
  #     mls - Multi Level Security protection.
  SELINUXTYPE=targeted

  [root@oldboyedu50-lnb nginx-1.14.0]# grep =disable /etc/selinux/config
  SELINUX=disabled


  ##临时修改
  setenforce 0

备注:可以使用  tree 查看结构

nginx目录结构

[root@oldboyedu50-lnb ~]# tree  /app/
/app/
└── nginx-1.14.0
    ├── client_body_temp
    ├── conf                          #配置文件
    │   ├── fastcgi.conf
    │   ├── fastcgi.conf.default
    │   ├── fastcgi_params
    │   ├── fastcgi_params.default
    │   ├── koi-utf
    │   ├── koi-win
    │   ├── mime.types
    │   ├── mime.types.default
    │   ├── nginx.conf                #nginx 主配置文件
    │   ├── nginx.conf.default        #
    │   ├── scgi_params
    │   ├── scgi_params.default
    │   ├── uwsgi_params
    │   ├── uwsgi_params.default
    │   └── win-utf
    ├── fastcgi_temp
    ├── html                          #站点目录
    │   ├── 50x.html
    │   └── index.html
    ├── logs                          #nginx的日志
    │   ├── access.log                #访问日志
    │   ├── error.log
    │   └── nginx.pid
    ├── proxy_temp
    ├── sbin                          #命令
    │   └── nginx                     #nginx管理命令
    ├── scgi_temp
    └── uwsgi_temp

10 directories, 21 files

 配置软连接(快捷方式):    ln -s /app/nginx-1.14.0/sbin/nginx  /sbin/

 nginx  -s reload   重启nginx 

 备注:curl  -v  10.0.0.200/html...   查看请求的过程

 ps  -ef 表示所有的进程        ps -ef  | grep nginx   查看nginx的进程

 nginx主配置文件详解:

vim的快捷方式

                                

原文地址:https://www.cnblogs.com/zhaopanpan/p/9347215.html