[内容] Linux SELinux 状态的设置

内容目录:

内容一:SELinux 的状态

内容二:永久切换 SELinux 状态
2.1 将 SELinux 永久切换至 Disabled 状态
2.1.1 修改 SELinux 配置文件
2.1.2 重启系统
2.1.3 显示 SELinux 状态
2.2 将 SELinux 永久切换至 Permissive 状态
2.2.1 修改 SELinux 配置文件
2.2.2 重启系统
2.2.3 显示 SELinux 状态
2.3 将 SELinux 永久切换至 Enforcing 状态
2.3.1 修改 SELinux 配置文件
2.3.2 重启系统
2.3.3 显示 SELinux 状态

内容三:临时切换 SELinux 状态
3.1 临时切换到 Permissive 状态
3.1.1 临时切换到 Permissive 状态
3.1.2 显示 SELinux 状态
3.2 临时切换到 Enforcing 状态
3.2.1 临时切换到 Enforcing 状态
3.2.2 显示 SELinux 状态

具体的内容:

内容一:SELinux 的状态

1) Disabled:完全关闭 SELinux
2) Permissive:即使违反了策略也依旧可以执行,但是违反策略的记录会被记录在日志中
3) Enforcing:如果违反了策略就不能之行

内容二:永久切换 SELinux 状态
2.1 将 SELinux 永久切换至 Disabled 状态
2.1.1 修改 SELinux 配置文件

# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=disabled
......

2.1.2 重启系统

# reboot

2.1.3 显示 SELinux 状态

# getenforce 
Disabled

2.2 将 SELinux 永久切换至 Permissive 状态
2.2.1 修改 SELinux 配置文件

# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=permissive
......

2.2.2 重启系统

# reboot

2.2.3 显示 SELinux 状态

# getenforce 
Permissive

2.3 将 SELinux 永久切换至 Enforcing 状态
2.3.1 修改 SELinux 配置文件

# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=enforcing
......

2.3.2 重启系统

# reboot

2.3.3 显示 SELinux 状态

# getenforce 
Enforcing

内容三:临时切换 SELinux 状态
3.1 临时切换到 Permissive 状态
3.1.1 临时切换到 Permissive 状态

# setenfoce 0


注意:
1) 系统重启后失效
2) 只能从 Enforcing 状态切换到 Permissive 状态

3.1.2 显示 SELinux 状态

# getenforce 
Permissive

3.2 临时切换到 Enforcing 状态
3.2.1 临时切换到 Enforcing 状态

# setenfoce 1


注意:
1) 系统重启后失效
2) 只能从 Permissive 状态切换到 Enforcing 状态

3.2.2 显示 SELinux 状态

# getenforce 
Enforcing

[内容] pip 工具的安装 (MacBook Air 版)

内容目录:

内容一:安装 pip2
1.1 下载 pip2
1.2 安装 pip2
1.3 删除 pip2
1.4 显示安装的 pip2
1.4.1 显示在 python 里有没有 pip 安装包
1.4.2 显示有没有 pip2 命令
1.4.3 升级 pip2

内容二:安装 pip3
2.1 准备安装 pip3 所需的环境
2.1.1 安装 python3
2.1.1.1 输入 python3 命令
2.1.1.2 在弹出的对话框里安装 python3
2.1.2 安装 xcode
2.1.2.1 输入 xcode-select –install 命令
2.1.2.2 在弹出的对话框里安装 xcode
2.2 安装 pip3
2.2.1 下载 pip3
2.2.2 安装 pip3
2.2.3 删除 pip3
2.2.4 显示安装的 pip3
2.2.4.1 显示在 python 里有没有 pip 安装包
2.2.4.2 显示有没有 pip3 命令
2.2.4.3 升级 pip3

具体的内容:

内容一:安装 pip2
1.1 下载 pip2

$ curl 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' > get-pip.py

1.2 安装 pip2

$ sudo python get-pip.py

1.3 删除 pip2

$ rm get-pip.py

1.4 显示安装的 pip2
1.4.1 显示在 python 里有没有 pip 安装包

$ ls /Library/Python/2.7/site-packages/

(补充:这里以 Python 版本是 2.7 为例)

1.4.2 显示有没有 pip2 命令

$ which pip2

1.4.3 升级 pip2

$ sudo pip2 install --upgrade pip

内容二:安装 pip3
2.1 准备安装 pip3 所需的环境
2.1.1 安装 python3
2.1.1.1 输入 python3 命令

$ python3

2.1.1.2 在弹出的对话框里安装 python3

(步骤略)

2.1.2 安装 xcode
2.1.2.1 输入 xcode-select –install 命令

$ xcode-select --install

2.1.2.2 在弹出的对话框里安装 xcode

(步骤略)

2.2 安装 pip3
2.2.1 下载 pip3

$ curl 'https://bootstrap.pypa.io/pip/get-pip.py' > get-pip.py

2.2.2 安装 pip3

$ sudo python get-pip.py

2.2.3 删除 pip3

$ rm get-pip.py

2.2.4 显示安装的 pip3
2.2.4.1 显示在 python 里有没有 pip 安装包

$ ls /Library/Python/3.8/site-packages/

(补充:这里以 Python 版本是 3.8 为例)

2.2.4.2 显示有没有 pip3 命令

$ which pip3

2.2.4.3 升级 pip3

$ sudo pip3 install --upgrade pip

[步骤] Linux GRUB 的修复

步骤一:挂载系统光盘进入拯救模式

(步骤略)

步骤二:将相应分区挂载到 /mnt

# mount <系统根分区> /mnt

(补充:如果还有其他目录的话也要像这样挂载)

(注意:swap 分区不需要挂载)

步骤三:管理关在后的系统环境

# mount --rbind /proc /mnt/proc
# mount --rbind /sys /mnt/sys
# mount --rbind /dev /mnt/dev

步骤四:使用挂载后的系统环境

# chroot /mnt /bin/bash

步骤五:重装 GRUB2
5.1 生成 /boot/grub2/grub.cfg

# grub2-mkconfig -o /boot/grub2/grub.cfg

5.2 将 GRUB2 安装到对应硬盘

# grub2-install <disk>

(注意:这里的 <硬盘> 是硬盘例如 /dev/sda,而不是分区或者目录)

[工具] Shell 检测服务器某个端口有没有启动

介绍:

作者:朱明宇
名称:检测服务器某个端口有没有启动
作用:检测服务器某个端口有没有启动

使用方法:
1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本
4. 如果被检测的端口被启动则会被记录在指定文件里

脚本分割线里的变量:
1. checkport=’7111′ #被检测的端口
2. logfile=’checkportlog.txt’ #记录文件

脚本:

#!/bin/bash

####################### Separator ########################
checkport='7111'
logfile='checkportlog.txt'
####################### Separator ########################

a=`/sbin/ss -ntulap | grep udp | grep $checkport | awk '{print $7}' | awk -F'"' '{print $2}'`

if [ -n "$a" ];then
       echo `date` >> $logfile
       echo $checkport >> $logfile
       echo `/sbin/ss -ntulap | grep udp | grep $checkport | awk '{print $7}' | awk -F'"' '{print $2}'` >> $logfile
       echo >> $logfile
fi