docker一键式安装nginx
文章目录
[隐藏]
- 一、准备Dockerfile文件
- 二、创建 nginx-1.8.1.sh 安装脚本
- 三、创建运行脚本 run.sh
- 四、构建
- 五、准备yaml文件 nginx.yaml
- 六、启动yaml
一、准备Dockerfile文件
FROM hub.c.163.com/library/centos:latest RUN echo "Asia/shanghai" > /etc/timezone; RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime COPY nginx-1.8.1.sh /usr/local/ COPY run.sh /usr/local
二、创建 nginx-1.8.1.sh 安装脚本
#!/bin/bash #install nginx-1.8.1 #安装目录 INSTALL_DIR=/opt/ SRC_DIR=/opt/software [ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR} [ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR} # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script!!" exit 1 fi #安装依赖包 for Package in unzip wget gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel do yum -y install $Package done Install_Nginx() { #更新版本信息 NGINX="nginx-1.8.1" PCRE="pcre-8.35" ZLIB="zlib1211" OPENSSL="openssl-1.0.1i" NGINXFEATURES="--prefix=${INSTALL_DIR}nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --pid-path=/var/run/nginx.pid --with-pcre=${SRC_DIR}/${PCRE} --with-zlib=${SRC_DIR}/zlib-1.2.11 --with-openssl=${SRC_DIR}/${OPENSSL} " cd ${SRC_DIR} #下载所需安装包 echo 'Downloading NGINX' if [ ! -f ${NGINX}.tar.gz ] then wget -c http://nginx.org/download/${NGINX}.tar.gz else echo 'Skipping: NGINX already downloaded' fi echo 'Downloading PCRE' if [ ! -f ${PCRE}.tar.gz ] then wget -c https://sourceforge.net/projects/pcre/files/pcre/8.35/${PCRE}.tar.gz else echo 'Skipping: PCRE already downloaded' fi echo 'Downloading ZLIB' if [ ! -f ${ZLIB}.zip ] then wget -c http://zlib.net/${ZLIB}.zip else echo 'Skipping: ZLIB already downloaded' fi echo 'Downloading OPENSSL' if [ ! -f ${OPENSSL}.tar.gz ] then wget -c http://www.openssl.org/source/${OPENSSL}.tar.gz else echo 'Skipping: OPENSSL already downloaded' fi echo '----------Unpacking downloaded archives. This process may take serveral minutes---------' echo "Extracting ${NGINX}..." tar xzf ${NGINX}.tar.gz echo 'Done.' echo "Extracting ${PCRE}..." tar xzf ${PCRE}.tar.gz echo 'Done.' echo "Extracting ${ZLIB}..." unzip ${ZLIB}.zip echo 'Done.' echo "Extracting ${OPENSSL}..." tar xzf ${OPENSSL}.tar.gz echo 'Done.' #添加用户 groupadd -r nginx useradd -r -g nginx nginx #编译 echo '###################' echo 'Compile NGINX' echo '###################' cd ${SRC_DIR}/${NGINX} ./configure ${NGINXFEATURES} make make install cd ../ mkdir -p ${INSTALL_DIR}/nginx/conf/vhosts } Install_Nginx
三、创建运行脚本 run.sh
#!/bin/bash source /etc/profile echo `pwd` sh /usr/local/nginx1.8.sh /usr/local/nginx/sbin/nginx while true; do sleep 1; done
四、构建
docker build -t nginx:0.1 .
五、准备yaml文件 nginx.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx spec: replicas: 1 selector: matchLabels: app: nginx minReadySeconds: 10 template: metadata: labels: app: nginx version: V20170907134852 spec: volumes: - name: logs hostPath: path: /data/log - name: jdk hostPath: path: /usr/local/java/jdk1.8.0_102 - name: project hostPath: path: /data/appdeploy containers: - name: nginx image: nginx:0.1 ports: - containerPort: 80 volumeMounts: - mountPath: /data/log name: logs - mountPath: /usr/local/java/jdk1.8.0_102 name: jdk readOnly: true - mountPath: /data/appdeploy name: project env: - name: DEPLOYMENT_DEMO_VER value: V20170907134852 command: - /usr/local/run.sh --- apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: type: NodePort selector: app: nginx ports: - name: http port: 80 nodePort: 80 targetPort: 80 protocol: TCP selector: app: nginx
六、启动yaml
kubectl create -f y nginx.yaml
大功告成!
原文出处:orchome -> http://www.orchome.com/647
本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。