linux(操作2)

 

 文件地址下载:

 cluster配置

 redis_for_python

redis

老男孩教育-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   (这里是安装tree插件,我们的文件目录以后就可以输入tree指令让它以树形结构显示出来,)

 

 

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.把光盘插入到系统   [进入我们的虚拟机界面,找到虚拟机,单击右键选属性,弹出一个框,在里面找到光盘,然后选择使用镜像,把我们的centos7.4下载好的镜像路径放进去即可]

2.在linux使用光盘安装软件   [使用光盘就不用联网了,下面是输入指令以及指令返回结果,root开头的就是我们需要输入的指令]
[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源  [这里的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   (这个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   [这里我们只查看active这一个状态,就用特定指令is-active]
systemctl is-enabled firewalld  [同上我们只查看enabled这个状态]

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


如何修改系统时间  date -s 就是set设置的意思
[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

 

如下是aliyun时间版本
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   这里就是我们的定时任务,每两分钟自动更新一下时间,任务固定格式{

*(分0-59)*(时0-23)*(日1-31)*(月1-12)*(周0-6)  后面加上指令,星期和日期不同时填写,这些参数不必同时填写上,用到什么填什么即可

}

###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

我们在执行指令的时候可以排查指令是否执行正确,使用echo $?  它返回的是0就是执行成功,如果是0以外的其他数字就是执行不成功.
[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 @ 2018-04-26 19:12  dream-子皿  阅读(95)  评论(0)    收藏  举报