网站开发设计思路,网站商城建设哪家好,网站开发如何设置视频教程,wordpress获取图片的绝对地址文章目录一、 vi 专栏二、固定ip设置2.1. 自动获取改为静态2.2. IDADDR获取2.3. GATEWAY获取2.4. 重新网卡2.5. 重新连接三、主机名调整3.1. 临时有效主机名3.2. 永久有效主机名四、防火墙调整4.1. 临时关闭防火墙4.2. 开机不启动防火墙五、shell脚本5.1. shell格式5.2. shell执…
文章目录一、 vi 专栏二、固定ip设置2.1. 自动获取改为静态2.2. IDADDR获取2.3. GATEWAY获取2.4. 重新网卡2.5. 重新连接三、主机名调整3.1. 临时有效主机名3.2. 永久有效主机名四、防火墙调整4.1. 临时关闭防火墙4.2. 开机不启动防火墙五、shell脚本5.1. shell格式5.2. shell执行5.3. shell中的变量六、shell逻辑判断表达式6.1. for循环6.2. while循环6.3. if判断6.4. 后台运行shell6.5. shell输出七、crontab7.1. crontab 简述与格式7.2. 常用命令7.3. 追加日志一、 vi 专栏
说明快捷键显示行数按左上角esc :set nu跳转首行gg跳转末尾G跳转当前行首Home跳转当前行末End跳转指定行按左上角esc :行号复制当前行yy粘贴到下一行p删除当前行以及下面所有行999dd查找关键词/关键词 按回车 按n查找下一个保存编辑按左上角esc :wq退出编辑不保存按左上角esc :q!
二、固定ip设置
2.1. 自动获取改为静态
cd /etc/sysconfig/network-scripts/
vi ifcfg-ens33将dhcp改为static2.2. IDADDR获取
添加
IPADDRip地址
GATEWAY
DNS1子网ip段是192.168.92后面的3-255自定义即可 如果想调整网段调整完成后点击应用即可
2.3. GATEWAY获取 DNS1网关即可
2.4. 重新网卡
#centos7.x RedHat7.x
systemctl restart network#centos6.x RedHat6.x
service networkrestart 2.5. 重新连接
客户端重新连接
三、主机名调整
3.1. 临时有效主机名
hostname 主机名3.2. 永久有效主机名
vi /etc/hostname
添加主机名# 重启服务器
reboot#防火墙临时关闭#开机不启动防火墙临时关闭
四、防火墙调整
4.1. 临时关闭防火墙
systemctl stop firewalld4.2. 开机不启动防火墙
systemctl disable firewalld五、shell脚本
5.1. shell格式
#!/bin/bash5.2. shell执行
# 第1种
sh xx.sh# 第2种
bash xx.sh# 第3种
chmod ux xx.sh
./xx.sh# 第4种 配置环境变量.
xx.sh5.3. shell中的变量
变量不需要声明初始化也不需要指定类型变量命名只能使用数字、字母和下划线且不能以数字开头变量赋值通过“”进行复制在变量、等号和值之间不能出现空格
六、shell逻辑判断表达式
6.1. for循环
格式1适用于有规律的for循环
for((i0;i10;i))
do
循环体。。。
done案例
#!/bin/bash
for((i0;i10;i))
do
echo $i
done格式2适用于没有规律的for循环
for i in 1 3 5
do
循环体。。。
done案例2:
#!/bin/bash
for i in 1 3 5 7
do
echo $i
done6.2. while循环
适用于循环次数未知或不便于使用for直接生成较大列表时测试条件为“真”则进入循环测试条件为“假”则退出循环
基本格式
whlie 测试条件
do
循环体。。。
done测试条件
格式test EXPR 或者 [ EXPR ] 中括号和表达式之间的空格不能少整型测试 -gt(大于)、-lt(小于)、-ge(大于等于)、-le(小于等于)、-eq(等于)、-ne(不等于)字符串测试(等于)、!(不等于)
整型测试
#!/bin/bash
while test 2 -gt 1
do
echo yes
sleep 1
done推荐使用第2种
#!/bin/bash
while [ 2 -gt 1 ]
do
echo yes
sleep 1
done字符串测试
#!/bin/bash
while [ qbc qbc ]
do
echo yes
sleep 1
done6.3. if判断
单分支
#格式
if 测试条件
then选择分支
fi案例
#!/bin/bash
flag1
if [ $flag -eq 1 ]
thenecho one
fi双分支
#格式
if 测试条件
then选择分支1
else选择分支2
fi案例
#!/bin/bash
flag1
if [ $flag -eq 1 ]
thenecho one
elseecho not support
fi多分支
#格式
if 测试条件
then选择分支1
elif 测试条件
then选择分支2...
else选择分支n
fi案例
#!/bin/bash
flag2
if [ $flag -eq 1 ]
thenecho one
elif [ $flag -eq 2 ]
thenecho two
elseecho not support
fi6.4. 后台运行shell
nohup xxx.sh 6.5. shell输出
标准输出1
标准错误输出2
重定向
追加nohup bash xxx.sh /dev/null 21
1是正确输出可以省略
2是错误输出
1 是引用标准输出1七、crontab
7.1. crontab 简述与格式
格式1适用于有规律的for循环
crontab作用于周期性白执行的命令 每天凌晨1点去“偷菜”格式
# For details see man 4 crontabs# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed7.2. 常用命令
# 查看crontab服务状态
systemctl status crond# 启动crontab服务
systemctl start crond# 关闭crontab服务
systemctl stop crond#添加定时任务
vim /etc/crontab案例 输出日期时间格式为yyyy-MM-dd HH:mm:ss
#!/bin/bash
showTime date %Y%m%d %H:%M:%S
echo $showTime#查看crontab执行日志
tail -f /var/log/cron7.3. 追加日志
执行脚本过程中记录日志输出到指定文件
* * * * * root sh /root/showTime.sh showtime.log