ansible常用來對集群進行維護和管理,它只需要在管理端安裝,被管理端主要提供sshd服務即可。本節講述ansible的安裝和使用。
# 新增epel-release第三方套件**。
yum install -y epel-release
# 安裝 ansible
yum install -y ansible
# 配置免密登陸,執行以下語句
ssh-keygen #一路回車
ssh-copy-id 192.168.100.101 # 回車之後,需要輸入192.168.100.101的密碼
ssh-copy-id 192.168.100.102 # 回車之後,需要輸入192.168.100.102的密碼
# 在管理端伺服器安裝python
yum install -y openssh-server python
# 連線到被管理端伺服器
ssh 192.168.100.102
# 在被管理端伺服器安裝python
yum install -y openssh-server python
# 退出102,繼續回到101
exit
[defaults]
inventory = /etc/ansible/hosts
forks = 5
become = root
remote_port = 22
host_key_checking = false
timeout = 10
log_path = /var/log/ansible.log
private_key_file = /root/.ssh/id_rsa
[servers]
192.168.100.101
192.168.100.102
ansible servers -m ping
# 在管理端建立可執行檔案
echo "hello world">test.sh
# 推送test.sh到被管理端
ansible servers -m copy -a "src=/root/test.sh dest=/root/ owner=root group=root mode=0755"
# 執行被管理端的test.sh
ansible servers -m shell -a "/root/test.sh"
# 安裝httpd
# 啟動httpd
# 檢視服務狀態
state: started
ansible-playbook nginx.yml
以上就是使用ansible維護linux集群的過程。 ansible架構原理及工作流程 linux技術
一 ansible介紹 ansible是一種自動化運維工具,基於paramiko模組開發,用於批量執行任務和發布工作,被廣泛用於日常運維工作當中.二 ansible架構架構圖 ansible核心模組介紹 core models ansible自帶的模組,file,shell,copy等custom ...
為何使用Ansible
b size large it 自動化 size b 現在市面上用一些實現it自動化的工具,例如 puppet,chef,salt。ansible 是乙個相對比較新的工具,但目前社群十分活躍。我用過puppet和ansible。這裡想討論一下我偏愛ansible的原因。b size large 架構...
ansible使用文件
假設a機器上安裝ansible yum install ansible vim etc ansible hosts 對每個主機加key認證 ssh copy id i ssh id rsa.pub root b ip ansible all m ping 乙個playbook檔案可以引入其他的yml...