linux命令小结

查看IP  ip a  

测试ip   ping 10.0.0.128

测试端口   telnet 10.0.0.128  22  # telnet + ip + 端口

老男孩教育-python全栈8期-Linux运维基础
李老师
QQ:918391635

Linux - CentOS 7.4
基础命令
系统优化+定时任务
nginx
nginx+py搭建网站

Linux
vmware fusion(mac) vmware workstation 12.0 (windows)
8.0
远程连接工具:xshell (windows) mac(iterm2)
android juiceSSH
IOS termius

Linux
Fedora
Red Hat Enterprise Linux RHEL 7.5
CentOS 红帽收费去掉,logo去掉

Debian
Ubuntu
SUSE OpenSUSE


https://mirrors.aliyun.com/centos/


F1
F2
F10
F12

intel virtual technology disabled(关闭)
enabled(开启)
intel vt


网卡名称 : eth0
ensxxx


vmware相关服务 要开启
win+r 输入 services.msc

VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动


远程连接服务器 : 10.0.0.128
Xshell 免费
SecureCRT
putty

屌丝去洗浴中心之路

1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows

2.是否有人劫财劫色

3.是否提供特殊服务

1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows

[d:\~]$ ping 10.0.0.128

正在 Ping 10.0.0.128 具有 32 字节的数据:
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64

10.0.0.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms

[d:\~]$ ping 10.0.0.130

正在 Ping 10.0.0.130 具有 32 字节的数据:
来自 10.0.0.1 的回复: 无法访问目标主机。
请求超时。
请求超时。
请求超时。

10.0.0.130 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 1,丢失 = 3 (75% 丢失),

2.是否有人劫财劫色
SeLinux
防火墙

3.

服务名称 搓澡 按摩 特殊服务
暗号(端口号) 80 443 22

远程连接服务 sshd 22
telnet 10.0.0.128 22
[d:\~]$ telnet 10.0.0.128 22

Connecting to 10.0.0.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
SSH-2.0-OpenSSH_7.4

Protocol mismatch.

Connection closed by foreign host.

Disconnected from remote host(10.0.0.128:22) at 12:17:03.

Type `help' to learn how to use Xshell prompt.
[d:\~]$ telnet 10.0.0.128 25


Connecting to 10.0.0.128:25...
Could not connect to '10.0.0.128' (port 25): Connection failed.

Type `help' to learn how to use Xshell prompt.


道路不通排查过程
1.ip地址
2.vmware 编辑-虚拟网络编辑器
3.windows 服务
vmware相关服务 要开启
win+r 输入 services.msc

VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动

4.我的电脑/此电脑/文件夹 输入 网络连接

通过安装包修复

CCleaner 把vmware相关信息 清理掉 重新安装


总结:
1.创建虚拟机-部署CentOS 7.4
2.配置VMware虚拟网络编辑器
3.通过Xshell连接虚拟机
4.无法连接服务器排查过程(屌丝去洗浴中心之路)
5.xshell优化


下午:
操作与命令


空格和tab键


[root@oldboyedu-s8 ~]# #mkdir make directory
[root@oldboyedu-s8 ~]# mkdir /data
[root@oldboyedu-s8 ~]# #显示目录的内容
[root@oldboyedu-s8 ~]# #ls list
[root@oldboyedu-s8 ~]# ls /data/
[root@oldboyedu-s8 ~]# ls -l /data/
total 0

相对路径与绝对路径:
绝对路径:从根开始的路径(位置) /data etc/hosts
从根开始的路径就是绝对路径。


[root@oldboyedu-s8 data]# touch /data/oldboy.txt
[root@oldboyedu-s8 data]# ls -l /data/
total 0
-rw-r--r--. 1 root root 0 Apr 25 15:16 oldboy.txt


第1个里程碑-打开文件
vi /data/oldboy.txt

第2个里程碑-编辑文件
按i 进入到编辑模式

第3个里程碑-退出编辑模式
按esc退出编辑模式

第4个里程碑-保存退出
:wq write quit
#保存退出
:q!
#强制退出不保存


第5个里程碑-显示文件内容
[root@oldboyedu-s8 data]# cat /data/oldboy.txt
I am studying linux.

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

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

#I am studying linux.I am studying linux.I am studying linux.
#I am studying linux.I am studying linux.I am studying linux.
#I am studying linux.I am studying linux.I am studying linux.
#I am studying linux.I am studying linux.I am studying linux.

批量删除

第1个里程碑-按ctrl + v 进入批量编辑模式

第2个里程碑-选择

第3个里程碑-删除 d

[root@oldboyedu-s8 data]# #copy cp
[root@oldboyedu-s8 data]#
[root@oldboyedu-s8 data]# cp /data/oldboy.txt /tmp/
[root@oldboyedu-s8 data]# ls -l /tmp/
total 8
-rwx------. 1 root root 836 Apr 25 11:03 ks-script-6cg4Xy
-rw-r--r--. 1 root root 183 Apr 25 15:56 oldboy.txt
drwx------. 3 root root 17 Apr 25 11:18 systemd-private-241350d318404b8eb4e0324ead618b12-chronyd.service-tG7NpS
drwx------. 3 root root 17 Apr 25 11:18 systemd-private-241350d318404b8eb4e0324ead618b12-vgauthd.service-bhBRbW
drwx------. 3 root root 17 Apr 25 11:18 systemd-private-241350d318404b8eb4e0324ead618b12-vmtoolsd.service-mHP4YZ
-rw-------. 1 root root 0 Apr 25 10:58 yum.log


2.5 把 /data 移动到 /root目录下面

move mv

[root@oldboyedu-s8 data]# mv /data/ /root/
[root@oldboyedu-s8 data]# ls -l /data
ls: cannot access /data: No such file or directory
[root@oldboyedu-s8 data]# ls -l /r
root/ run/
[root@oldboyedu-s8 data]# ls -l /root/
total 4
-rw-------. 1 root root 1233 Apr 25 11:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root 46 Apr 25 16:00 data

进入/root目录下的data目录,删除oldboy.txt文件
remove
rm

[root@oldboyedu-s8 tmp]# cd /root/
[root@oldboyedu-s8 ~]# ls -l
total 4
-rw-------. 1 root root 1233 Apr 25 11:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root 28 Apr 25 16:32 data
[root@oldboyedu-s8 ~]# pwd
/root
[root@oldboyedu-s8 ~]# rm -f data
rm: cannot remove ‘data’: Is a directory
[root@oldboyedu-s8 ~]# ls -l
total 4
-rw-------. 1 root root 1233 Apr 25 11:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root 28 Apr 25 16:32 data
[root@oldboyedu-s8 ~]# rm -r data
rm: descend into directory ‘data’? y
rm: remove regular file ‘data/oldboy.txt.bak’? n
rm: remove directory ‘data’? n
[root@oldboyedu-s8 ~]# rm -rf data

[root@oldboyedu-s8 ~]# find /root/ -type f -name "oldboy.txt"
/root/oldboy.txt
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]# find /root/ -type f -name "*.txt"
/root/oldboy.txt
#*.txt 以.txt 结尾的文件

#find /root/ -type f -name "*.txt"
# 在哪里找 -什么类型 f(file)
# d(dir)

在/etc 找出以eth0结尾的文件


http://blog.51cto.com/lidao/1927347

老男孩教育每日一题-2017年5月18日-说说|(管道)与|xargs(管道xargs)的区别

[root@oldboyedu-s8 ~]# find /root/ -type f -name "*.txt"
/root/oldboy.txt
/root/alex.txt
[root@oldboyedu-s8 ~]# find /root/ -type f -name "*.txt" |xargs ls -l
-rw-r--r--. 1 root root 0 Apr 25 17:01 /root/alex.txt
-rw-r--r--. 1 root root 0 Apr 25 17:01 /root/oldboy.txt

# .. 当前目录的上一级目录
# . 当前目录
[root@oldboyedu-s8 sysconfig]# cd /etc/sysconfig/network-scripts/
[root@oldboyedu-s8 network-scripts]# cd ../../../../../../../../../

[root@oldboyedu-s8 ~]# cat /data/test.txt
test
liyao
oldboy
[root@oldboyedu-s8 ~]# #在文件中过滤
[root@oldboyedu-s8 ~]# #显示出文件中 你想要的或不想要的内容
[root@oldboyedu-s8 ~]# grep "oldboy" /data/test.txt
oldboy
[root@oldboyedu-s8 ~]# grep -v "oldboy" /data/test.txt
test
liyao
[root@oldboyedu-s8 ~]# head -2 /data/test.txt
test
liyao


2.10 已知/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 egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
#\cp 临时取消cp命令的别名
#别名相当于给命令设置了 昵称 或 快捷键

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

seq 40 > /oldboy/ett.txt
cat /oldboy/ett.txt

#sed默认输出文件的每一行
[root@oldboyedu-s8 oldboy]# sed -n '20p' ett.txt
20
#-n 取消默认输出
[root@oldboyedu-s8 oldboy]#
[root@oldboyedu-s8 oldboy]# sed -n '20,30p' ett.txt
20
21
22
23
24
25
26
27
28
29
30

2.12 把/oldboy目录及其子目录下所有以扩展名 .sh结尾的文件中,文件包含./hostlists.txt(oldboy)的字符串全部替换为../idctest_iplist(oldgirl)
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[root@oldboyedu-s8 oldboy]# #把一个文件的oldboy替换为 oldgirl
[root@oldboyedu-s8 oldboy]# #替换
[root@oldboyedu-s8 oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/t.sh
oldgirl
[root@oldboyedu-s8 oldboy]# cat /oldboy/t.sh
[root@oldboyedu-s8 oldboy]# cat /oldboy/t.sh
oldboy
[root@oldboyedu-s8 oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/t.sh
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'


[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[root@oldboyedu-s8 oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/t.sh
oldgirl
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh" |xargs sed 's#oldboy#oldgirl#g'
oldgirl
oldgirl
oldgirl
[root@oldboyedu-s8 oldboy]# cat /oldboy/t.sh
oldboy
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh" |xargs sed -i 's#oldboy#oldgirl#g'
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh" |xargs cat
oldgirl
oldgirl
oldgirl


[root@oldboyedu-s8 network-scripts]# cd /etc/sysconfig/network-scripts/
[root@oldboyedu-s8 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@oldboyedu-s8 network-scripts]# cd /tmp/
[root@oldboyedu-s8 tmp]# cd -
/etc/sysconfig/network-scripts
[root@oldboyedu-s8 network-scripts]# #cd - 快速进入你上一次的位置 从哪里来回哪里去
[root@oldboyedu-s8 network-scripts]# cd -
/tmp

[root@oldboyedu-s8 tmp]# cat -n /root/oldboy.txt
1 oldboy
2 oldboy
3 oldboy
4 oldboy
5 oldboy

vi/vim
nu==== number
:set nu 显示行号
:set nonu 取消显示行号


windows 创建压缩包
linux 打包压缩

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

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


[root@oldboyedu-s8 tmp]# tar zcf /tmp/etc.tar.gz /etc/
tar: Removing leading `/' from member names
[root@oldboyedu-s8 tmp]# ll /tmp/etc.tar.gz
-rw-r--r--. 1 root root 9916889 Apr 25 19:20 /tmp/etc.tar.gz

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

解压
[root@oldboyedu-s8 tmp]# cd /tmp/
[root@oldboyedu-s8 tmp]# tar xf etc.tar.gz

解压到指定位置
[root@oldboyedu-s8 tmp]# tar xf etc.tar.gz -C /mnt/
[root@oldboyedu-s8 tmp]# ls -l /mnt/
total 12
drwxr-xr-x. 80 root root 8192 Apr 25 16:30 etc
-rw-r--r--. 1 root root 0 Apr 25 18:06 test.txt

总结:
1.创建虚拟机-部署CentOS 7.4
2.配置VMware虚拟网络编辑器
3.通过Xshell连接虚拟机
4.无法连接服务器排查过程(屌丝去洗浴中心之路)
5.xshell优化
6.必知必会命令 根据题目练习
7.find命令
8.打包压缩
9.三剑客 grep sed

预习:
0.ping baidu.com
1.单引号 双引号 区别
2.linux启动过程 运行级别
3.如何关闭Selinux和防火墙
4.定时任务 同步系统时间
5.nginx

老男孩教育-python全栈8期-Linux运维基础
李老师
QQ:918391635


1.mkdir
-p 创建多层目录
2.ls list
-l 显示详细信息

3.cd change directory 进入到目录中

4.pwd print working directory 显示当前所在位置

5.touch 摸 创建文件 修改文件的时间戳

6.vi 编辑文件

7.cat 显示文件内容

8.cp copy 复制

9.man 查询命令的帮助

10. mv move 移动

11. rm remove 删除文件或目录
-f 强制删除不提示

-r 递归删除目录

12. find 查找
-type f(file)
d(dir)
-name 名字

13. grep 三剑客老三 擅长 过滤
-v 排除

14. head 显示文件的前几行 默认显示文件的前10行
-n2 === -2 显示文件的前2行

15. tail 显示文件的最后几行 默认显示文件的后10行
-n1 === -1 显示文件的最后1行
-f 实时显示文件的更新


16. sed 三剑客老二 擅长取行
-n 取消默认输出
-i 修改文件的内容

-n '20p'
-n '20,30p'

's#oldboy#oldgirl#g'
's@oldboy@oldgirl@g'


17. tar 创建解压查看压缩包
zcf
tf
xf
-C



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

Linux - CentOS 7.4
基础命令
系统优化+定时任务
nginx
nginx+py搭建网站

Linux
vmware fusion(mac) vmware workstation 12.0 (windows)
8.0
远程连接工具:xshell (windows) mac(iterm2)
android juiceSSH
IOS termius

Linux
Fedora
Red Hat Enterprise Linux RHEL 7.5
CentOS 红帽收费去掉,logo去掉

Debian
Ubuntu
SUSE OpenSUSE


https://mirrors.aliyun.com/centos/


F1
F2
F10
F12

intel virtual technology disabled(关闭)
enabled(开启)
intel vt


网卡名称 : eth0
ensxxx


vmware相关服务 要开启
win+r 输入 services.msc

VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动


远程连接服务器 : 10.0.0.128
Xshell 免费
SecureCRT
putty

屌丝去洗浴中心之路

1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows

2.是否有人劫财劫色

3.是否提供特殊服务

1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows

[d:\~]$ ping 10.0.0.128

正在 Ping 10.0.0.128 具有 32 字节的数据:
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64

10.0.0.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms

[d:\~]$ ping 10.0.0.130

正在 Ping 10.0.0.130 具有 32 字节的数据:
来自 10.0.0.1 的回复: 无法访问目标主机。
请求超时。
请求超时。
请求超时。

10.0.0.130 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 1,丢失 = 3 (75% 丢失),

2.是否有人劫财劫色
SeLinux
防火墙

3.

服务名称 搓澡 按摩 特殊服务
暗号(端口号) 80 443 22

远程连接服务 sshd 22
telnet 10.0.0.128 22
[d:\~]$ telnet 10.0.0.128 22

Connecting to 10.0.0.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
SSH-2.0-OpenSSH_7.4

Protocol mismatch.

Connection closed by foreign host.

Disconnected from remote host(10.0.0.128:22) at 12:17:03.

Type `help' to learn how to use Xshell prompt.
[d:\~]$ telnet 10.0.0.128 25


Connecting to 10.0.0.128:25...
Could not connect to '10.0.0.128' (port 25): Connection failed.

Type `help' to learn how to use Xshell prompt.


道路不通排查过程
1.ip地址
2.vmware 编辑-虚拟网络编辑器
3.windows 服务
vmware相关服务 要开启
win+r 输入 services.msc

VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动

4.我的电脑/此电脑/文件夹 输入 网络连接

通过安装包修复

CCleaner 把vmware相关信息 清理掉 重新安装


总结:
1.创建虚拟机-部署CentOS 7.4
2.配置VMware虚拟网络编辑器
3.通过Xshell连接虚拟机
4.无法连接服务器排查过程(屌丝去洗浴中心之路)
5.xshell优化


下午:
操作与命令


空格和tab键


[root@oldboyedu-s8 ~]# #mkdir make directory
[root@oldboyedu-s8 ~]# mkdir /data
[root@oldboyedu-s8 ~]# #显示目录的内容
[root@oldboyedu-s8 ~]# #ls list
[root@oldboyedu-s8 ~]# ls /data/
[root@oldboyedu-s8 ~]# ls -l /d
data/ dev/
[root@oldboyedu-s8 ~]# ls -l /data/
total 0

老男孩教育-python全栈8期-Linux运维基础
李老师
QQ:918391635

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

小结:
selinux关闭
0.操作前备份操作后检查
1.修改配置文件
2.命令行

防火墙

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)

猜你喜欢

转载自www.cnblogs.com/zjchao/p/8943009.html
今日推荐