home目录下会生成一对秘钥:id_rsa为私钥,id_rsa.pub为公钥
6.传输公钥(传输给受控主机之后,可免密登录受控主机) ssh-copy-id -i ~/.ssh/id_rsa.pub mtnsadmin@172.22.9.4
OS规划(ansible批量)
1.ansible目录下创建脚本文件pres_root
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