Docker 鏡像只制作LNMP + redis

jopen 8年前發布 | 14K 次閱讀 Docker

Docker 鏡像只制作LNMP + redis

一、制作背景

Window10 + VM11 + opensuse + docker + centos7dockers鏡像

這里主要是分享LNMP + redis 鏡像的制作,跳過其他。

二、配置LNMP

      1、安裝docker 鏡像 centos7

Yum install docker-io 安裝docker

Service docker start   啟動 docker 服務

Chkconfig docker on 設置開機啟動

Docker pull centos:7  docker 倉庫中獲取鏡像(這里的鏡像)

可以通過 docker images 列出本地倉庫中存在的docker 鏡像

docker run -it -p 80:80 -p 10000:10000 --name=test2 centos:7

跑起鏡像centos:7        開放80 10000端口權限 命名為 test2

Ctrl + p Ctrl + q 退出容器

Docker ps 查看正在運行的容器

 

Docker attach test2 進入正在運行的test2容器  L已經配好了)

2、安裝 mysql

把所需要的源代碼下載至 /usr/local/src

安裝M mysql

Yum install –y wget

Wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz  獲取mysql 源代碼

將壓縮包解壓到/usr/local/mysql

命令如下:

cd /usr/local
tar -zxvf /usr/local/src/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.28-linux-glibc2.5-x86_64 mysql

創建一個mysql 用戶組和mysql用戶并將 mysql目錄的所有的權限給mysql

Groupadd mysql
Useradd –r –g mysql mysql
Cd  /usr/local/mysql
Chmod –R mysql:mysql ./

執行命令 ./scripts/mysql_install_db --user=mysql 安裝mysql

安裝之前先檢查 有沒有安裝 perl 如果沒有先安裝:yum –y install perl perl-devel perl-Module-Install.noarch

再檢查有沒有安裝libaio ,如果沒有就安裝:yum –y install libaio libaio-devel

 安裝完提示:

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h 59ee867f63a2 password 'new-password'
Alternatively you can run:
  ./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
  cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
  http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.

修改當前目錄擁有者為root用戶:執行命令 chown -R root:root ./

修改當前data目錄擁有者為mysql用戶:執行命令 chown -R mysql:mysql data

support-files/mysql.server start(假如啟動成功)

./bin/mysqladmin -u root password '密碼'

檢查是否安裝成功: /usr/local/mysql/bin/mysql –u root –p

                           然后輸入密碼

3、安裝 N nginx

wget http://nginx.org/download/nginx-1.9.8.tar.gz

1:首先安裝Nginx所需要的庫

a.GCC編譯器

yum install -y gcc

b.G++編譯器:C++來編譯Nginxhttp模塊

yum install -y gcc-c++

c.PCRE庫:正則表達式

yum install -y pcre pcre-devel

d.zlib

HTTP包的內容作gzip壓縮

yum install -y zlib zlib-devel

e.OpenSSL開發庫

如果服務器要支持在SSL協議上傳輸HTTP就需要OpenSSL

yum install -y openssl openssl-devel

 

tar –zxvf nginx-1.9.8.tar.gz

 

wget http://nginx.org/download/nginx-1.9.8.tar.gz

mkdir /usr/local/nginx

1:首先安裝Nginx所需要的庫

a.GCC編譯器

yum install -y gcc

b.G++編譯器:C++來編譯Nginxhttp模塊

yum install -y gcc-c++

c.PCRE庫:正則表達式

yum install -y pcre pcre-devel

d.zlib

HTTP包的內容作gzip壓縮

yum install -y zlib zlib-devel

e.OpenSSL開發庫

如果服務器要支持在SSL協議上傳輸HTTP就需要OpenSSL

yum install -y openssl openssl-devel

 

./configure --prefix=/usr/local/nginx

make && make install

 

4、安裝P

wget  

yum -y install make cmake automake autoconf kernel-devel ncurses-devel libxml2-devel curl-devel libjpeg-devel libpng-devel  pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils   readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel openldap openldap-devellibxslt-devel libldap libldap-devel

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-zlib --with-curl --with-curlwrappers --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-openssl --enable-sockets --enable-zip --without-pear

 

跑起fpm

 命令:/usr/local/php/sbin/php-fpm

編輯 nginx.conf如下:

新建index.phpconnectMysql.php兩個文件 ,保存在/usr/local/nginx/html

Index.php

內容:<?php phpinfo(); ?>

connectMysql.php

內容:

用瀏覽器跑他們兩個

127.0.0.1/index.php

127.0.0.1/connectMysql.php

5、安裝redis

wget http://download.redis.io/releases/redis-2.8.3.tar.gz

tar –zxvf redis-2.8.3.tar.gz

cd redis-2.8.3

make

cd src

mkdir /usr/local/redis

cp redis-server /usr/local/redis cp redis-benchmark /usr/local/redis cp redis-cli /usr/local/redis cp ../redis.conf /usr/local/redis

cd /usr/local/redis

跑起redis redis-server redis.conf

 

6、編譯 phpreids

下載:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

cd /usr/local/src #進入軟件包存放目錄

wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

tar -zxvf 2.2.4.tar.gz #解壓

cd phpredis-2.2.4 #進入安裝目錄

/usr/local/php/bin/phpize #phpize生成configure配置文件

./configure --with-php-config=/usr/local/php/bin/php-config  #配置

make  #編譯

make install  #安裝

安裝完成之后,出現下面的安裝路徑

/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/


vi /usr/local/php/etc/php.ini  #編輯配置文件,在最后一行添加以下內容

添加

extension="redis.so"

:wq! #保存退出

sudo service nginx restart

sudo /etc/init.d/php-fpm restart

瀏覽器訪問:127.0.0.1/index.php 查看redis 擴展是否已經裝上

退出容器 exit

要先登陸才能上傳哦

docker commit -m "create my first php env" -a "sw_cyz" 59ee867f63a2 cover/phpenv:v1

docker push cover/phpenv:v1 


來自: http://my.oschina.net/swchenyuzhe/blog/598503

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!