Docker 鏡像只製做LNMP + redis

Docker 鏡像只製做LNMP + redisphp

1、製做背景html

Window10 + VM11 + opensuse + docker + centos7dockers鏡像mysql

這裏主要是分享LNMP + redis 鏡像的製做,跳過其餘。linux

2、配置LNMPnginx

      一、安裝docker 鏡像 centos7c++

Yum install docker-io 安裝dockergit

Service docker start   啓動 docker 服務github

Chkconfig docker on 設置開機啓動web

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已經配好了)

二、安裝 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
Chown –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

                           而後輸入密碼

三、安裝 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

 

四、安裝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

五、安裝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

 

六、編譯 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 

相關文章
相關標籤/搜索