ansible安装

(1)环境准备
在两台机器上关闭防火墙和SELinux,并修改/etc/hosts文件。
[root@ansible-test1 ~]# systemctl stop firewalld
[root@ansible-test1 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@ansible-test1 ~]# setenforce 0
[root@ansible-test1 ~]# cat /etc/selinux/config

disabled - No SELinux policy is loaded.
SELINUX=disabled //将此处改为disabled
SELINUXTYPE= can take one of three two values:

[root@ansible-test1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.10 ansible-test1 //添加两台主机的ip和主机名
192.168.2.20 ansible-test2
(2)安装ansible
准备两台机器anisble-01和anisble-02,只需要在anisble-01上安装ansible,先安装epel仓库。
[root@ansible-test1 ~]# yum install epel-release -y
[root@ansible-test1 ~]# yum install -y ansible
[root@ansible-test1 ~]# ansible --version
ansible 2.9.10
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
(3)免密配置
anisble-01上生成密钥对 ssh-keygen -t rsa ,把公钥放到anisble-02上,设置密钥认证。
注:需要将本机也配置免密。
[root@ansible-test1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0a:47:86:44:83:a2:7c:c3:0c:1b:33:1c:03:88:0c:09 root@ansible-test1
The key’s randomart image is:
±-[ RSA 2048]----+
|E+.o+ |
|=Bo. o |
|o.O . o |
|.o = o |
| . o . S |
| o . |
| . |
| |
| |
±----------------+
[root@ansible-test1 ~]# ssh-copy-id 192.168.2.20
The authenticity of host ‘192.168.2.20 (192.168.2.20)’ can’t be established.
ECDSA key fingerprint is dc:a5:08:4d:9a:40:8a:be:ee:68:dd:41:61:7d:d7:05.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
root@192.168.2.20’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘192.168.2.20’”
and check to make sure that only the key(s) you wanted were added.

[root@ansible-test1 ~]# ssh 192.168.2.20
Last login: Sat Jul 4 16:49:18 2020 from 192.168.2.3
[root@ansible-test2 ~]# 登出
Connection to 192.168.2.20 closed.
(4)主机组设置
在/etc/ansible/hosts文件中添加本机和另一台机器的ip
[root@ansible-test1 ~]# grep [#] /etc/ansible/hosts
[testhost]
127.0.0.1
192.168.2.20
说明: testhost为自定义的主机组名字,下面两个ip为组内的机器ip。
**

ansible远程执行命令

**
这样就可以批量执行命令了。这里的testhost 为主机组名,-m后边是模块名字,-a后面是命令。当然我们也可以直接写一个ip,针对某一台机器来执行命令。
还有一个模块就是shell同样也可以实现 。
[root@ansible-test1 ~]# ansible testhost -m command -a “hostname”
127.0.0.1 | CHANGED | rc=0 >>
ansible-test1
192.168.2.20 | CHANGED | rc=0 >>
ansible-test2
[root@ansible-test1 ~]# ansible 192.168.2.20 -m command -a “hostname”
192.168.2.20 | CHANGED | rc=0 >>
ansible-test2

ansible拷贝文件或目录

源目录会放到目标目录下面去,如果目标指定的目录不存在,它会自动创建。如果拷贝的是文件,dest指定的名字和源如果不同,并且它不是已经存在的目录,相当于拷贝过去后又重命名。但相反,如果desc是目标机器上已经存在的目录,则会直接把文件拷贝到该目录下面。
[root@ansible-test1 ~]# ansible 192.168.2.20 -m copy -a “src=/etc/passwd dest=/tmp/123”
192.168.2.20 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“checksum”: “8f3ebea24b1558e6207af80195aa12931d96345f”,
“dest”: “/tmp/123”,
“gid”: 0,
“group”: “root”,
“md5sum”: “ca8f3327c9a73cb6fd96ba88ec4d18ee”,
“mode”: “0644”,
“owner”: “root”,
“secontext”: “unconfined_u:object_r:admin_home_t:s0”,
“size”: 1040,
“src”: “/root/.ansible/tmp/ansible-tmp-1593856449.24-11462-53060923085626/source”,
“state”: “file”,
“uid”: 0
}
这里的/tmp/123和源机器上的/etc/passwd是一致的,但如果目标机器上已经有/tmp/123目录,则会再/tmp/123目录下面建立passwd文件。
**

ansible远程执行脚本

**
首先创建一个shell脚本。
[root@ansible-test1 ~]# cat /tmp/test.sh
#!/bin/bash
echo date > /tmp/ansible_test.txt
然后把该脚本分发到各个机器上。
[root@ansible-test1 ~]# ansible testhost -m copy -a “src=/tmp/test.sh dest=/tmp/test.sh
mode=0755”
192.168.2.20 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“checksum”: “1a6e4af02dba1bda6fc8e23031d4447efeba0ade”,
“dest”: “/tmp/test.sh”,
“gid”: 0,
“group”: “root”,
“md5sum”: “edfaa4371316af8c5ba354e708fe8a97”,
“mode”: “0755”,
“owner”: “root”,
“secontext”: “unconfined_u:object_r:admin_home_t:s0”,
“size”: 48,
“src”: “/root/.ansible/tmp/ansible-tmp-1593856700.7-11499-220274653312920/source”,
“state”: “file”,
“uid”: 0
}
127.0.0.1 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“checksum”: “1a6e4af02dba1bda6fc8e23031d4447efeba0ade”,
“dest”: “/tmp/test.sh”,
“gid”: 0,
“group”: “root”,
“mode”: “0755”,
“owner”: “root”,
“path”: “/tmp/test.sh”,
“secontext”: “unconfined_u:object_r:user_tmp_t:s0”,
“size”: 48,
“state”: “file”,
“uid”: 0
}
最后是批量执行该shell脚本。
[root@ansible-test1 ~]# ansible testhost -m shell -a “/tmp/test.sh”
127.0.0.1 | CHANGED | rc=0 >>

192.168.2.20 | CHANGED | rc=0 >>

shell模块,还支持远程执行命令并且带管道。
[root@ansible-test1 ~]# ansible testhost -m shell -a "cat /etc/passwd |wc -l "
127.0.0.1 | CHANGED | rc=0 >>
21
192.168.2.20 | CHANGED | rc=0 >>
21
[root@ansible-test1 ~]# cat /tmp/ansible_test.txt //
2020年 07月 04日 星期六 18:00:51 CST
运行成功。
**

ansible管理任务计划

**
创建任务计划,命名并定义工作。
[root@ansible-test1 ~]# ansible testhost -m cron -a “name=‘test cron’ job=’/bin/bash
/tmp/test.sh’ weekday=6”
127.0.0.1 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“envs”: [],
“jobs”: [
“test cron”
]
}
192.168.2.20 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“envs”: [],
“jobs”: [
“test cron”
]
}
若要删除该cron 只需要加一个字段 state=absent 。
[root@ansible-test1 ~]# ansible testhost -m cron -a “name=‘test cron’ state=absent”
127.0.0.1 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“envs”: [],
“jobs”: []
}
192.168.2.20 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“envs”: [],
“jobs”: []
}
其他的时间表示:分钟 minute 小时 hour 日期 day 月份 month。
**

ansible安装rpm包/管理服务

**
使用yum模块安装httpd服务。
[root@ansible-test1 ~]# ansible testhost -m yum -a “name=httpd”
127.0.0.1 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“changes”: {
“installed”: [
“httpd”
]
},
“msg”: “”,
“rc”: 0,
“results”: [


\n\nComplete!\n"
]
}
192.168.2.20 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“changes”: {
“installed”: [
“httpd”
]
},
“msg”: “”,
“rc”: 0,
“results”: [

\n\nComplete!\n"
]
}
在name后面还可以加上state=installed/removed
设置服务状态,这里的name是centos系统里的服务名,可以通过chkconfig --list查到。
[root@ansible-test1 ~]# ansible testhost -m service -a “name=httpd state=started enabled=yes”
127.0.0.1 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“enabled”: true,
“name”: “httpd”,
“state”: “started”,
“status”: {

“WatchdogTimestampMonotonic”: “0”,
“WatchdogUSec”: “0”
}
}
192.168.2.20 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: true,
“enabled”: true,
“name”: “httpd”,
“state”: “started”,
“status”: {

“WatchdogUSec”: “0”
}
}
Ansible文档的使用
[root@ansible-test1 ~]# ansible-doc -l //列出所有模块
fortios_router_community_list Configure community lists in Fortinet’s FortiOS …
azure_rm_devtestlab_info Get Azure DevTest Lab facts
ecs_taskdefinition register a task definition in ecs
avi_alertscriptconfig Module for setup of AlertScriptConfig Avi RESTfu…
tower_receive Receive assets from Ansible Tower
netapp_e_iscsi_target NetApp E-Series manage iSCSI target configuratio…
azure_rm_acs Manage an Azure Container Service(ACS) instance

[root@ansible-test1 ~]# ansible-doc yum //查看指定模块的文档

YUM (/usr/lib/python2.7/site-packages/ansible/modules/packaging/os/yum.py)

    Installs, upgrade, downgrades, removes, and lists packages and groups with the `yum'package manager. This module only works on Python 2. If you require Python 3 supportsee the [dnf] module.
  • This module is maintained by The Ansible Core Team
  • note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

  • allow_downgrade
    Specify if the named package and version is allowed to downgrade a maybe already
    installed higher version of that package. Note that setting allow_downgrade=True can
    make this module behave in a non-idempotent way. The task could end up with a set of
    packages that does not match the complete list of specified packages to install
    (because dependencies between the downgraded package and others can cause changes to
    the packages which were in the earlier transaction).
    [Default: no]
    type: bool
    version_added: 2.4

**

ansible playbook使用

**

ansible playbook中的使用

相当于把模块写入到配置文件里面,例:
[root@ansible-test1 ansible]# cat /etc/ansible/test.yml

  • hosts: 192.168.2.20
    remote_user: root
    tasks:
    • name: test_playbook
      shell: touch /tmp/playbook_test.txt
      说明:第一行需要有三个杠,hosts参数指定了对哪些主机进行参作,如果是多台机器可以用逗号作为分隔,也可以使用主机组,在/etc/ansible/hosts里定义,user参数指定了使用什么用户登录远程主机操作,tasks指定了一个任务,其下面的name参数同样是对任务的描述,在执行过程中会打印出来,shell是ansible模块名字
      [root@ansible-test1 ansible]# ansible-playbook test.yml

PLAY [192.168.2.20] ***********************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [192.168.2.20]

TASK [test_playbook] **********************************************************************************************
[WARNING]: Consider using the file module with state=touch rather than running ‘touch’. If you need to use
command because file is insufficient you can add ‘warn: false’ to this command task or set
‘command_warnings=False’ in ansible.cfg to get rid of this message.
changed: [192.168.2.20]

PLAY RECAP ********************************************************************************************************
192.168.2.20 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
再来一个创建用户的例子:
[root@ansible-test1 ansible]# cat create_user.yml

  • name: create_user
    hosts: 192.168.2.20
    user: root
    gather_facts: false
    vars:
    • user: “test”
      tasks:
    • name: create user
      user: name="{{ user }}"
      说明:name参数对该playbook实现的功能做一个概述,后面执行过程中,会打印 name变量的值 ,可以省略;gather_facts参数指定了在以下任务部分执行前,是否先执行setup模块获取主机相关信息,这在后面的task会使用到setup获取的信息时用到;vars参数,指定了变量,这里指字一个user变量,其值为test ,需要注意的是,变量值一定要用引号引住;user提定了调用user模块,name是user模块里的一个参数,而增加的用户名字调用了上面user变量的值。
      [root@ansible-test1 ansible]# ansible-playbook create_user.yml

PLAY [create_user] ************************************************************************************************

TASK [create user] ************************************************************************************************
changed: [192.168.2.20]

PLAY RECAP ********************************************************************************************************
192.168.2.20 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
**

ansible playbook中的循环

**
创建while.yml文件
[root@ansible-test1 ansible]# cat while.yml

  • hosts: testhost
    user: root
    tasks:
    • name: change mode for files
      file: path=/tmp/{{ item }} mode=600
      with_items:
      • 1.txt
      • 2.txt
      • 3.txt
        说明: with_items为循环的对象
        执行while.yml。
        [root@ansible-test1 ansible]# ansible-playbook while.yml

PLAY [testhost] ***************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [127.0.0.1]
ok: [192.168.2.20]

TASK [change mode for files] **************************************************************************************
ok: [127.0.0.1] => (item=1.txt)
changed: [192.168.2.20] => (item=1.txt)
ok: [127.0.0.1] => (item=2.txt)
changed: [192.168.2.20] => (item=2.txt)
ok: [127.0.0.1] => (item=3.txt)
changed: [192.168.2.20] => (item=3.txt)

PLAY RECAP ********************************************************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.2.20 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
**

ansible playbook中的条件判断

**
创建when.yml文件。
[root@ansible-test1 ansible]# cat when.yml

  • hosts: testhost
    user: root
    gather_facts: True
    tasks:
    • name: use when
      shell: touch /tmp/when.txt
      when: ansible_eno16777736.ipv4.address == “192.168.2.20”
      说明:ansible anisble-02 -m setup 可以查看到所有的facter信息
      执行when.yml。
      [root@ansible-test1 ansible]# ansible-playbook when.yml

PLAY [testhost] ***************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [127.0.0.1]
ok: [192.168.2.20]

TASK [use when] ***************************************************************************************************
skipping: [127.0.0.1]
[WARNING]: Consider using the file module with state=touch rather than running ‘touch’. If you need to use
command because file is insufficient you can add ‘warn: false’ to this command task or set
‘command_warnings=False’ in ansible.cfg to get rid of this message.
changed: [192.168.2.20]

PLAY RECAP ********************************************************************************************************
127.0.0.1 : ok=1 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
192.168.2.20 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

ansible playbook中的handlers

执行task之后,服务器发生变化之后要执行的一些操作,比如我们修改了配置文件后,需要重启一下服务,创建handlers.yml文件加入如下内容
[root@ansible-test1 ansible]# cat handlers.yml

  • name: handlers test
    hosts: 192.168.2.20
    user: root
    tasks:
    • name: copy file
      copy: src=/etc/passwd dest=/tmp/aaa.txt
      notify: test handlers
      handlers:
    • name: test handlers
      shell: echo “111111” >> /tmp/aaa.txt
      说明,只有copy模块真正执行后,才会去调用下面的handlers相关的操作。也就是说如果1.txt和2.txt内容是一样的,并不会去执行handlers里面的shell相关命令。 这种比较适合配置文件发生更改后,重启服务的操作。
      [root@ansible-test1 ansible]# ansible-playbook handlers.yml

PLAY [handlers test] **********************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [192.168.2.20]

TASK [copy file] **************************************************************************************************
changed: [192.168.2.20]

RUNNING HANDLER [test handlers] ***********************************************************************************
changed: [192.168.2.20]

PLAY RECAP ********************************************************************************************************
192.168.2.20 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

ansible playbook实战

ansible自动化安装nginx

(1)编译安装nginx
1)使用wget下载nginx包,下载地址:http://mirrors.sohu.com/nginx/nginx-1.9.6.tar.gz
2)解压下载的nginx包
./configure --prefix=/usr/local/nginx
make && make install
3)编写/etc/init.d/nginx文件
内容如下:
#!/bin/bash
chkconfig: - 30 21
description: http service.
Source Function Library
. /etc/init.d/functions
Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usx/local/nginx/logs/nginx.pid"
RETVAL=0
prog=“Nginx”

start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c NGINXCONFRETVAL=NGINX_CONF RETVAL=NGINXCONFRETVAL=?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID NGINXSBIN−TERMrm−rf/dev/shm/nginxtempRETVAL=NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=NGINXSBINTERMrmrf/dev/shm/nginxtempRETVAL=?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID NGINXSBIN−HUPRETVAL=NGINX_SBIN -HUP RETVAL=NGINXSBINHUPRETVAL=?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case “$1” in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $“Usage: $0 {start|stop|reload|restart|configtest}”
RETVAL=1
esac

exit $RETVAL
4)清空配置文件并重新编写

> /usr/local/nginx/conf/nginx.conf
内容如下:
user nobody nobody;		//定义nginx运行的用户和用户组
worker_processes 2;		//nginx进程数,一般为CPU总核心数
error_log /usr/local/nginx/logs/nginx_error.log crit;	//全局错误日志定义类型
pid /usr/local/nginx/logs/nginx.pid;	//进程文件
worker_rlimit_nofile 51200;
events		//工作模式与连接数上限
{
use epoll;
worker_connections 6000;
}
http		//http下的一些配置
{
include mime.types;		//文件扩展名与文件类型映射表
default_type application/octet-stream;		//默认文件类型
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;		//开启高效文件传输模式
tcp_nopush on;		//防止网络阻塞
keepalive_timeout 30;		//长连接超时时间,单位为秒
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;		//防止网络阻塞
gzip on;		//开启gzip压缩输出
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server		//虚拟主机配置
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/1ocal/nginx/html$fastcgi_script_name;
}
}
}

5)编写完成后可以检查一下
/usr/local/nginx/sbin/nginx -t
6)启动nginx
service nginx start
编译安装完成
(2)环境准备
1)将nginx.tar.gz复制到/etc/ansible/nginx_install/roles/install/files下
启动脚本和配置文件都放到/etc/ansible/nginx_install/roles/install/template下
mv nginx.tar.gz /etc/ansible/nginx_install/roles/install/files/
cp nginx/conf/nginx.conf /etc/ansible/nginx_install/roles/install/templates/
cp /etc/init.d/nginx /etc/ansible/nginx_install/roles/install/templates/
2)编写需要的yml文件
[root@ansible2 nginx_install]# cat install.yml

  • hosts: 192.168.2.101 //入口文件
    remote_user: root
    gather_facts: True
    roles:
    • common
    • install
      [root@ansible2 nginx_install]# cat roles/common/tasks/main.yml
  • name: install initialization require software //安装需要的依赖
    yum: name={{ item }} state=installed
    with_items:
    • zlib-devel
    • pcre-devel
    • gcc
      [root@ansible2 nginx_install]# cat roles/install/vars/main.yml
      nginx_user: www //定义所需变量
      nginx_port: 80
      nginx_basedir: /usr/local/nginx
      [root@ansible2 nginx_install]# cat roles/install/tasks/copy.yml
  • name: Copy Nginx Software //复制压缩包
    copy: src=nginx.tar.gz dest=/tmp/nginx.tar.gz owner=root group=root
  • name: Uncompression Nginx Software //解压压缩包
    shell: tar zxf /tmp/nginx.tar.gz -C /usr/local/
  • name: Copy Nginx Start Script //复制启动脚本
    template: src=nginx dest=/etc/init.d/nginx owner=root group=root mode=0755
  • name: Copy Nginx Config //复制nginx配置文件
    template: src=nginx.conf dest={{ nginx_basedir }}/conf/ owner=root group=root
    mode=0644
    [root@ansible2 nginx_install]# cat roles/install/tasks/install.yml
  • name: create nginx user //创建用户
    user: name={{ nginx_user }} state=present createhome=no shell=/sbin/nologin
  • name: start nginx service //开启服务
    shell: /etc/init.d/nginx start
  • name: add boot start nginx service //加入开机启动
    shell: chkconfig --level 345 nginx on
  • name: delete nginx compression files //删除压缩包
    shell: rm -rf /tmp/nginx.tar.gz
    [root@ansible2 nginx_install]# cat roles/install/tasks/main.yml
  • include: copy.yml //调用copy.yml和install.yml
  • include: install.yml
    (3)执行文件
    运行install.yml文件
    ansible-playbook /etc/ansible/nginx_install/install.yml
    注:要检查远程机器存在端口占用,及时卸载。
    结果如下:
    [root@ansible-01 ~]# ansible-playbook /etc/ansible/nginx_install/install.yml

PLAY [192.168.2.31] ****************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [192.168.2.31]

TASK [common : install initializtion requre software] ******************************************************************
[DEPRECATION WARNING]: Invoking “yum” only once while using a loop via squash_actions is deprecated. Instead of using a
loop to supply multiple items and specifying name: "{{ item }}", please use name: ['zlib-devel', 'pcre-devel'] and
remove the loop. This feature will be removed in version 2.11. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
ok: [192.168.2.31] => (item=[u’zlib-devel’, u’pcre-devel’])

TASK [install : Copy Nginx Software] ***********************************************************************************
changed: [192.168.2.31]

TASK [install : Uncompression Nginx Software] **************************************************************************
[WARNING]: Consider using the unarchive module rather than running ‘tar’. If you need to use command because unarchive
is insufficient you can add ‘warn: false’ to this command task or set ‘command_warnings=False’ in ansible.cfg to get
rid of this message.
changed: [192.168.2.31]

TASK [install : Copy Nginx Start Script] *******************************************************************************
ok: [192.168.2.31]

TASK [install : Copy Nginx Config] *************************************************************************************
ok: [192.168.2.31]

TASK [install : Create Nginx User] *************************************************************************************
ok: [192.168.2.31]

TASK [install : Start Nginx Service] ***********************************************************************************
changed: [192.168.2.31]

TASK [install : Add Boot start Nginx service] **************************************************************************
changed: [192.168.2.31]

TASK [install : Delete Nginx compression files] ************************************************************************
[WARNING]: Consider using the file module with state=absent rather than running ‘rm’. If you need to use command
because file is insufficient you can add ‘warn: false’ to this command task or set ‘command_warnings=False’ in
ansible.cfg to get rid of this message.
changed: [192.168.2.31]

PLAY RECAP *************************************************************************************************************
192.168.2.31 : ok=10 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

管理配置文件

生产环境中大多时候是需要管理配置文件的,安装软件包只是在初始化环境的时候用一下。下面我们来写个管理nginx配置文件的playbook。
[root@ansible2nginx_config]#cat
/etc/ansible/nginx_config/roles/new/handlers/main.yml

  • name: restart nginx //用于重新加载nginx服务
    shell: /etc/init.d/nginx reload
    [root@ansible2nginx_config]# cat /etc/ansible/nginx_config/roles/new/tasks/main.yml
  • name: copy conf file //复制.conf和hosts文件
    copy: src={{ item.src }} dest={{ nginx_basedir }}/{{ item.dest }} backup=yes owner=root group=root mode=0644
    with_items:
    • { src: nginx.conf, dest: conf/nginx.conf }
    • { src: vhosts, dest: conf/ }
      notify: restart nginx
      [root@ansible2 nginx_config]# cat /etc/ansible/nginx_config/roles/new/vars/main.yml
      nginx_basedir: /usr/local/nginx //定义变量
      [root@ansible2 nginx_config]# cat update.yml

  • hosts: 192.168.2.101 //入口文件
    user: root
    roles:
    • new //这里只有new
      old目录中的yml文件与new目录中的相同,files中的配置文件不同。
      其中new为更新时用到的,old为回滚时用到的,files下面为nginx.conf和vhosts目录,handlers为重启nginx服务的命令
      在执行update.yml前,应备份当前配置文件,当执行之后发现错误,则进行回滚操作,
      关于回滚,需要在执行playbook之前先备份一下旧的配置,所以对于老配置文件的管理一定要严格,千万不能随便去修改线上机器的配置,并且要保证new/files下面的配置和线上的配置一致,命令如下:
      rsync -av /etc/ansible/nginx_config/roles/new/
      /etc/ansible/nginx_config/roles/old/
      回滚操作就是把旧的配置覆盖,然后重新加载nginx服务, 每次改动nginx配置文件之前先备份到old里,对应目录为/etc/ansible/nginx_config/roles/old/files。
      更新操作结果:
      [root@ansible-01 nginx_config]# ansible-playbook /etc/ansible/nginx_config/update.yml

PLAY [testhost] ********************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [192.168.2.31]
ok: [127.0.0.1]

TASK [new : copy conf file] ********************************************************************************************
ok: [192.168.2.31] => (item={u’dest’: u’conf/nginx.conf’, u’src’: u’nginx.conf’})
ok: [127.0.0.1] => (item={u’dest’: u’conf/nginx.conf’, u’src’: u’nginx.conf’})
ok: [127.0.0.1] => (item={u’dest’: u’conf/’, u’src’: u’vhosts’})
changed: [192.168.2.31] => (item={u’dest’: u’conf/’, u’src’: u’vhosts’})

RUNNING HANDLER [new : restart nginx] **********************************************************************************
changed: [192.168.2.31]

PLAY RECAP *************************************************************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.2.31 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
回滚操作结果:
[root@ansible-01 nginx_config]# ansible-playbook /etc/ansible/nginx_config/rollback.yml

PLAY [testhost] ********************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [192.168.2.31]
ok: [127.0.0.1]

TASK [old : copy conf file] ********************************************************************************************
ok: [192.168.2.31] => (item={u’dest’: u’conf/nginx.conf’, u’src’: u’nginx.conf’})
ok: [127.0.0.1] => (item={u’dest’: u’conf/nginx.conf’, u’src’: u’nginx.conf’})
ok: [192.168.2.31] => (item={u’dest’: u’conf/’, u’src’: u’vhosts’})
ok: [127.0.0.1] => (item={u’dest’: u’conf/’, u’src’: u’vhosts’})

PLAY RECAP *************************************************************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.2.31 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

注:本次实验并未改变配置文件,故changed为0。

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. 打工四年总结的数据库知识点

    有情怀,有干货,微信搜索【三太子敖丙】关注这个不一样的程序员。 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试完整考点、资料以及我的系列文章。 国庆在家无聊,我随手翻了一下家里数据库相关的书籍&#xf…...

    2024/4/10 7:33:02
  2. 深圳数字货币来了 未来竞争格局还需观察

    宁夏女孩儿高妞妞,2017年12月来到深圳上班。昨晚,她在微信和微博中,都晒出了她的“中签”信息。   高妞妞中的是数字人民币的红包。12日晚间,包括她在内的5万深圳人接到短信,可以激活总计1000万元数字人民币红包。这…...

    2024/4/21 6:59:34
  3. VMware ESXi 5.0配置SSH密码登录

    一、esxi版本 二、esxi开启ssh登录 1、输入安装时设置的密码 2、选择Troubleshooting Options 3、开启SSH 三、身份认证方式 1、默认是使用密钥认证 2、修改为密码登录 回到ESXI5.0登录界面,在此画面按AltF1,出现以下界面。按AltF2可以切换回图形化界…...

    2024/4/27 16:47:39
  4. Invisor for Mac(媒体文件检查工具)v3.14免激活版

    Invisor for Mac破解版是一款简单易用的媒体文件检查工具,拥有显示有关您的视频、音频和照片文件的技术信息。兼容有关文件容器和媒体流的详细信息。此外,还能够比较收集的数据。 名称:Invisor for Mac(媒体文件检查工具) 类别:工…...

    2024/4/6 7:37:36
  5. 第一个vue程序,如何通过vue-model来渲染数据

    <!--第一个vue程序,介绍了如何用通过vue-model来渲染数据--> <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Title</title> </head> <body> <!--view层 模板--> <d…...

    2024/4/6 7:37:35
  6. c++引用专题之普通引用

    1引用&#xff08;普通引用&#xff09; 变量名回顾 变量名实质上是一段连续存储空间的别名&#xff0c;是一个标号(门牌号) 程序中通过变量来申请并命名内存空间 通过变量的名字可以使用存储空间 问题1&#xff1a;对一段连续的内存空间只能取一个别名吗&#xff1f; 1 引用概…...

    2024/4/6 7:37:34
  7. SAP HANA中重置SAP系统用户密码.

    在HANA系统中&#xff0c;SAP*和DDIC密码忘记&#xff0c;导致无法进入系统&#xff0c;重置上述系统账号密码方法如下&#xff1a; 1. 安装HANA Studio后&#xff0c;添加数据库&#xff0c;注意选择 “Teant Database”. 2. 必须登陆到SAPHANADB这个数据库用户下&#xff0c;…...

    2024/4/6 7:37:33
  8. 简单介绍python在CMD界面读取excel所有数据

    这篇文章主要介绍了python在CMD界面读取excel所有数据&#xff0c;帮助大家更好的利用python办公&#xff0c;感兴趣的朋友可以了解下 代码 import xlrd import os from prettytable import PrettyTable import pandas #创建一个Excel表类 class Excel(object):def __init__(…...

    2024/4/6 7:37:32
  9. js计算两个指定日期之间相差的月份

    js计算两个指定日期之间相差的月份 需求&#xff1a;如图实现下拉框显示指定月份到当月相差月份选项 使用&#xff1a; const monthArr getMonths(new Date("2019-10-10"),new Date("2020-10-10")); console.log(monthArr) /* [{"label":&qu…...

    2024/4/6 7:37:31
  10. 求解整数拆分问题【动态规划】【备忘录】

    问题描述 求讲正整数n无需拆分成最大数为k的拆分方案个数【f(n,k)】&#xff0c;要求所有的拆分方案不重复。 动态规划 f(n,k)满足动态规划问题的最优性原理、无后效性和有重叠子问题。 f(n,k): 当n1或k1&#xff0c;f(n,k)1当n<k&#xff0c;f(n,k)f(n,n)当nk&#xf…...

    2024/4/8 3:49:18
  11. windows server 2012下的桌面图标问题

    登录服务器中的windows server 2012&#xff0c;安装完成之后&#xff0c;默认只有回收站&#xff0c;至于我的电脑&#xff0c;文件夹以及控制面板等都不在&#xff0c;虽然都可以点击之后找到&#xff0c;但为了不麻烦&#xff0c;所以添加一些桌面图标对我来说&#xff0c;有…...

    2024/4/6 7:37:29
  12. 《管理学》第四章 计划(思维导图)

    《管理学》第四章 计划&#xff08;思维导图&#xff09; 前言 前天了解了思维导图工具&#xff0c;今天尝试一下。 按照两个内容写一下&#xff0c;一个是课本的思维导图&#xff0c;一个是MOOC的思维导图。 《管理学》第四章 计划 课本的思维导图 MOOC的思维导图 结尾 …...

    2024/4/6 7:37:28
  13. TopOpt | 88行拓展的71行拓扑优化程序完全注释. conv2

    The Corresponding Files (Click to Save): Code: top71.mReferences Efficient topology optimization in MATLAB using 88 lines of codeThe Related Artical (Click in): [TopOpt] 99行拓扑优化程序完全注释[TopOpt] 针对99行改进的88行拓扑优化程序完全注释…...

    2024/4/6 7:37:27
  14. 污水流量测量中污水出水流量计选型与应用

    流量计是为数不多的比制造更难使用的仪器之一。这是因为流量是一个动态量&#xff0c;在运动的液体中不仅存在粘性摩擦&#xff0c;还存在不稳定涡流、二次流等复杂的流动现象。测量仪器本身受多种因素影响&#xff0c;如&#xff1a;管材、直径、形状(圆形、矩形)、边界条件、…...

    2024/4/6 7:37:26
  15. spring应用手册-AOP(注解)-(13)-@Pointcut的表达式-@target

    戴着假发的程序员出品 抖音ID&#xff1a;戴着假发的程序员 欢迎关注 Pointcut的表达式-target 限制与连接点的匹配(使用 Spring AOP 时执行方法)&#xff0c;其中执行 object 的 class 具有给定类型的 annotation。我的解释就是&#xff1a;target会匹配所有拥有target指定注…...

    2024/4/22 20:13:08
  16. [SLAM]粒子滤波中部分推导(Monte Carlo in Particle Filter(PF))

    Monte Carlo在粒子滤波中的应用基本推导Monte Carlo积分拟合表达基本推导 bel‾(x)∫p(xt∣ut,xt−1)bel(xt−1)dx\overline{bel}(x)\int p(x_{t}|u_{t},x_{t-1})bel(x_{t-1})dxbel(x)∫p(xt​∣ut​,xt−1​)bel(xt−1​)dx ∵bel(xt−1)p(xt−1∣ut−1,zt−1)\because bel(x_…...

    2024/4/21 22:52:13
  17. SDL Trados 2019 和 2021 十月更新

    SDL Trados 2019 和 2021 十月更新 十一假期之后查了一下更新&#xff0c;SDL Trados 2019 和 2021都发布了新版本 SDL Trados 2019 没有什么必要安装&#xff0c;针对个人单机版增加了支持兼容2021许可证 就这一个变动 一般使用不需要更新 下载地址: http://update.sdl.com/…...

    2024/4/29 15:06:19
  18. 070《爬虫实战:从数据到产品》小记

    读万卷书&#xff0c;行万里路。 这段时间&#xff0c;行路少了&#xff0c;读书也少了。身体和灵魂&#xff0c;始终要有一个在路上。这少了的节奏&#xff0c;就是懈怠啊&#xff01; 距离年底目标还有很大一步&#xff0c;再不抓紧&#xff0c;可真的flag要倒了。 这本书&…...

    2024/4/6 7:11:53
  19. TopOpt | 88行拓展的82行拓扑优化程序完全注释. PDE

    The Corresponding Files (Click to Save): Code: top82.mThe Related Artical (Click in): [TopOpt] 99行拓扑优化程序完全注释[TopOpt] 针对99行改进的88行拓扑优化程序完全注释> [TopOpt] 88行拓展的82行拓扑优化程序完全注释. PDE[TopOpt] 88行拓展的71行拓扑优化程序完…...

    2024/5/2 19:41:06
  20. c++引用专题之常引用

    常引用 下面开始进入const引用难点 1 使用变量初始化const引用 思考cost int &a b PK const int &a 10; &#xff1f;&#xff1f;&#xff1f;&#xff1f;问题&#xff1a;const引用&#xff0c; 在C中可以声明const引用 const Type& name var&#xff1b; co…...

    2024/4/6 7:11:51

最新文章

  1. 一文带你了解MySQL的MySQL的日期函数

    &#x1f339;作者简介&#xff1a;✌全网粉丝10W&#xff0c;前大厂员工&#xff0c;多篇互联网电商推荐系统专利&#xff0c;现有多家创业公司&#xff0c;致力于建站、运营、SEO、网赚等赛道。也是csdn特邀作者、博客专家、Java领域优质创作者&#xff0c;博客之星、掘金/华…...

    2024/5/3 14:43:15
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. Go语言中如何实现继承

    完整课程请点击以下链接 Go 语言项目开发实战_Go_实战_项目开发_孔令飞_Commit 规范_最佳实践_企业应用代码-极客时间 Go语言中没有传统意义上的类和继承的概念&#xff0c;但可以通过嵌入类型&#xff08;embedded types&#xff09;来实现类似的功能。嵌入类型允许一个结构…...

    2024/4/30 4:14:53
  4. 【ensp实验】GRE和MGRE相关实验

    要求&#xff1a; 1、R5为ISP,只能进行IP地址配置&#xff0c;其所有地址均配为公有IP地址; 2、R1和R5间使用PPP的PAP认证&#xff0c;R5为主认证方 R2与R5之间使用ppp的CHAP认证&#xff0c;R5为主认证方; R3与R5之间使用HDLC封装; 3、R1、R2、R3构建一个MGRE环境&#…...

    2024/5/1 14:52:08
  5. 416. 分割等和子集问题(动态规划)

    题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义&#xff1a;dp[i][j]表示当背包容量为j&#xff0c;用前i个物品是否正好可以将背包填满&#xff…...

    2024/5/3 11:50:27
  6. 【Java】ExcelWriter自适应宽度工具类(支持中文)

    工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...

    2024/5/2 16:04:58
  7. Spring cloud负载均衡@LoadBalanced LoadBalancerClient

    LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon&#xff0c;直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件&#xff0c;我们讨论Spring负载均衡以Spring Cloud2020之后版本为主&#xff0c;学习Spring Cloud LoadBalance&#xff0c;暂不讨论Ribbon…...

    2024/5/2 23:55:17
  8. TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案

    一、背景需求分析 在工业产业园、化工园或生产制造园区中&#xff0c;周界防范意义重大&#xff0c;对园区的安全起到重要的作用。常规的安防方式是采用人员巡查&#xff0c;人力投入成本大而且效率低。周界一旦被破坏或入侵&#xff0c;会影响园区人员和资产安全&#xff0c;…...

    2024/5/2 9:47:31
  9. VB.net WebBrowser网页元素抓取分析方法

    在用WebBrowser编程实现网页操作自动化时&#xff0c;常要分析网页Html&#xff0c;例如网页在加载数据时&#xff0c;常会显示“系统处理中&#xff0c;请稍候..”&#xff0c;我们需要在数据加载完成后才能继续下一步操作&#xff0c;如何抓取这个信息的网页html元素变化&…...

    2024/5/3 11:10:49
  10. 【Objective-C】Objective-C汇总

    方法定义 参考&#xff1a;https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...

    2024/5/2 6:03:07
  11. 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】

    &#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】&#x1f30f;题目描述&#x1f30f;输入格…...

    2024/5/2 9:47:30
  12. 【ES6.0】- 扩展运算符(...)

    【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数&#xff0…...

    2024/5/2 23:47:43
  13. 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?

    文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕&#xff0c;各大品牌纷纷晒出优异的成绩单&#xff0c;摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称&#xff0c;在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁&#xff0c;多个平台数据都表现出极度异常…...

    2024/5/3 13:26:06
  14. Go语言常用命令详解(二)

    文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令&#xff0c;这些命令可以帮助您在Go开发中进行编译、测试、运行和…...

    2024/5/3 1:55:15
  15. 用欧拉路径判断图同构推出reverse合法性:1116T4

    http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b&#xff0c;我们在 a i a_i ai​ 和 a i 1 a_{i1} ai1​ 之间连边&#xff0c; b b b 同理&#xff0c;则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然&#xff0…...

    2024/5/2 9:47:28
  16. 【NGINX--1】基础知识

    1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息&#xff0c;并安装一些有助于配置官方 NGINX 软件包仓库的软件包&#xff1a; apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...

    2024/5/2 9:47:27
  17. Hive默认分割符、存储格式与数据压缩

    目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限&#xff08;ROW FORMAT&#xff09;配置标准HQL为&#xff1a; ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...

    2024/5/3 1:55:09
  18. 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法

    文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中&#xff0c;传感器和控制器产生大量周…...

    2024/5/2 8:37:00
  19. --max-old-space-size=8192报错

    vue项目运行时&#xff0c;如果经常运行慢&#xff0c;崩溃停止服务&#xff0c;报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中&#xff0c;通过JavaScript使用内存时只能使用部分内存&#xff08;64位系统&…...

    2024/5/2 9:47:26
  20. 基于深度学习的恶意软件检测

    恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞&#xff0c;例如可以被劫持的合法软件&#xff08;例如浏览器或 Web 应用程序插件&#xff09;中的错误。 恶意软件渗透可能会造成灾难性的后果&#xff0c;包括数据被盗、勒索或网…...

    2024/5/2 9:47:25
  21. JS原型对象prototype

    让我简单的为大家介绍一下原型对象prototype吧&#xff01; 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定&#xff0c;每一个构造函数都有一个 prototype 属性&#xff0c;指向另一个对象&#xff0c;所以我们也称为原型对象…...

    2024/5/2 23:47:16
  22. C++中只能有一个实例的单例类

    C中只能有一个实例的单例类 前面讨论的 President 类很不错&#xff0c;但存在一个缺陷&#xff1a;无法禁止通过实例化多个对象来创建多名总统&#xff1a; President One, Two, Three; 由于复制构造函数是私有的&#xff0c;其中每个对象都是不可复制的&#xff0c;但您的目…...

    2024/5/2 18:46:52
  23. python django 小程序图书借阅源码

    开发工具&#xff1a; PyCharm&#xff0c;mysql5.7&#xff0c;微信开发者工具 技术说明&#xff1a; python django html 小程序 功能介绍&#xff1a; 用户端&#xff1a; 登录注册&#xff08;含授权登录&#xff09; 首页显示搜索图书&#xff0c;轮播图&#xff0…...

    2024/5/3 7:43:42
  24. 电子学会C/C++编程等级考试2022年03月(一级)真题解析

    C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...

    2024/5/3 1:54:59
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57