yum能够解决依赖关系
rpm 全称readhat package manager(红帽包管理工具),须要本身解决依赖
查看yum源配置python
cat /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch #名字
baseurl=http://mirrors.aliyun.com/epel/7/$basearch #rpm源的地址,后面能够写http,https,ftp,Samba,file:
failovermethod=priority
enabled=1 # 是否开启,1表明开启,0表示关闭
gpgcheck=0 #是否校验签名,1表明校验,0表示校验(校验安全性)
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
yum install -y nginx
注:一个包组中有一类功能对于各个软件的处理linux
yum grouplist #查看包组信息
yum groupinstall 包组名 #安装包组
disablerepo #禁用源
enablerepo #启用源
name #包名
static #状态,包括安装和卸载
ansible web -m yum -a 'name=wget'
ansible web -m copy -a 'src=/etc/yum.repos.d/epel.repo dest=/etc/yum.repos.d/epel.repo'
ansible web -m yum -a 'name=python2-pip' #下载安装pip包
ansible web -m yum -a 'name=wget state=absent'
ansible web -m yum -a 'name="@Development Tools"'
pip freeze > a.txt
pip install -r a.txt
pip install 包名
pip list
ansible web -m pip -a 'name=flask'
requirements #安装电脑上的全部
ansible web -m yum -a 'name=nginx'
systemctl start nginx #centos7
service nginx start #centos6
ps -ef|grep nginx
ss -tnlp
systemctl enabled nginx #centos7开机自启动
chkconfig nginx on #centos6开机自启动
ansible web -m service -a 'name=nginx,static=started'
ss -tnlp
ansible web -m service -a 'name=nginx,ststic=stoped'
分时日月周 任务
crontab 0 */2 * * * pwd # 每两个小时执行一次命令
crontab -e
crontab -l
day 天
disabled 禁用
hour 小时
job 任务
minute 分钟
month 月
name 任务名字
weekday 周
ansible web -m cron -a 'minute=27 job="touch /tmp/aaaaaaa.txt" name=touchfile'
ansible web -m cron -a 'name=touchfile state=absent'
ansible web -m cron -a 'minute=30 job="touch /tmp/bbbb.txt" name=touchfile2 disabled=yes'
管理员 root uid 0 普通用户 系统用户 不能登陆系统 uid 1-999 centos7,uid 1-499 centos 6 登陆用户 能够登陆 uid 1000-65535 centos7,uid 500-65535 centos6
管理员组 root 0 系统用户组 uid 1-999 centos7,uid 1-499 centos 6 登陆用户组 uid 1000-65535 centos7,uid 500-65535 centos6
useradd shy
useradd的参数nginx
-d 指定用户的家目录(默认在/home下) -g 指定用户的组 -G 指定用户的附加组 -s 指定登录后使用的shell -r 建立一个系统组(系统用户)
useradd -r shy 建立一个系统用户,从999倒叙 useradd -s /sbin/nologin shy #建立普通用户,从1000开始升序 useradd -d /opt/shy #建立用户时,指定用户的家目录 useradd -u 3000 shy2 #指定uid建立用户
userdel alex #仅删除用户 userdel -r alex #删除用户和加目录
group 组 groups 附加组 home 家目录 name 用户名 password 密码 shell 用户登陆后使用shell system 建立系统用户 uid 指定id建立用户 state 状态 remove 删除用户
ansible web -m user -a 'name=ccc uid=4000 home=/opt/ccc groups=root shell=/sbin/nologin'
ansible web -m user -a 'name=shy static=absent'
ansible web -m user -a 'name=shy static=absent remove=yes'
groupadd shy
groupdel shy
tail -l /etc/group
gid 组的id name 组名 system 系统组 static 状态
ansible web -m group -a 'name=shy system=yes'
ansible web -m group -a 'name=shy static=absent'
在web组中建立一个用户组shy1web
ansible web -m group -a 'name=shy1'
在web组中建立一个用户组shy2shell
ansible web -m group -a 'name=shy2'
把/etc/fstab文件复制到/tmp/f编程
ansible web -m copy -a 'src=/etc/fatab dest=/tmp/f'
安装nginx,并设置开机自启flask
ansible web -m service -a 'name=nginx enabled=yes'
当相同的任务屡次执行时,将任务内容编辑到脚本中,之后执行时,执行脚本便可,节省时间centos
经常使用来写配置文件安全
字典的表示 key:value 列表的表示 -
注:后缀名.yaml或.yml并发
例:
name:shy age:18 addr:heilongjiang hobby: - running - skiing - sleeping
注:yaml对语法要求十分严格(:后必定要有一个空格,=先后必定不能有空格)
- hosts: web tasks: - name: creategroup group: name=shy10 - name: createuser user: name=user10
-C, --check # 检查,白跑,干跑 -f FORKS, --forks=FORKS #用来作并发 --list-hosts # 列出主机列表 --syntax-check # 语法检查
ansible-playbook --syntax-check p1.yml
ansible-playbook -C p1.yml
ansible-playbook p1.yml
注:执行顺序,从上往下执行
幂等性:无论执行多少遍,结果都是同样的
- hosts: web tasks: - name: create{{ user }} user: name={{ user}}
ansible-playbook -e 'user=shy11' p2.yml
修改/etc/ansible/hosts文件
[db] 192.168.107.132 user=shy12 192.168.107.133 user=shy13
修改/etc/ansible/hosts文件
[db:vars] #表示组的参数 user=shy14
- hosts: db vars: - user: shy15 tasks: - name: create{{ user }} user: name={{ user}}
- hosts: db tasks: - name: sum shell: echo 7+8|bc register: user - name: createuser user: name={{user.stdout}}
echo 3+4|bc #计算3+4
-e > playbook > hosts