1+X 云计算运维与开发 项目八 脚本运维与开发 (初中级)模拟题题目(附答案,共4题)

1+X 云计算运维与开发 项目八 脚本运维与开发 (初中级)模拟题题目(附答案,共4题)

链接: 其他题目链接.

Shell脚本补全(40分)

下面有一段脚本,作用是自动配置redis服务,由于工程师的失误,将脚本中的某些代码删除了,但注释还在,请根据注释,填写代码。最后将填写的代码按照顺序以文本形式提交至答题框。

redis(){ 
cd 
#修改redis的配置文件,将bind 127.0.0.1注释 
sed -i (此处填写) /etc/redis.conf 

#修改redis的配置文件,将protected-mode yes改为protected-mode no 
sed -i (此处填写) /etc/redis.conf 

#启动redis服务 
systemctl start redis 

#设置开机自启
systemctl enable redis 
if [ $? -eq 0 ] 
	then 
		sleep 3 
		echo -e "\033[36m==========redis启动成功==========\033[0m"
	 else 
		echo -e "\033[31m******redis启动失败,请检查******\033[0m" 
	exit 1 
fi 
sleep 2 }
参考答案:
sed -i 's/bind 127.0.0.1/#bind 127.0.0.1/g' /etc/redis.conf

sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf

Shell脚本补全(40分)

下面有一段脚本,作用是自动配置mysql服务,由于工程师的失误,将脚本中的某些代码删除了,但注释还在,请根据注释,填写代码。最后将填写的代码按照顺序以文本形式提交至答题框。

脚本如下所示: 
mariadb(){ 
cd 
#在数据库的my.cnf文件添加内容如下 (此处需填写)
 [mysqld] 
init_connect='SET 
collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake 
EOF 
#启动数据库
 systemctl start mariadb 
#设置数据库root的密码为123456 
mysqladmin -uroot password 123456 
#创建gpmall数据库,并将gpmall.sql文件导入 
mysql -uroot -p123456 << 

(此处需填写) 
use gpmall 
source /root/gpmall.sql 
EOF 

#设置开机自启数据库 
systemctl enable mariadb 

#重启数据库服务 
systemctl restart mariadb 

#检查数据库是否重启成功 
if [ $? -eq 0 ] 
	then 
		sleep 3 
		echo -e "\033[36m==========maridb启动成功=========\033[0m" 		
	else 
		echo -e "\033[31m**********mariadb启动失败,请检查**********\033[0m" 
		exit 1 
	fi 
sleep 2 }

参考答案:
cat >> /etc/my.cnf << EOF
create database gpmall;

Shell脚本补全(40分)

下面有一段脚本,作用是自动配置nginx服务,由于工程师的失误,将脚本中的某些代码删除了,但注释还在,请根据注释,填写代码。最后将填写的代码按照顺序以文本形式提交至答题框。

nginx(){ 
cd 
#删除默认项目路径下的文件
rm -rf /usr/share/nginx/html/*
#将提供的dist静态文件复制到nginx项目目录 
cp -rvf /root/dist/* /usr/share/nginx/html 
#修改nginx配置文件如下 
cat > /etc/nginx/conf.d/default.conf << EOF
server 
{	listen 80; 
	server_name localhost; 
#charset koi8-r; 
#access_log /var/log/nginx/host.access.log main; 
	location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
	location /user { (此处需要填写) } 

	location /user {
		proxy_pass http://127.0.0.1:8082;
	}
	location /shopping {
		proxy_pass http://127.0.0.1:8081;
	}
	error_page 500 502 503 504 /50x.html; 
	location = /50x.html {
        root   /usr/share/nginx/html;
}
EOF #启动nginx服务 
systemctl start nginx

#设置nginx开机自启 
(此处需填写)

#检查nginx服务是否成功启动 
if [ $? -eq 0 ]
 	then
		sleep 3 
		echo -e "\033[36m==========nginx启动成功==========\033[0m" 
 	else 
		echo -e "\033[31m**********nginx启动失败,请检查**********\033[0m" 
		exit 1
fi 
sleep 2 }
  
参考答案:
proxy_pass http://127.0.0.1:8082;
systemctl enable nginx

Python脚本补全(40分)

下面有一段Python脚本,由于工程师的失误,将脚本中的某些代码删除了,但注释还在,请根据注释,填写代码。最后将填写的代码按照顺序以文本形式提交至答题框。

Python脚本如下: 
def get_html(url, encoding='utf-8'):
# 定义
headers headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } 
# 调用requests依赖包的get方法,请求该网址,返回response (此处需填写)

# 设置response字符为utf-8 (此处需填写)
 
# 返回response的文本 
return response.text

参考答案:
response = requests.get(url, headers=headers)
response.encoding = encoding
发布了24 篇原创文章 · 获赞 13 · 访问量 4577

猜你喜欢

转载自blog.csdn.net/weixin_43663238/article/details/105779373
今日推荐