一,基本命令

1,mkdir 创建目录

  -p 创建多层目录

2,ls ==》list

  -l 显示详细信息

3,cd 进入到目录

4,pwd 显示当前所在目录

5,touch 创建文件

6,vi 编辑文件

7,cat 显示文件内容

8,cp 复制

9,man 查看查询命令的帮助

10,mv 移动

11,rm 删除文件或目录

  -f 强制删除不提示

  -r递归删除目录

12,find 查找

  -type f(file)

  -name "名字"

13,grep 三剑客老三,擅长过滤

  -v排除

14,head 显示文件的前几行,默认前10行

  -n2 ===  -2  显示文件的前两行

15,tail 显示文件的最后几行,默认后10行

  -n2 ===-2 显示文件的最后两行

  -f  实时显示文件的更新

16,sed 三剑客老二,擅长取行

  -n 取消默认输出

  -i 修改文件的内容

  -n ‘20p’ 取第20行

  -n ‘20,30p’ 取20到30行

  's#oldboy#oldgirl#g' 替换
  's@oldboy@oldgirl@g' 替换

17,tar 创建查看解压压缩包

  zcf 创建压缩包

  tf 查看压缩包

  xf 解压包

  -C 解压到指定目录

特殊符号:

1.   * :所有 *.log *.txt 2.   .. :当前目录的上一级目录
3.   . :当前目录
4.   | :管道
  find + |xargs 前面查到的结果传给后面的命令
5.   >: 重定向符号 先清空文件的内容 然后追加
6.   >> :追加, 把信息追加到文件的结尾

 

修改文件步骤:

  第1-打开文件
  vi      /data/oldboy.txt

  第2-编辑文件
  按i 进入到编辑模式

  第3-退出编辑模式
  按esc退出编辑模式

  第4-保存退出
  :wq     保存退出
  :q!     强制退出不保存

vi/vim 快捷键   

  复制 yy
  粘贴 p
  删除、剪切 dd
  撤销 u
  把光标所在行到文件最后一行删除 dG

移动光标

  把光标移动到文件的最后一行 G
  把光标移动到文件的第一行 gg

 

批量删除

1-按ctrl + v进入批量编辑模式

2-按方向键进行选择

3-按d删除

 

 

已知/tmp下已经存在test.txt文件,如何执行命令才能把/mnt/test.txt拷贝到/tmp下覆盖掉/tmp/test.txt,而让系统不提示是否覆盖(root权限下)。

\cp /tmp/test.txt /mnt/

#cp cp -i
#别名
[root@oldboyedu-s8 ~]# alias
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'


#\cp        \临时取消cp命令的别名
#alias    别名相当于给命令设置了 昵称 或 快捷键

 

 

只查看ett.txt文件(共100行)内第20到第30行的内容


sed -n '20,30p' ett.txt


seq 40 > /oldboy/ett.txt  将1-40放到ett.txt中
cat /oldboy/ett.txt

#sed默认输出文件的每一行
sed -n '20p' ett.txt
输出20
-n 取消默认输出

把/oldboy目录及其子目录下所有以扩展名 .sh结尾的文件中,文件包含./hostlists.txt(oldboy)的字符串全部替换为../idctest_iplist(oldgirl)

第1-找出想要的文件
find /oldboy/ -type f -name "*.sh"
第2-替换1个文件的内容
sed 's#oldboy#oldgirl#g' /oldboy/t.sh
第3-把find命令找出的文件交给sed
find /oldboy/ -type f -name "*.sh" |xargs sed 's#oldboy#oldgirl#g'


find /oldboy/ -type f -name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh


sed 's#oldboy#oldgirl#g' /oldboy/t.sh
oldgirl


find /oldboy/ -type f -name "*.sh" |xargs sed 's#oldboy#oldgirl#g'
oldgirl
oldgirl
oldgirl


cat /oldboy/t.sh
oldboy


find /oldboy/ -type f -name "*.sh" |xargs sed -i 's#oldboy#oldgirl#g'
find /oldboy/ -type f -name "*.sh" |xargs cat
oldgirl
oldgirl
oldgirl

 

 

#cd - 快速进入你上一次的位置 从哪里来回哪里去 

cd /etc/sysconfig/network-scripts/  跳到指定目录
pwd  查看当前所在目录
  /etc/sysconfig/network-scripts
cd /tmp/    直接跳到另一指定目录
cd -  返回到上一目录
  /etc/sysconfig/network-scripts
cd -  又跳回到上上目录
  /tmp

查看带行号的文件内容 加参数-n

cat -n /root/oldboy.txt
1 oldboy
2 oldboy
3 oldboy
4 oldboy
5 oldboy

对于在vi/vim编辑文件时 
  :set nu 显示行号
  :set nonu 取消显示行号

 

 

创建一个压缩包
tar zcf /tmp/etc.tar.gz /etc

z=== 通过gzip软件进行压缩
c=== create 创建
f=== file 指定压缩包

查看压缩包内容
tar tf /tmp/etc.tar.gz
t === list 显示压缩包内容

解压
cd /tmp/    进入到压缩包目录
tar xf etc.tar.gz    解压

解压到指定位置
tar xf etc.tar.gz -C /mnt/       -C指定目录解压

 

Linux - CentOS 7.4
基础命令
系统优化+定时任务
nginx


1.虚拟机可以联网
ping baidu.com


2.linux下面安装软件

1)通过yum安装软件 需要你联网


2) 更改系统的yum源 阿里云
#https://opsx.alibaba.com/mirror 来源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3)安装常用软件

yum install -y tree bash-completion wget vim

 

 

Linux无法上网排查过程
1. 查看是否能上网
[root@bigdata ~]# ping baidu.com
connect: 网络不可达

2. 验证是否DNS 域名解析 域名---->ip地址
[root@bigdata ~]# ping 223.5.5.5
connect: 网络不可达

3. 网关-验证你的网络配置(网卡 虚拟机vmwarexxx)是否有问题
ip r
[root@bigdata ~]# ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=128 time=0.206 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=128 time=0.170 ms
^C
--- 10.0.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.170/0.188/0.206/0.018 ms

 

使用CentOS7.4 光盘镜像

1.把光盘插入到系统

2.在linux使用光盘
[root@oldboyedu-s8 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboyedu-s8 ~]# #mount 给/dev/cdrom 创建一个入口 /mnt
[root@oldboyedu-s8 ~]# cd /mnt/
[root@oldboyedu-s8 mnt]# ls -l
total 664
-rw-rw-r--. 3 root root 14 Sep 5 2017 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Sep 5 2017 EFI
-rw-rw-r--. 3 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 3 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Sep 5 2017 images
drwxr-xr-x. 2 root root 2048 Sep 5 2017 isolinux
drwxr-xr-x. 2 root root 2048 Sep 5 2017 LiveOS
drwxrwxr-x. 2 root root 641024 Sep 5 2017 Packages
drwxr-xr-x. 2 root root 4096 Sep 5 2017 repodata
-rw-rw-r--. 3 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 3 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Sep 6 2017 TRANS.TBL

[root@oldboyedu-s8 mnt]# ls -l /mnt/Packages/
Display all 3895 possibilities? (y or n)
[root@oldboyedu-s8 mnt]# ls -l /mnt/Packages/bash-completion-2.1-6.el7.noarch.rpm
-rw-rw-r--. 2 root root 87272 Jul 4 2014 /mnt/Packages/bash-completion-2.1-6.el7.noarch.rpm
[root@oldboyedu-s8 mnt]# rpm -ivh /mnt/Packages/bash-completion-2.1-6.el7.noarch.rpm
Preparing... ################################# [100%]
package bash-completion-1:2.1-6.el7.noarch is already installed
[root@oldboyedu-s8 mnt]# ll /mnt/Packages/telnet-
telnet-0.17-64.el7.x86_64.rpm telnet-server-0.17-64.el7.x86_64.rpm
[root@oldboyedu-s8 mnt]# ll /mnt/Packages/telnet-0.17-64.el7.x86_64.rpm
-rw-rw-r--. 2 root root 65632 Aug 11 2017 /mnt/Packages/telnet-0.17-64.el7.x86_64.rpm


1.Linux下面安装软件: yum 通过光盘安装

yum
yum install

rpm -ivh

编译安装
三部曲: 备菜切菜 做菜 上菜
nginx ./configure make make install

2.如何使用光盘安装软件

3.Linux无法上网排查过程

系统优化+定时任务
1.更改系统的yum源
#阿里云 mirrors.aliyun.com
https://opsx.alibaba.com/mirror

#清华
https://mirrors.tuna.tsinghua.edu.cn/help/centos/

#网易
http://mirrors.163.com/.help/centos.html

云服务 物理服务器

2.关闭SElinux
rpm -qa
#-qa query all
rpm -qa

1#永久 修改配置文件 重启服务器之后生效

# enforcing - 已开启 正在运行
# permissive - selinux关闭 警告提示
# disabled - 彻底关闭
SELINUX=enforcing
|

SELINUX=disabled

cp /etc/selinux/config /etc/selinux/config.bak
#快捷键:esc + .(点) 使用上一个命令的最后一个东西(参数)

sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@oldboyedu-s8 ~]# 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
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

2#临时 重启服务器之后失效
[root@oldboyedu-s8 ~]# getenforce
Enforcing
[root@oldboyedu-s8 ~]# #显示当前selinux
[root@oldboyedu-s8 ~]# #显示当前selinux的运行状态
[root@oldboyedu-s8 ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldboyedu-s8 ~]# setenforce 0
[root@oldboyedu-s8 ~]# getenforce
Permissive

 

防火墙

iptables
firewalld

[root@oldboyedu-s8 ~]# rpm -qa bash-completion
bash-completion-2.1-6.el7.noarch
#查询防火墙状态
systemctl status firewalld.service

#当前正在运行的防火墙 --- 临时
systemctl stop firewalld.service

#让防火墙不会开机自启动 --- 永久
systemctl disable firewalld.service

#systemctl is-active firewalld.service
#is-active 是否正在运行 是否健在
#systemctl is-enabled firewalld.service
#is-enabled 是否开机自启动
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]# systemctl is-active firewalld.service
unknown
[root@oldboyedu-s8 ~]# systemctl is-active crond.service
active
[root@oldboyedu-s8 ~]# systemctl is-enabled firewalld.service
disabled


[root@oldboyedu-s8 ~]# systemctl start firewalld.service
[root@oldboyedu-s8 ~]# systemctl is-active firewalld.service
active
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@oldboyedu-s8 ~]# systemctl is-enabled firewalld.service
enabled

小结:
systemctl 管理服务
如何关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

systemctl status firewalld
systemctl is-active firewalld
systemctl is-enabled firewalld

systemctl enable firewalld.service

crond 定时任务
同步系统时间 √
备份


检查crond状态
[root@oldboyedu-s8 ~]# rpm -qa cronie
cronie-1.4.11-17.el7.x86_64
[root@oldboyedu-s8 ~]# systemctl is-active crond.service
active
[root@oldboyedu-s8 ~]# systemctl is-enabled crond.service
enabled

#定时任务管理命令
[root@oldboyedu-s8 ~]# crontab -l
no crontab for root

[root@oldboyedu-s8 ~]# crontab -e
#oldboyedu.com

#-e edit
#-l list

定时任务格式


每天的早上8:30到学校上车(go to school)
30 08 * * * go to school

每天的晚上12点整回家自己开车(go to bed)
00 00 * * * go to bed


如何修改系统时间
[root@oldboyedu-s8 ~]# date
Thu Apr 26 12:13:53 CST 2018
[root@oldboyedu-s8 ~]# date -s "20180101 01:01:01"
Mon Jan 1 01:01:01 CST 2018
[root@oldboyedu-s8 ~]# date
Mon Jan 1 01:01:05 CST 2018

让系统自动同步时间
yum install ntpdate -y
[root@oldboyedu-s8 ~]# ntpdate ntp1.aliyun.com
26 Apr 12:19:53 ntpdate[18819]: step time server 182.92.12.11 offset 9976502.795919 sec
[root@oldboyedu-s8 ~]# date
Thu Apr 26 12:20:24 CST 2018


ntpdate ntp1.aliyun.com
ntpdate ntp2.aliyun.com
ntpdate ntp3.aliyun.com
ntpdate ntp4.aliyun.com
ntpdate ntp5.aliyun.com
ntpdate ntp6.aliyun.com
ntpdate ntp7.aliyun.com


#显示命令的绝对路径
[root@oldboyedu-s8 ~]# which ntpdate
/usr/sbin/ntpdate
[root@oldboyedu-s8 ~]# find / -type f -name "ntpdate"
/etc/sysconfig/ntpdate
/usr/sbin/ntpdate

#每2分钟同步一次系统时间

###1.命令行测试
[root@oldboyedu-s8 ~]# /usr/sbin/ntpdate ntp1.aliyun.com
26 Apr 12:28:11 ntpdate[19018]: adjust time server 182.92.12.11 offset 0.000723 sec

###2.命令写入定时任务
[root@oldboyedu-s8 ~]# crontab -l
#sync time
*/2 * * * * /usr/sbin/ntpdate ntp1.aliyun.com

###3.进行检查与测试
[root@oldboyedu-s8 ~]# date -s "20190101"
Tue Jan 1 00:00:00 CST 2019
[root@oldboyedu-s8 ~]# date
Tue Jan 1 00:00:01 CST 2019
[root@oldboyedu-s8 ~]# date
Thu Apr 26 12:31:25 CST 2018


总结:
1.安装常用软件
yum rpm 编译安装
2.linux优化
1)yum源配置
增加常用yum源 :
epel源
yum install wget -y
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum repolist
yum install sl cowsay -y


2)关闭selinux和防火墙
3.定时任务 执行命令

下午:
nginx

作用:
1.web网站
2.nginx+其他fastcgi(php)/ uwsgi(python)

部署nginx
1#下载nginx

wget http://nginx.org/download/nginx-1.12.2.tar.gz

yum install pcre-devel openssl-devel -y

#编译安装三部曲 : ./configure make make install

tar xf nginx-1.12.2.tar.gz
cd nginx-1.12.2

./configure --prefix=/application/nginx-1.12.2 --with-http_stub_status_module --with-http_ssl_module
make
make install


故障1:
error: the HTTP rewrite module requires the PCRE library.
yum install pcre-devel -y


[root@oldboyedu-s8 nginx-1.12.2]# ll /application/nginx-1.12.2/
total 4
drwxr-xr-x. 2 root root 4096 Apr 26 15:55 conf #configure nginx配置文件
drwxr-xr-x. 2 root root 40 Apr 26 15:55 html #站点目录 网站根目录
drwxr-xr-x. 2 root root 6 Apr 26 15:55 logs #日志
drwxr-xr-x. 2 root root 19 Apr 26 15:55 sbin #nginx管理命令

#检查语法
/application/nginx-1.12.2/sbin/nginx -t

#启动nginx
/application/nginx-1.12.2/sbin/nginx


/application/nginx-1.12.2/sbin/nginx -s reload


#nginx配置说明

nginx.conf #nginx配置文件
nginx.conf.default #

#对比两个文件区别
diff conf/nginx.conf conf/nginx.conf.default

egrep -v "#|^$" /application/nginx-1.12.2/conf/nginx.conf.default >/application/nginx-1.12.2/conf/nginx.conf


1 worker_processes 1;
2 events {
3 worker_connections 1024;
4 }
5 http {
6 include mime.types; #媒体类型
7 default_type application/octet-stream;
8 sendfile on; #开启高效的传输模式
9 keepalive_timeout 65; #超时时间
10 server { #一个server相当于是一个网站 虚拟主机
11 listen 80; #监听的端口
12 server_name www.etiantian.org; #网站名字 域名
13 location / {
14 root html; #根 站点的根目录
15 index index.html index.htm; #首页文件
16 }
21 }
22 }

 

总结:
1.nginx部署 配置
2.定时任务
3.系统优化 配置和增加yum源 关闭selinux和防火墙
4.安装软件方法
5.linux下面如何使用光盘

再约:
1.redis
2.lnmp(python)

 

posted on 2018-04-25 21:46  Py行僧  阅读(147)  评论(0编辑  收藏  举报