自动化 运维
puppet 老牌
saltstack 效率高 适用大基数平台
ansible 轻量 功能全
puppet 安装配置
服务端 172.7.15.106 web9.aming.com
客户端 172.7.15.111 web10.aming.com
两台机器关闭selinux 清空iptables规则 设置hostname
getenforce Permissive 关闭
vim /etc/selinux/config selinux=disabled 永久生效
iptables -F 清空iptables规则
service iptables save
编辑hosts文件,106和111全部为 vim /etc/hosts 添加
172.7.15.106 web9.aming.com
172.7.15.111 web10.aming.com
利用DNS服务器批量添加hosts
ping web9.aming.com
ping web10.aming.com
都安装ntpdate,并建立自动同步时间的任务计划
yum install -y ntp
cront -e
*/10 * * * * ntpdate time.windows.com >/dev/null 2>&1
puppet 老牌
saltstack 效率高 适用大基数平台
ansible 轻量 功能全
puppet 安装配置
服务端 172.7.15.106 web9.aming.com
客户端 172.7.15.111 web10.aming.com
两台机器关闭selinux 清空iptables规则 设置hostname
getenforce Permissive 关闭
vim /etc/selinux/config selinux=disabled 永久生效
iptables -F 清空iptables规则
service iptables save
编辑hosts文件,106和111全部为 vim /etc/hosts 添加
172.7.15.106 web9.aming.com
172.7.15.111 web10.aming.com
利用DNS服务器批量添加hosts
ping web9.aming.com
ping web10.aming.com
都安装ntpdate,并建立自动同步时间的任务计划
yum install -y ntp
cront -e
*/10 * * * * ntpdate time.windows.com >/dev/null 2>&1
0
本帖最后由 wyxqqhaha 于 2016-3-14 17:52 编辑
client host 都要装
安装RPM包
rpm -ivh "http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm"
查看是否生成yum源 ls /etc/yum.repos.d/
yum list
安装服务端程序
yum install -y puppet-server host
yum install -y puppet client
host加入服务列表
chkconfig puppetmaster on
service puppetmaster start
ps aux |grep puppet
查看ruby启动端口 8140
client修改配置文件
vim /etc/puppet/puppet.conf [agent]最后添加
listen = true
server = web9.aming.com
ruminterval = 30 //主动更新间隔
service puppet start
//etc/init.d/puppet restart 这是重启~
chkconfig puppet on
可能会查询不到端口 客户端在连接时启动。
puppet配置认证
host client 相互认证才能沟通
puppet cert list --all //列出所有的客户端 签名&未签名
puppet cert sign web10 签名注册
puppet cert sign web9.aming.com
列表时前面带+号则认证成功
puppet cert clean web10 host删除签名
puppet cert --clean all 清空证书
rm -rf /var/lib/puppet/ssl/* 客户端清除旧证书重启
/etc/init.d/puppet restart
puppet 配置自动签发证书
puppet cert --clean all host清空证书
rm -rf /var/lib/puppet/ssl/* client清除ssl相关文件
在host端创建自动签发配置文件
vim /etc/puppet/autosign.conf
*.aming.com 加入一个域vim /etc/puppet/puppet.conf
[main] 后加入一行
autosign = ture //支持自动签名
//etc/init.d/puppetmaster restart host重启
//etc/init.d/puppet restart
在client上
vim /etc/puppet/puppet.conf
[agent] 后加入一行
server = web9.aming.com
runinterval = 106
rm -rf /var/lib/puppet/ssl/*
/etc/init.d/puppe restart client重启
重启后即可得到签名
如果client不启动puppet服务,可通过命令签发
puppet agent --test --server web9.aming.com
测试证书
host 端编辑配置文件
vim /etc/puppet/manifests/site.pp
node default{
file{"/tmp/123.txt":
content =>"test,test";
}}
如果不配置 客户端不会同步任何数据
host重启服务
这个123.txt 文件则会同步到client
client host 都要装
安装RPM包
rpm -ivh "http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm"
查看是否生成yum源 ls /etc/yum.repos.d/
yum list
安装服务端程序
yum install -y puppet-server host
yum install -y puppet client
host加入服务列表
chkconfig puppetmaster on
service puppetmaster start
ps aux |grep puppet
查看ruby启动端口 8140
client修改配置文件
vim /etc/puppet/puppet.conf [agent]最后添加
listen = true
server = web9.aming.com
ruminterval = 30 //主动更新间隔
service puppet start
//etc/init.d/puppet restart 这是重启~
chkconfig puppet on
可能会查询不到端口 客户端在连接时启动。
puppet配置认证
host client 相互认证才能沟通
puppet cert list --all //列出所有的客户端 签名&未签名
puppet cert sign web10 签名注册
puppet cert sign web9.aming.com
列表时前面带+号则认证成功
puppet cert clean web10 host删除签名
puppet cert --clean all 清空证书
rm -rf /var/lib/puppet/ssl/* 客户端清除旧证书重启
/etc/init.d/puppet restart
puppet 配置自动签发证书
puppet cert --clean all host清空证书
rm -rf /var/lib/puppet/ssl/* client清除ssl相关文件
在host端创建自动签发配置文件
vim /etc/puppet/autosign.conf
*.aming.com 加入一个域vim /etc/puppet/puppet.conf
[main] 后加入一行
autosign = ture //支持自动签名
//etc/init.d/puppetmaster restart host重启
//etc/init.d/puppet restart
在client上
vim /etc/puppet/puppet.conf
[agent] 后加入一行
server = web9.aming.com
runinterval = 106
rm -rf /var/lib/puppet/ssl/*
/etc/init.d/puppe restart client重启
重启后即可得到签名
如果client不启动puppet服务,可通过命令签发
puppet agent --test --server web9.aming.com
测试证书
host 端编辑配置文件
vim /etc/puppet/manifests/site.pp
node default{
file{"/tmp/123.txt":
content =>"test,test";
}}
如果不配置 客户端不会同步任何数据
host重启服务
这个123.txt 文件则会同步到client
0
定义模块管理
模块是puppet的配置单元,模块里会包含类和资源。
同步文件,远程命令,cron等叫做资源,通过模块来实现
创建模块名test1
mkdir /etc/puppet/modules/test1
创建模块对应子目录
mkdir /etc/puppet/modules/test1/{files,manifests,templates}f
file里面存储文件,可留空
manifests里放置模块配置文件
templates放置模块文件,可留空
vim file/1.txt
vim manifests/init.pp 重要 可被识别
class test1{
file{"/tmp/2.txt":
owner => "root",
group => "root",
mode =>0400,
source => "puppet://$puppetserver/modules/test1/1.txt"
}}
owner,group,mode定义文件属主,属组,权限
source定义文件从那里获取
$puppetserver 也需要定义,可由site.pp配置,这里指host端/etc/puppet/modules/test1/files/1.txt
vim /etc/puppet/manifests/site.pp
$puppetserver = 'web9.aming.com'
node 'web10'{
include test1
}
$puppetserver 定义服务端主机名,node后为客户端主机名,这里定义客户端要加载的模块
配置完成后,在客户端执行
puppet agent --test --server = web9.aming.com
如果客户端启动了puppet服务,则不用执行,将会自动同步
1.txt 会同步到客户端 /tmp/2.txt
模块是puppet的配置单元,模块里会包含类和资源。
同步文件,远程命令,cron等叫做资源,通过模块来实现
创建模块名test1
mkdir /etc/puppet/modules/test1
创建模块对应子目录
mkdir /etc/puppet/modules/test1/{files,manifests,templates}f
file里面存储文件,可留空
manifests里放置模块配置文件
templates放置模块文件,可留空
vim file/1.txt
vim manifests/init.pp 重要 可被识别
class test1{
file{"/tmp/2.txt":
owner => "root",
group => "root",
mode =>0400,
source => "puppet://$puppetserver/modules/test1/1.txt"
}}
owner,group,mode定义文件属主,属组,权限
source定义文件从那里获取
$puppetserver 也需要定义,可由site.pp配置,这里指host端/etc/puppet/modules/test1/files/1.txt
vim /etc/puppet/manifests/site.pp
$puppetserver = 'web9.aming.com'
node 'web10'{
include test1
}
$puppetserver 定义服务端主机名,node后为客户端主机名,这里定义客户端要加载的模块
配置完成后,在客户端执行
puppet agent --test --server = web9.aming.com
如果客户端启动了puppet服务,则不用执行,将会自动同步
1.txt 会同步到客户端 /tmp/2.txt
0
同步文件或目录资源
生产环境中同步目录是非常常见的,可以做一个包发布系统,通过这个模块把如apache 目录整个分发到其他机器上。
vim /etc/puppet/modules/test1/manifests/init.pp
模块配置文件添加如下:
class apache{
file {"/usr/local/apache2"; //客户端文件路径
owner =>"root",
group =>"root",
source =>"puppet://$puppetserver/modules/test1/apache2",
recurse =>true, //针对目录 目录用
purge =>true //支持删除操作
}}
recurse =>true 表示递归 没有这个不能同步目录
purge 可以保证当服务端删除某个文件,客户端可以跟着删除。
cd test1/files
mkdir apache2
cd apache2
mkdir {conf,bin,logs}
touch logs/1.log
touch bin/apachectl
touch conf/httpd.conf 简单模拟apache环境
vim manifests/site.pp
$puppetserver='web9.aming.com'
node 'web10' {
include test1
include apache 添加
}
tail /var/log/messages 查看日志可以看到apache目录是否同步
ls -l /usr/local/apache2/
puppet 远程执行命令
vim /modules/test1/manifests/init.pp
class apache{
file {"/usr/local/apache2";
owner =>"root",
group =>"root",
source =>"puppet://$puppetserver/modules/test1/apache2",
recurse =>true, //针对目录 目录用
purge =>true //支持删除操作
}
exec {"123": /123: 执行命令的名字
unless =>"test -f /tmp/aminglinux.txt", //条件 IF不成立则。。。 onlyif 存在时则执行
path => ["/bin","/sbin","/usr/bin","/usr/sbin"], //环境变量
command => "touch /tmp/aminglinux.txt"
}
}
查看tail /var/log/messages EXEC[123]/returns) executed successfully 成功~
puppet 远程任务计划
vim /modules/test1/manifests/init.pp
class apache{
file {"/usr/local/apache2";
owner =>"root",
group =>"root",
source =>"puppet://$puppetserver/modules/test1/apache2",
recurse =>true, //针对目录 目录用
purge =>true //支持删除操作
}
exec {"123": /123: 执行命令的名字
unless =>"test -f /tmp/aminglinux.txt", //条件 IF不成立则。。。 onlyif 存在时则执行
path => ["/bin","/sbin","/usr/bin","/usr/sbin"], //环境变量
command => "touch /tmp/aminglinux.txt"
}
cron {"aming1": /命令名 puppet name
command => "/sbin/ntpdate time.windows.com",
user => "root",
minute =>"*/10", /分时日月周 minute,hour,monthday,month,weekday
monthday =>"10-15",
#ensure =>"absent" 未加入 修改删除后同步恢复,加入后 任务可删除
}
}
crontab -l 查看客户端是否自动生成自动任务
生产环境中同步目录是非常常见的,可以做一个包发布系统,通过这个模块把如apache 目录整个分发到其他机器上。
vim /etc/puppet/modules/test1/manifests/init.pp
模块配置文件添加如下:
class apache{
file {"/usr/local/apache2"; //客户端文件路径
owner =>"root",
group =>"root",
source =>"puppet://$puppetserver/modules/test1/apache2",
recurse =>true, //针对目录 目录用
purge =>true //支持删除操作
}}
recurse =>true 表示递归 没有这个不能同步目录
purge 可以保证当服务端删除某个文件,客户端可以跟着删除。
cd test1/files
mkdir apache2
cd apache2
mkdir {conf,bin,logs}
touch logs/1.log
touch bin/apachectl
touch conf/httpd.conf 简单模拟apache环境
vim manifests/site.pp
$puppetserver='web9.aming.com'
node 'web10' {
include test1
include apache 添加
}
tail /var/log/messages 查看日志可以看到apache目录是否同步
ls -l /usr/local/apache2/
puppet 远程执行命令
vim /modules/test1/manifests/init.pp
class apache{
file {"/usr/local/apache2";
owner =>"root",
group =>"root",
source =>"puppet://$puppetserver/modules/test1/apache2",
recurse =>true, //针对目录 目录用
purge =>true //支持删除操作
}
exec {"123": /123: 执行命令的名字
unless =>"test -f /tmp/aminglinux.txt", //条件 IF不成立则。。。 onlyif 存在时则执行
path => ["/bin","/sbin","/usr/bin","/usr/sbin"], //环境变量
command => "touch /tmp/aminglinux.txt"
}
}
查看tail /var/log/messages EXEC[123]/returns) executed successfully 成功~
puppet 远程任务计划
vim /modules/test1/manifests/init.pp
class apache{
file {"/usr/local/apache2";
owner =>"root",
group =>"root",
source =>"puppet://$puppetserver/modules/test1/apache2",
recurse =>true, //针对目录 目录用
purge =>true //支持删除操作
}
exec {"123": /123: 执行命令的名字
unless =>"test -f /tmp/aminglinux.txt", //条件 IF不成立则。。。 onlyif 存在时则执行
path => ["/bin","/sbin","/usr/bin","/usr/sbin"], //环境变量
command => "touch /tmp/aminglinux.txt"
}
cron {"aming1": /命令名 puppet name
command => "/sbin/ntpdate time.windows.com",
user => "root",
minute =>"*/10", /分时日月周 minute,hour,monthday,month,weekday
monthday =>"10-15",
#ensure =>"absent" 未加入 修改删除后同步恢复,加入后 任务可删除
}
}
crontab -l 查看客户端是否自动生成自动任务
0
saltstack
由python开发
host 172.7.15.106
client 172.7.15.111
设置hostname hosts
172.7.15.106 web9.aming.com
172.7.15.111 web10.aming.com
关闭selinux
安装saltstack
host操作
yum install -y epel-release
yum install -y salt-master salt-minion
client操作
yum install -y epel-release
yum install -y salt-minion
安装完成
host端 指定服务端IP
vim /etc/salt/minion //大概16行修改或增加
#master:salt 修改或添加
master:172.7.15.106
/etc/init.d/salt-master start
/etc/init.d/salt-minion start
ps aux |grep salt
启动完成
client端
vim /etc/salt/minion
/etc/init.d/salt-master start
master:172.7.15.106
服务启动
host端
salt-key -a web10.aming.com
将 web10.aming.com 加入 accept keys 中 -a签名主机 -d删除主机
salt-key -a web9.aming.com
salt '*' test.ping 验证签名的主机
salt '*' cmd.run 'df -h' 远程执行命令
salt 'web9.aming.com' cmd.rum '-w'
由python开发
host 172.7.15.106
client 172.7.15.111
设置hostname hosts
172.7.15.106 web9.aming.com
172.7.15.111 web10.aming.com
关闭selinux
安装saltstack
host操作
yum install -y epel-release
yum install -y salt-master salt-minion
client操作
yum install -y epel-release
yum install -y salt-minion
安装完成
host端 指定服务端IP
vim /etc/salt/minion //大概16行修改或增加
#master:salt 修改或添加
master:172.7.15.106
/etc/init.d/salt-master start
/etc/init.d/salt-minion start
ps aux |grep salt
启动完成
client端
vim /etc/salt/minion
/etc/init.d/salt-master start
master:172.7.15.106
服务启动
host端
salt-key -a web10.aming.com
将 web10.aming.com 加入 accept keys 中 -a签名主机 -d删除主机
salt-key -a web9.aming.com
salt '*' test.ping 验证签名的主机
salt '*' cmd.run 'df -h' 远程执行命令
salt 'web9.aming.com' cmd.rum '-w'
编辑回复