1、ansible安装及常用模块使用
yum install -y ansible
确认版本
ansible --version
另外一台机器也是这么安装ansible
cd /etc/ansible
cp ansible.cfg ansible.cfg.bak
vi ansible.cfg
修改
log_path = /var/log/ansible.log 方便记录log
host_key_checking = False
然后加资源清单
vi /etc/ansible/hosts
增加行
然后测试一下 ansible all -uroot -k -m ping
常用模块 command 模块 , shell 模块, script模块,copy模块,fetch模块,file模块,unarchive模块,archive模块,hostname模块,cron模块,yum和apt模块,service模块,user模块,group模块,lineinfile 模块,replace模块,setup模块
2、使用ansible-playbook安装apache,并实现修改配置文件重启服务。
vi install_httpd.yml
---
#install httpd
- hosts: mysql
remote_user: root
gather_facts: no
tasks:
- name: install httpd
yum: name=httpd state=present
- name: modify config
lineinfile: path=/etc/httpd/conf/httpd.conf regexp='^Listen' line='Listen 8080'
- name: mkdir website dir
file: path=/data/html state=directory
- name: start service
service: name=httpd state=restarted enabled=yes
ansible-playbook -uroot -k install_httpd.yml
3、redis编译安装多实例。
先装依赖包 yum -y install gcc jemalloc-devel
mkdir /apps/redis
上传redis压缩包
tar xvf redis-6.2.1.tar.gz
cd redis-6.2.1/
make PREFIX=/apps/redis install
ln -s /apps/redis/bin/* /usr/bin/
mkdir /apps/redis/{etc,log,data,run}
useradd -r -s /sbin/nologin redis
chown -R redis.redis /apps/redis/
cp /redis/redis-6.2.1/redis.conf /apps/redis/etc/
vi /apps/redis/etc/redis.conf
daemonize yes
mv /apps/redis/etc/redis.conf /apps/redis/etc/redis_6379.conf
/apps/redis/bin/redis-server /apps/redis/etc/redis_6379.conf
然后分别创建redis_6380.conf 和redis_6381.conf 并且配置文件修改port 分别为6380 和6381
/apps/redis/bin/redis-server /apps/redis/etc/redis_6380.conf
/apps/redis/bin/redis-server /apps/redis/etc/redis_6381.conf
ps aux | grep redis
ss -tunlp | grep 6379
ss -tunlp | grep 6380
ss -tunlp | grep 6381