使用Ad-hoc部署nfs

使用Ad-hoc部署nfs

1.安装nfs
yum -y install nfs-utils
2.配置nfs
vim /etc/exports
/code/blog 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
3.根据配置文件创建必要数据
mkdir -p /code/blog
创建www组和用户
授权/code/blog
4.启动nfs

ansible部署NFS
1.密钥下发
[root@ansible ~]# ssh-copy-id -i .ssh/id_rsa.pub 10.0.0.31
2.写入主机清单
[root@ansible ~]# cat /etc/ansible/hosts
[nfs]
10.0.0.31

[webs]
web01 ansible_ssh_host=10.0.0.7
web02 ansible_ssh_host=10.0.0.8

[backups]
backup ansible_ssh_host=10.0.0.41
[root@ansible ~]#

3.安装NFS
[root@ansible ~]# ansible nfs -m yum -a 'name=nfs-utils state=present'

4.拷贝配置文件到/etc/exports
[root@ansible ~]# ansible nfs -m copy -a 'src=exports dest=/etc/exports'

5.根据配置创建数据
创建组:
[root@ansible ~]# ansible nfs -m group -a 'name=www gid=666'
创建用户:
[root@ansible ~]# ansible nfs -m user -a 'name=www group=www uid=666 shell=/sbin/nologin create_home=false'

创建目录:
[root@ansible ~]# ansible nfs -m file -a 'path=/code/blog/ state=directory owner=www group=www'

6.启动NFS
[root@ansible ~]# ansible nfs -m systemd -a 'name=nfs state=started enabled=yes'

 

5.客户端挂载nfs
模块:
mount:
src: 挂载的源(172.16.1.31:/code/blog)
path: 挂载到本地的目录
state:
present # 只写入到/etc/fstab 不能直接挂载
unumounted # 只卸载不删除/etc/fstab中的配置

absent # 卸载并且删除/etc/fstab配置
mounted # 挂载并且写入到/etc/fstab

[root@ansible ~]# ansible web01 -m mount -a 'src=172.16.1.31:/code/blog path=/mnt fstype=nfs state=absent'

模块:commnd
[root@ansible ~]# ansible web01 -m command -a 'ifconfig eth0'

[root@ansible ~]# ansible web01 -m command -a 'nginx -t'
web01 | CHANGED | rc=0 >>
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@ansible ~]# ansible web01 -m shell -a 'ps axu|grep nginx'

scripts:
ansible web01 -m script -a '/root/1.sh' # 1.sh在ansible主机上

 

yum_repository: 配置YUM仓库模块
[root@ansible ~]# ansible nfs -m yum_repository -a 'name=nginx description="Nginx YUM repo" baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ enabled=yes gpgcheck=no gpgkey=https://nginx.org/keys/nginx_signing.key'

get_url: 下载软件
get_url:
url: 链接
dest: 下载到本地的位置
[root@ansible ~]# ansible web01 -m get_url -a 'url=https://img10.360buyimg.com/n1/g12/M00/08/03/rBEQYVGZ8F0IAAAAAAIapXb0bREAABlfAPtsn0AAhq9958.jpg dest=/root/'

firewalld 停止防火墙
[root@ansible ~]# ansible web01 -m systemd -a 'name=firewalld state=stopped enabled=no'

selinux 关闭selinux
[root@ansible ~]# ansible web01 -m selinux -a 'policy=targeted state=disabled'

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章