linux运维13

一、ansible-playbook实现MySQL的二进制部署

ansible 的服务器上配置:
yum install -y ansible  安装ansible
vi /etc/ansible/hosts   配置节点IP
[nodes]
192.168.116.132
192.168.116.133

ssh-keygen    创建秘钥认证,直接回车就行
ssh-copy-id 192.168.116.132
ssh-copy-id 192.168.116.133

cd /root            文件需要放在同一个路径下

vi start_mysql.sh   创建mysql启动脚本
#!/bin/bash
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
service mysqld start
chkconfig --add mysqld


vi init_mysql.exp   创建mysql初始化加固脚本,"Test12#$"这个是数据库root账户密码,可以自己修改
#!/usr/bin/expect
spawn /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/bin/mysql_secure_installation
expect {
        "key for No" { send "y\r"; exp_continue }
        "2 = STRONG" { send "2\r"; exp_continue }
        "password:" { send "Test12#$\r"; exp_continue }
        "password:" { send "Test12#$;\r"; exp_continue}
        "key for No" { send "y\r"; exp_continue }
        "y|Y" { send "y\r"; exp_continue }
        "y|Y" { send "y\r"; exp_continue }
        "y|Y" { send "y\r"; exp_continue }
        "y|Y" { send "y\r"; exp_continue }
}

vi play_mysql.yml  创建play-book文件

#mysql-5.7.31_install
- hosts: nodes
  remote_user: root
  tasks:
    - name: yum_yuan
      yum: name=libaio,numactl-libs,expect

    - name: down_tar.gz
      unarchive: src=https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz dest=/usr/local/ copy=no

    - name: group_mysql
      group: name=mysql gid=55 system=yes

    - name: user_mysql
      user: name=mysql uid=55 group=mysql shell=/sbin/nologin system=yes create_home=no

    - name: copy_cfg
      copy: src=/root/my.cnf dest=/etc/my.cnf owner=root group=root mode=600

    - name: create_link
      file: src=/usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ dest=/usr/local/mysql state=link owner=mysql group=mysql mode=755 force=yes

    - name: create_dir_init-server
      file: path=/data/ state=directory owner=mysql group=mysql mode=755

    - name: init_mysql
      shell: '/usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/bin/mysqld  --initialize-insecure --user=mysql --datadir=/data/mysql'

    - name: copy_mysqld
      shell: '/usr/bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld'

    - name: chkconfig_mysqld
      shell: '/usr/sbin/chkconfig --add /etc/init.d/mysqld'

    - name: file_mode_change
      file: path=/data/ state=directory owner=mysql group=mysql recurse=yes

    - name: scirpt_status
      script: /root/start_mysql.sh

    - name: scirpt_init
      script: /root/init_mysql.exp

ansible-playbook play_mysql.yml      运行配置,开始安装为节点安装mysql

在这里插入图片描述

在节点上测试是否安装成功,查看密码是否能登录

service mysqld status
mysql -uroot -pTest12#$

在这里插入图片描述

二、Ansible playbook实现apache批量部署,并对不同主机提供以各自IP地址为内容的index.html

cd /root
vi httpd.service   创建service文件

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
ExecStart=/httpd/bin/apachectl start
ExecReload=/httpd/bin/apachectl graceful
ExecStop=/httpd/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target

vi play_httpd.yml    创建ansible-play文件

#httpd_2.4_install
- hosts: nodes
  remote_user: root
  tasks:
    - name: yum_yuan
      yum: name=gcc,expat-devel

    - name: group_apache
      group: name=apache gid=80 system=yes

    - name: user_apache
      user: name=apache uid=80 group=apache shell=/sbin/nologin system=yes create_home=no

    - name: create_dir
      file: path=/httpd state=directory owner=apache group=apache mode=755

    - name: down_apr
      unarchive: src=https://dlcdn.apache.org/apr/apr-1.7.0.tar.gz dest=/usr/local/ copy=no validate_certs=no

    - name: down_apr_util
      unarchive: src=https://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz dest=/usr/local/ copy=no validate_certs=no

    - name: down_httpd
      unarchive: src=http://archive.apache.org/dist/httpd/httpd-2.4.46.tar.gz dest=/usr/local/ copy=no validate_certs=no

    - name: change_apr
      shell: sed -ri 's@\$RM "\$cfgfile"@\# \$RM "\$cfgfile"@g' /usr/local/apr-1.7.0/configure

    - name: make_apr
      shell: /usr/local/apr-1.7.0/configure --prefix=/httpd/apr && make && make install

    - name: make_apr_util
      shell: /usr/local/apr-util-1.6.1/configure --prefix=/httpd/apr-util --with-apr=/httpd/apr/ && make && make install

    - name: make_httpd
      shell: /usr/local/httpd-2.4.46/configure --prefix=/httpd  --enable-so  --enable-ssl --enable-cgi  --enable-rewrite  --with-zlib --with-pcre --with-apr=/httpd/apr/  --with-apr-util=/httpd/apr-util/  --enable-modules=most  --enable-mpms-shared=all --with-mpm=prefork  && make && make install

    - name: set_conf_user_group
      shell: sed -ri -e 's/User daemon/User apache/g'  -e 's/Group daemon/Group apache/g' /httpd/conf/httpd.conf

    - name: create_index
      shell: echo `hostname -I` >/httpd/htdocs/index.html

    - name: copy_service
      copy: src=/root/httpd.service dest=/usr/lib/systemd/system/httpd.service owner=root group=root mode=600

    - name: path
      shell: echo "PATH=/httpd/bin:$PATH" >/etc/profile.d/httpd.sh && source /etc/profile.d/httpd.sh

    - name: file_mode_change
      file: path=/httpd/ state=directory owner=apache group=apache recurse=yes

    - name: start_httpd
      service: name=httpd state=started enabled=yes
      
ansible-playbook play_httpd.yml   开始节点安装httpd

在这里插入图片描述
查看节点的httpd状态和网页访问

httpd -v                   查看httpd的版本
systemctl status httpd     查看服务状态
curl 192.168.116.132       查看网页

在这里插入图片描述

三、http的报文结构和状态码总结

具体代码查看链接: http代码介绍

  • 200:网页访问正常
  • 301: 临时重定向
  • 302: 永久重定向
  • 304:请求网页没有发生过改变,一般是浏览器缓存
  • 307: 浏览器内部重定向
  • 401: 需要输入账号和密码认证方能访问
  • 403: 请求被禁止,一般是没被服务器授权
  • 404: 页面不存在,请求不了资源
  • 500: 服务器内部错误或故障
  • 502:代理服务器无法连接到后端服务器
  • 503: 一般是服务器负载太高或卡死,无法回复客户端请求
  • 504: 客户端和服务器的连接超时
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值