新聞中心
Ansible簡(jiǎn)介
Ansible是一個(gè)開(kāi)源的IT自動(dòng)化工具,用于配置管理、應(yīng)用部署、任務(wù)執(zhí)行和多節(jié)點(diǎn)協(xié)調(diào),通過(guò)SSH協(xié)議,可以在遠(yuǎn)程服務(wù)器上以安全的方式執(zhí)行命令,實(shí)現(xiàn)對(duì)系統(tǒng)資源的管理,Ansible使用YAML語(yǔ)言編寫的Playbook來(lái)描述任務(wù)流程,可以輕松地將任務(wù)模塊化、可重復(fù)使用和可擴(kuò)展。

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到湛江網(wǎng)站設(shè)計(jì)與湛江網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋湛江地區(qū)。
Ansible安裝與配置
1、安裝Ansible
在Linux系統(tǒng)中,可以通過(guò)以下命令安裝Ansible:
sudo apt-get update sudo apt-get install software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible sudo apt-get install ansible
2、配置Ansible
在安裝完成后,需要對(duì)Ansible進(jìn)行基本配置,編輯/etc/ansible/ansible.cfg文件,設(shè)置以下參數(shù):
[defaults] inventory = /etc/ansible/hosts remote_user = root private_key_file = ~/.ssh/id_rsa
3、創(chuàng)建主機(jī)清單文件
在/etc/ansible/hosts文件中,添加主機(jī)信息。
[group1] host1 ansible_host=192.168.1.1 ansible_user=root ansible_connection=local host2 ansible_host=192.168.1.2 ansible_user=root ansible_connection=local [group2] host3 ansible_host=192.168.1.3 ansible_user=root ansible_connection=local host4 ansible_host=192.168.1.4 ansible_user=root ansible_connection=local
使用Ansible編寫Playbook
1、創(chuàng)建Playbook文件
使用文本編輯器創(chuàng)建一個(gè)名為example.yml的Playbook文件,編寫以下內(nèi)容:
name: Install Nginx
hosts: all
tasks:
name: Update package list
apt:
name: "{{ item }}" state=present update_cache=yes
with_items:
nginx
php-fpm php-mysqlnd php-gd php-xml php-mbstring php-curl php-bcmath php-ldap php-json php-tokenizer php-mcrypt php-apcu php-intl php-soap curl php-dev libxml2 zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev wget git libc6 libncurses5-dev unzip automake libtool bison subversion python3 python3-pip python3-dev python3-venv zip g++ make cmake libboost-all-dev libbz2-dev libffi-dev libpq-dev nodejs npm supervisor virtualenv python3-venv python3-setuptools pip xz-utils tar git mercurial orwpan emacs emacs24 m4 libgtk2.0-dev libwebkitgtk-dev libnotify-dev libnss3-dev libxslt1.1 libxml2-dev libxsltproc-dev libgconf2-dev libgdk-pixbuf2.0-dev libpangocairo-1.0-0 libatk1.0-0 libatkmm1.6-1 libgtk2.0-0 libpcre3-dev libjpeg62 libcap2-bin zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc zlib1g zlibc --with-openssl --with-python --with-python3 --with-systemd --with-systemdsystemunitdir=/usr/share/systemd/system --with-selinux --with-selinuxtypes --with-cacertdir=/etc/ssl/certs --with-cacert=/etc/ssl/certs/cacert.pem --with-validationchecksum true
git clone https://github.com/ansible/ansible.git $HOME/ansible
cd $HOME/ansible && git checkout release/2.9
cd $HOME/ansible && git pull origin master
cd $HOME/ansible && make && make install
mkdir ~/.ansible
cp ~/.vimrc ~/.emacs ~/.inputrc ~/.profile ~/.bashrc ~/.bash_profile ~/.bash_login ~/.config/fish/config.fish ~/.config/polybar/launch.sh ~
chown root:root *
chmod go+rwx *
"
become: yes become_method: sudo
become_user: root
when: "'group1|group2' in groupnames"
become_ask_pass: yes
become_pass: "{{ lookup('passwordfile', 'admin') | b64decode('utf-8') }}
"
notify:
Reload Nginx
Run Service
SSH Reconnect
tasks:
-
ping:
host: localhost
register: result
ignore_errors: yes
Debug:
var: result.stdout_lines
name: Install Nginx
nginx:
enabled: yes
state: present
update_cache: yes
enablerepo: extras
docroot: /var/www/html
errorlog: /var/log/nginx/error.log
accesslog: /var/log/nginx/access.log
http_proxy: http://{{ inventory_hostname }}
https_proxy: https://{{ inventory_hostname }}
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
keepalive_timeout 65;
listen [::]:80 default_server;
listen [::]:443 default_server {
return ("HTTPS required")
}
notify:
Reload Nginx
runservice:
name: service apache2 restart
pip install requests==2.25.1
pip freeze > requirements.txt
cd ~ && git clone https://github.com/jakevdp/
gitbucket gitbucket
cd gitbucket && git remote add upstream https://github.com/jakevdp/
gitbucket && git fetch upstream && git rebase upstream/master --autostash --keep-index && git push origin master --force --quiet --set-upstream origin master && cd ~ && pip install dist/*whl >> requirements.txt
cd $HOME && git add requirements.txt && git commit -
adcommit message="Upgrade dependencies" && git push origin master --force --quiet --set-upstream origin master && cd ~ && pip install virtualenvwrapper >> requirements.txt && echo export WORKON_HOME=$HOME >> ~.bashrc && echo export VIRTUALENVWRAPPER_PYTHON=python3 >> ~.bashrc && source ~.bashrc && workon venv && cd venv && source bin/activate && pip install wheel >> requirements.txt && pip wheel * >> requirements.txt && deactivate
noopierun pip install --requirement
文章名稱:linux如何使用Ansible讓系統(tǒng)管理自動(dòng)化
網(wǎng)站地址:http://m.5511xx.com/article/dpseejc.html


咨詢
建站咨詢
