Ansible安装及OS规划

Ansible安装  1.以管理用户mtnsadmin连接服务器后下载安装包(-O表示将下载的文件存放到指定的文件夹下,同时重命名下载的文件)     sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo     Ansible安装及OS规划 2.cd到用户根目录安装    cd ~    sudo yum install -y ansible    Ansible安装及OS规划 3.安装完成后可查看版本信息    ansible --version    Ansible安装及OS规划 4.创建ansible用户,修改密码和文件夹权限    sudo useradd -d /home/ansible ansible    sudo passwd ansible    sudo chown -R ansible:ansible /etc/ansible/    Ansible安装及OS规划 5.配置ssh免密登录(切到ansible用户,生成秘钥对)    su ansible    ssh-keygen -t rsa    Ansible安装及OS规划

   home目录下会生成一对秘钥:id_rsa为私钥,id_rsa.pub为公钥

 Ansible安装及OS规划

6.传输公钥(传输给受控主机之后,可免密登录受控主机)    ssh-copy-id -i ~/.ssh/id_rsa.pub mtnsadmin@172.22.9.4    Ansible安装及OS规划

OS规划(ansible批量)

1.ansible目录下创建脚本文件pres_root

   Ansible安装及OS规划

2.指定服务器创建安装目录(all代表脚本文件中配置的所有主机,-f分线程执行)

ansible all -i pres_root -a "sudo mkdir -p /u01/pres/app" -f 21 ansible web -i pres_root -a "sudo mkdir -p /u01/pres/app/hap" -f 4 ansible web,hybris -i pres_root -a "sudo mkdir -p /u01/pres/app/hybris6200" -f 11 ansible sourcing -i pres_root -a "sudo mkdir -p /u01/pres/app/sourcing" -f 3 ansible sourcing -i pres_root -a "sudo mkdir -p /u01/pres/app/inventory" -f 3 创建用户 ansible web,hybris -i pres_root -a "sudo useradd -u 1100 preshybris" -f 11 ansible web -i pres_root -a "sudo useradd -u 1110 preshap" -f 4 ansible kafka -i pres_root -a "sudo useradd -u 1120 preskafka" -f 3 ansible redis -i pres_root -a "sudo useradd -u 1130 presredis" -f 3 ansible sourcing -i pres_root -a "sudo useradd -u 1140 pressourcing" -f 3 ansible sourcing -i pres_root -a "sudo useradd -u 1150 presinv" -f 3 检查用户 ansible sourcing -i pres_root -a "sudo tail -10 /etc/passwd" -f 3 修改目录权限 ansible kafka -i pres_root -a "sudo chown -R preskafka:preskafka /u01/pres/app" -f 3 ansible redis -i pres_root -a "sudo chown -R presredis:presredis /u01/pres/app" -f 3 ansible web,hybris -i pres_root -a "sudo chown -R preshybris:preshybris /u01" -f 11 ansible web -i pres_root -a "sudo chown -R preshybris:preshybris /u01/pres/app/hybris6200" -f 4 ansible web -i pres_root -a "sudo chown -R preshap:preshap /u01/pres/app/hap" -f 4 ansible sourcing -i pres_root -a "sudo chown -R pressourcing:pressourcing /u01/pres/app/sourcing" -f 3 ansible sourcing -i pres_root -a "sudo chown -R presinv:presinv /u01/pres/app/inventory" -f 3 3.创建挂载用户 sudo useradd -u 1160 presimage sudo passwd presimage sudo mkdir -p /u01/pres/app //sudo chown -R presimage:presimage /u01 sudo useradd -u 1100 preshybris sudo passwd preshybris sudo useradd -u 1110 preshap sudo passwd preshap sudo useradd -u 1140 pressourcing sudo passwd pressourcing 4.连接ftp服务器创建用户 sudo useradd -u 1180 preswmsftp sudo passwd preswmsftp sudo useradd -u 1190 presamiftp sudo passwd presamiftp Ansible安装及OS规划
上一篇:权限管理--用户介绍;用户与组相关文件;用户管理命令之用户创建、查看、删除、修改


下一篇:Linux 创建用户、组