在本文中,您将会了解到关于centos脚本基础练习2的新资讯,同时我们还将为您解释centos脚本怎么写的相关在本文中,我们将带你探索centos脚本基础练习2的奥秘,分析centos脚本怎么写的特点
在本文中,您将会了解到关于centos 脚本基础练习2的新资讯,同时我们还将为您解释centos脚本怎么写的相关在本文中,我们将带你探索centos 脚本基础练习2的奥秘,分析centos脚本怎么写的特点,并给出一些关于aauto 快手编程基础练习一、ansible 练习2 --剧本基础、CentOS 7 Shell 脚本编程第十一讲 if 语句和简单练习、CentOS 7上安装WordPress详细步骤 centos7忘记 centos7的pxe centos7加的实用技巧。
本文目录一览:- centos 脚本基础练习2(centos脚本怎么写)
- aauto 快手编程基础练习一
- ansible 练习2 --剧本基础
- CentOS 7 Shell 脚本编程第十一讲 if 语句和简单练习
- CentOS 7上安装WordPress详细步骤 centos7忘记 centos7的pxe centos7加
centos 脚本基础练习2(centos脚本怎么写)
练习1, 写一个脚本 判定命令历史中历史命令的总条目是否大于1000; 如果大于,则显示“Some command will gone.”;否则显示“ok”. [root@localhost mscripts]# cat lx5.sh #!/bin/bash TOTALS=history | tail -1 | cut -d' ' -f2
if [ $TOTALS -gt 1000 ]; then echo "some command will gone." else echo "ok." fi
练习2 写一个脚本 给定一个用户,获取其密码警告期限;而后判断用户密码使用期限是否已经小于警告期限;如果小于,则显示“Warning”;否则,显示“OK” cat lx6.sh #/bin/bash USERNAMES=bruce //指定一个用户 NowDAY=date +%s
//现在的时间 LASTDAYS=grep "bruce" /etc/shadow | cut -d: -f3
//最近一次修改密码的时间 MAXDAYS=grep "bruce" /etc/shadow | cut -d: -f5
//最长使用期限 WARNDAYS=grep "bruce" /etc/shadow | cut -d: -f6
//警告时间 PASTDAYS=$[$(($NowDAY/86400))-$LASTDAYS] //已经使用时间 ZDAYS=$(($MAXDAYS-$PASTDAYS)) //最终还剩下时间 if [ $ZDAYS -lt $WARNDAYS ]; then echo "Warning." else echo "OK!" fi
aauto 快手编程基础练习一
aauto快手编程练习一 打印九九乘法表。
io.open();
for(i=1;9){
for(j=1;i){
io.stdout.write(string.format("%d*%d=%d ",i,j,i*j));
}
io.print(''\n'');
}
execute("pause");
io.close();
/*
需要注意的地方
1、io.stdout.write(string.format("%d*%d=%d ",i,j,i*j));
2、io.print(''\n''); 是单引号,不是双引号
*/
下面是结果图片:
ansible 练习2 --剧本基础
playbook
yaml语法:
1.文件后缀一般为 .yml 或者 .yaml
2.文件开头一般为 —
3.注释使用 #
4.缩进代表层级结构,一般为俩个空格
5.数据结构:
列表 : - 短横线后跟一个空格
例如: - name
字典: 键值对
例如: name: tom :后跟一个空格
一、创建剧本config_Nginx.yml。完成以下功能:
1、安装Nginx
2、提供默认主页
3、启动并开机自启服务。
Nginx的默认路径为 /usr/share/Nginx/html
vim config_Nginx.yum
---
- host: dev
tasks:
- name: install Nginx
yum:
name: Nginx
- name: html
copy:
content: ''This is test page.\n''
dest: /usr/share/Nginx/html
- name: config service
service:
name: Nginx
state: started
enable: yes
- name: firewalld
firewalld:
service: Nginx
permanent: yes
immediate: yes
state: enabled
运行剧本:ansible-playbook 文件名 ansible-playbook 文件名 --Syntax-check 检测语法 ansible-playbook 文件名 -C空运行
二、创建一个名为packages.yml的剧本
1、在dev, prod 和 test 主机组中安装 PHP 和 mariadb 软件包
2、在dev 主机组中安装 Development Tools 包组
3、升级dev主机组中主机的所有软件包
方法一: 编写为3个play
---
- name: play 1
hosts: dev,prod,test
tasks:
- name: install PHP and mariadb
yum:
name:
- PHP
- mariadb
- name: play 2
hosts: dev
tasks:
- name: install Development Tools
yum:
name: "@Development Tools"
- name: play 3
hosts: dev
tasks:
- name: updage all
yum:
name: ''*''
state: latest
方法2:编写2个play
---
- name: play 1
hosts: dev,prod,test
tasks:
- name: install PHP and mariadb
yum:
name:
- PHP
- mariadb
- name: play 2
hosts: dev
tasks:
- name: install Development Tools
yum:
name: "@Development Tools"
- name: updage all
yum:
name: ''*''
state: latest
总结
以上是小编为你收集整理的ansible 练习2 --剧本基础全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
原文地址:https://blog.csdn.net/weixin_57395956/article/details/121583526
CentOS 7 Shell 脚本编程第十一讲 if 语句和简单练习
Shell if 语句通过表达式与关系运算符判断表达式真假来决定执行哪个分支。有三种 if ... else 语句:
if ... fi 语句;
if ... else ... fi 语句;
if ... elif ... else ... fi 语句。
首先需要记住 if 和 fi 成对出现。先看一个简单脚本。
#表达式语句结构
if <条件表达式> ;then
指令
fi
#上下两条语句等价
if <条件表达式>
then
指令
fi
#判断输入是否为yes,没有判断其他输入操作
[root@promote ~]# cat testifv1.0.sh
#!/bin/bash
read -p "please input yes or no: " input
if [ $input == "yes" ] ;then
echo "yes"
fi
#请勿直接回车
[root@promote ~]# bash testifv1.0.sh
please input yes or no: yes
yes
[root@promote ~]#
if 语句条件表达式为真时,执行后续语句,为假时,不执行任何操作;语句结束。单分支结构。
再看一个稍微复杂代码。
[root@promote ~]# cat testifv1.1.sh
#!/bin/bash
read -p "please input yes or no: " input ;
if [ $input == "yes" -o $input == "y" ]
then
echo "yes"
fi
[root@promote ~]# vim testifv1.2.sh
[root@promote ~]# bash testifv1.2.sh
please input yes or no: y
yes
[root@promote ~]#
[root@promote ~]# bash testifv1.2.sh
please input yes or no: n
[root@promote ~]#
if else 语句是双分支结构。含有两个判断结构,判断条件是否满足任意条件,满足 if then 语句块直接执行语句,else 执行另一个语句。语句结构类比单分支结构。
[root@promote ~]# cat testifv1.3.sh
read -p "please input yes or no: " input ;
if [ $input == "yes" -o $input == "y" ]
then
echo "yes"
else
echo "no yes"
fi
[root@promote ~]# bash testifv1.3.sh
please input yes or no: n
no yes
[root@promote ~]# bash testifv1.3.sh
please input yes or no: yes
yes
[root@promote ~]#
需要注意 else 无需判断,直接接语句。
if else 语句判断条件更多,可以称为多分支结构。
[root@promote ~]# cat testifv1.4.sh
#!/bin/bash
read -p "please input yes or no: " input
if [ $input == "yes" -o $input == "y" ]
then
echo "yes"
elif [ $input == "no" -o $input == "n" ]
then
echo "no"
else
echo "not yes and no"
fi
[root@promote ~]#
[root@promote ~]# bash testifv1.4.sh
please input yes or no: yes
yes
[root@promote ~]# bash testifv1.4.sh
please input yes or no: y
yes
[root@promote ~]# vim testifv1.4.sh
[root@promote ~]# bash testifv1.4.sh
please input yes or no: no
no
[root@promote ~]# bash testifv1.4.sh
please input yes or no: n
no
[root@promote ~]# bash testifv1.4.sh
please input yes or no: ssss
not yes and no
再看几个简单实例。
#判断是否为文件
#!/bin/bash
if [ -f /etc/hosts ]
then
echo "is file"
fi
#判断是否是root用户
[root@promote ~]# cat isroot.sh
#!/bin/bash
if [ "$(whoami)"=="root" ]
then
echo "root user"
else
"not root user"
fi
[root@promote ~]# bash isroot.sh
root user
CentOS 7上安装WordPress详细步骤 centos7忘记 centos7的pxe centos7加
一、搭建
php 5.2.4 或者更高版本、MySQL 5.0 或者更高版本。
二、搭建Wordpress平台:
以下以Wordpress3.92版本为例进行说明,如果大家想安装最近版本的话,安装完成后再管理界面可以自动升级安装最新版本。
1、建立一个临时文件夹,下载最新版本的Wordpress3.92,中英文都可以:
mkdir /tmp/wp cd /tmp/wp wget http://wordpress.org/latest.zip
2、解压缩到网站根目录: 由于我是使用的LAMP一键安装包安装的LAMP,所以默认网站根目录为/data/www/default,大家在实际安装过程中注意自己的根目录。
unzip -q latest.zip -d /data/www/default/
3、更改wordpree文件夹属主和权限
chown -R apache:apache /data/www/default/wordpresschmod -R 755 /data/www/default/wordpress
4、创建一个可以上传的目录upload,并将属主改为apache
mkdir -p /data/www/default/wordpress/wp-content/uploads chown -R :apache /data/www/default/wordpress/wp-content/uploads
5、修改配置文件,以便可以访问数据库
cd /data/www/default/wordpress/ cp wp-config-sample.php wp-config.php vim wp-config.php 修改部分分别为数据库名称、数据库用户名、数据库用户密码,大家根据实际修改: define(''DB_NAME'', ''wp_database''); define(''DB_USER'', ''root''); define(''DB_PASSWORD'', ''root''); 修改完成后 :wq!
6、浏览器浏览 安装
浏览器输入http://http://127.0.0.1/wordpress/wp-admin/install.php 后就可以进行最后的登陆安装: 输入站点名称,登陆户名,密码,邮箱就可以完成Wordpress的安装。 由于我是本地搭建的,所以是127.0.0.1,如果申请了域名,这里就是域名了。
7、开启支持网站固定链接修改和重定向功能。 编辑主配置文件:
vi /etc/httpd/conf/httpd.conf AllowOverride None 修改为: AllowOverride All 然后重启服务: systemctl restart httpd.service 创建.htaccess文件: touch /data/www/default/wordpress/.htaccess 编辑.htaccess文件: vim /data/www/default/wordpress/.htaccess 看是否有以下内容,没有自己添加,有可能网站会自动生成。 <ifmodule> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L]</ifmodule> 修改.htaccess文件权限: chmod 664 /data/www/default/wordpress/.htaccess 修改为664可以让网站支持自动更新,也可以修改为644。
至此,Wordpress在Centos7上已经完全安装了,可以用它搭建你想要的任意网站了。
本文转载自:http://www.linuxprobe.com/centos7-install-wordpress-detail-steps/
免费提供最新Linux技术教程书籍,为开源技术爱好者努力做得更多更好:http://www.linuxprobe.com/
以上就介绍了CentOS 7上安装WordPress详细步骤,包括了wordpress,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
关于centos 脚本基础练习2和centos脚本怎么写的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于aauto 快手编程基础练习一、ansible 练习2 --剧本基础、CentOS 7 Shell 脚本编程第十一讲 if 语句和简单练习、CentOS 7上安装WordPress详细步骤 centos7忘记 centos7的pxe centos7加等相关知识的信息别忘了在本站进行查找喔。
本文标签: