docker容器安装运维工具ansible和nginx安装

简介:本次博客讲解使用dockerfile编写在当前主流的自动化运维工具ansible和nginx的安装和配置。单机的ansible安装请参考我之前的多主机的ansible安装的文章
步骤
(1)从基础镜像构建开始安装nginx和ansible的安装:代码如下


vi dockerfile

# Pull base image
FROM  centos:latest

MAINTAINER zxj wang "[email protected]"


#环境安装,包括ansible的安装
RUN  yum install -y wget gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype \
freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
 ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel \
 openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid \
 mysql-devel  inetutils-ping net-tools  automake autoconf libtool make  epel-release ansible


#pcre-8.39和nginx-1.1.10安装
RUN  cd /usr/local/src &&  wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz  && tar -zxvf pcre-8.39.tar.gz  &&  cd pcre-8.39 && ./configure &&  make && make install  && cd /usr/local/src &&  groupadd  www && useradd -g  www www -s /bin/false  &&   mkdir /usr/local/nginx   &&   mkdir -p /data/logs/nginx  &&  chown www:www /data/logs/nginx -R   &&  yum install -y zlib-devel  &&   wget http://nginx.org/download/nginx-1.1.10.tar.gz && tar -zxvf nginx-1.1.10.tar.gz &&  cd nginx-1.1.10  && ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module  && make && make install

#设置环境变量
ENV NGINX_HOME /usr/local/nginx
ENV PATH $PATH:$NGINX_HOME/sbin
#ansible把其他集群容器的ip加进来实现免密码登陆

ADD dockerCluster.conf  /root

RUN cd /root && cat dockerCluster.conf >> /etc/ansible/hosts  && sed -i -e 's|#host_key_checking = False|host_key_checking = False|' /etc/ansible/ansible.cfg

RUN yum install -y openssh-server   openssh-clients &&  ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa  &&  cd /root/.ssh/ &&  cp id_rsa.pub  authorized_keys  &&  ssh-keygen -t rsa -P '' -f /etc/ssh/ssh_host_rsa_key  && ssh-keygen -t dsa -P '' -f /etc/ssh/ssh_host_dsa_key &&  ssh-keygen -t rsa -P '' -f /etc/ssh/ssh_host_ecdsa_key && ssh-keygen -t rsa -P '' -f /etc/ssh/ssh_host_ed25519_key && /usr/sbin/sshd

#配置ansible每个节点的连接,两种方式
ADD sendIP.sh  /root    #使用ssh方式建立主管理节点到每个节点的免密码
CMD ["sh", "sendIP.sh"]   #使用直接将各子节点密码设置的方式部署ansible的连接

(2)在同一目录下创建要王ansible配置文件中放的子节点ip等
vi dockerCluster.conf

此处的配置文件直接将子节点密码填写上主要是用于第二种ansible和子节点连接方式的考虑
[dockerCluster]
172.20.30.1 ansible_ssh_pass=root
172.20.30.2 ansible_ssh_pass=root```
3)同样在同一目录下编辑从dockerCluster.conf读取子节点IP发送到其他节点,建立免密码登陆的实现
vi sendIP.sh

‘#’ /bin/bash

while read ip
do
echo ipsshcopyidi/root/.ssh/idrsa.pub ip
done < dockerCluster.conf
“`

(4)编译运行
docker build -t ansiale_nginx:v1
这里写图片描述

你可能感兴趣的:(dockre开发)