linux 循环 nginx

判断目录文件夹或文件是否存在 [ -e]

[-d fengdeyong] directory文件夹判断是否

test -e   ~.sh  -s判断存在和是否非空

man test

[-f] file 判断是否为文件

退出循环 终止本次开始下一次Continue

结束 跳出循环Break

seq 5  sequence 从1-5

for循环

$@所有位置变量

集合 $(命令)

固定循环

通过位置变量传递 控制循环次数

id 查询用户存不存在

bash create_user.sh feng 5

创建5 个feng开头的用户名

&>/dev/null 重定向到空 方便不显示的时候

while循环

1.控制循环次数   高级用法

2,固定循环次数

whileread

命令|while read var1 var2 var3 read 后面接变量名

do

命令

done <filename  <将文件里内容导入到循环里 注意第一行表头可以用if语句去除                                                                                                                                  

变量尽量一一对应没有对应的会合并到最后输出                                                                                                                                       

cat grade.txt|while…效果一样

死循环

Ctrl +c 强行结束

exit 退出整个脚本                        后面的不执行

整个脚本有很多命令如果某条出错需要退出整个脚本使后面的命令不执行

如果有一百条都检查的话脚本很臃肿 但是可以实现

每个后面加if循环或者每个命令之间用&&连接只有前面的执行成功后面的才会进行

最好方法  ser -e  如果出错 里面停止执行

-n(nonzero) $..判读是否空  --z

|wc -L统计字符数 length  wc 是统计工具 2 10 158  意思是2行10个单词 158 个字节

${#sg}   也可以

id feng 判断用户feng 是否存在

  1. case 多分支
  2. #!/bin/bash
  3. case  $1  in
  4. start)
  5.                                                 echo  "service is  start"
  6.                                                 mkdir  feng$RANDOM
  7.                                                 ;;
  8. stop)
  9.                                                 echo "service is stop"
  10.                                                 ;;
  11. restart|reload)
  12.                                                 echo  "service is restart|reload"
  13.                                                 ;;
  14. *)
  15.                                                 echo  "usage: $0 start|stop|restart|reload"
  16. esac

整数的比较  --》(($1 >=90  ))  && (( $1 <= 100   ))

&&

(( $1 >=90  &&  $1 <= 100 ))

if  条件1  ;then

                                                         命令1

elif  条件2 ;then

                                                         命令2

elif  条件3 ;then

                                                         命令3

elif  条件4 ;then

                                                         命令4

else

                                                         命令5

fi

  1. >&2 错误的重定向输出
  2. exit 1 (1是返回值 范围是1-255)

basename 得到绝对路径的文件名

dirname 获得绝对路径的目录

#定义一个函数sum

sum() {

        total=$(( $1 + $2))

        echo  "$1 + $2 = $total"

        return 0

}

#调用

sum  50 60

脚本外面的位置变量如何传递到函数里?

[root@localhost shell]# cat f2.sh

#!/bin/bash

#定义一个函数sum

num1=$1

num2=$2

sum() {

        total=$(( $num1 + $num2))

        echo  "$num1 + $num2 = $total"

        return 0

}

#调用

sum

[root@localhost shell]# bash f2.sh 60 70

60 + 70 = 130

shell 编程里面变量是全局变量 可以互相调用 A函数可以调用B函数里面的变量

在变量前面加local可以变成局部变量

cd /etc/init.d    vim functions里面定义了function 里面很多函数

python/java调用库 import  c语言是include

shell脚本在执行的时候的4种方式

在当前bash进程里启用一个子进程去执行脚本f1.sh

1.  bash  f1.sh

2.  ./f1.sh    需要脚本文件f1.sh具有可执行权限(相对路径执行)

在当前bash进程里执行脚本f1.sh(父进程)

3.  .  f1.sh

4.  source  f1.sh

[root@localhost shell]# bash f1.sh

50 + 60 = 110

[root@localhost shell]# ./f1.sh  相对路径执行

-bash: ./f1.sh: 权限不够

[root@localhost shell]# . f1.sh

50 + 60 = 110

[root@localhost shell]# source f1.sh

50 + 60 = 110

[root@localhost shell]# /shell/f1.sh   绝对路径执行

-bash: /shell/f1.sh: 权限不够

export sg meinv 输出这两个变量转换为全局变量 这

[root@localhost shell]# chmod +x  f1.sh  授予f1.sh 可执行权限  execute  

[root@localhost shell]# ./f1.sh

50 + 60 = 110

[root@localhost shell]# /shell/f1.sh

50 + 60 = 110

[root@localhost shell]# ll

总用量 44

-rw-r--r--. 1 root root   63 4月  19 16:57 app.log

-rw-r--r--  1 root root  227 5月   9 15:26 case.sh

-rw-r--r--. 1 root root   91 4月  19 17:01 cpu_usage.log

-rwxr-xr-x  1 root root  124 5月   9 16:09 f1.sh

-rw-r--r--  1 root root  195 5月   9 16:19 f2.sh

drwxr-xr-x  2 root root    6 5月   9 15:26 feng28595

-rw-r--r--. 1 root root  693 4月  19 17:01 monitor_cpu_disk.py

-rw-r--r--. 1 root root  471 4月  19 16:30 monitor_cpu_disk.sh

-rw-r--r--. 1 root root  467 4月  19 17:04 monitor_disk.py

-rw-r--r--. 1 root root  239 4月  19 17:11 monitor_disk.sh

-rwxr-xr-x  1 root root 3245 5月   9 15:28 service

-rw-r--r--. 1 root root   42 4月  19 16:28 test.sh

https://nginx.org/download/nginx-1.24.0.tar.gz

解压缩 tar xf nginx-1.24.0.tar.gz

cd  nginx-1.24.0进入解压后的文件夹

lscpu 查看cpu核心

cd /usr/local/nginx1/html/ 进入存放网页的目录

ls

index.html 首页文件 进入网站第一个看到的页面

在vim 脚本里面加上<meta charset=”UTF-8”> 让网页里面可以用中文

卸载脚本
[root@localhost shell]# vim uninstall_nginx.sh 
[root@localhost shell]# cat uninstall_nginx.sh 
#!/bin/bash
#停止运行的nginx
/usr/local/nginx1/sbin/nginx  -s  stop
#删除安装目录
rm  -rf  /usr/local/nginx1
#清除开机启动nginx
sed -i  &apos;/nginx1/ s/^/#/&apos; /etc/rc.local 
#删除用户
userdel  -r  liujinming
[root@localhost shell]# bash uninstall_nginx.sh 执行脚本


安装的脚本
[root@localhost shell]# vim onekey_install_nginx.sh 
[root@localhost shell]# cat onekey_install_nginx.sh 
#!/bin/bash
#解决软件的依赖关系
yum  install  pcre-devel  gcc   openssl-devel -y
#下载nginx源码包
mkdir -p  /nginx
cd  /nginx
curl(网站) -O(直接下载) https://nginx.org/download/nginx-1.24.0.tar.gz
#解压压缩包
tar xf nginx-1.24.0.tar.gz 
#进入解压后的文件夹
cd nginx-1.24.0
#编译前的配置
./configure(软件提供 在里面选参数)  --prefix=/usr/local/nginx1  --user=liujinming   --group=liujinming   --with-http_ssl_module  --with-http_v2_module --with-http_sub_module 
#编译,将c语言的代码编译成二进制程序
make  -j 2(开两个进程 建议开启个数和cpu一样)当你有一个多核 CPU 时,每个核心都可以独立地运行一个任务。如果 make 只运行一个任务,那么其他核心将处于空闲状态,这浪费了计算资源。通过增加 -j 的值,你可以让 make 同时运行多个任务,从而更充分地利用 CPU 的所有核心。
#编译安装,将编译好的二进制程序复制到我们指定的安装路径下/usr/local/nginx1
make  install
#运行nginx
useradd  liujinming
/usr/local/nginx1/sbin/nginx
#开机启动,系统在开机的时候会自动去执行rc.local文件里面的命令
chmod +x /etc/rc.d/rc.local
echo  "/usr/local/nginx1/sbin/nginx"  >>/etc/rc.local
#关闭防火墙服务
service firewalld  stop
#设置防火墙服务开机不启动
systemctl disable  firewalld
[root@localhost shell]# bash onekey_install_nginx.sh 执行脚本

  • 29
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值