docker基础实战v1(lnmp+squid)

one.配置基本环境

systemctl stop firewalld
systemctl disable firewalld
vim /etc/selinux/config    #禁用selinux,重起

tar -xf docker.tar.gz #docker安装包
cd docker
yum -y install docker-engine-*
systemctl restart docker ; systemctl enable docker
unzip docker_images.zip
cd docker_images/
docker load < centos.tar    #导入镜像

tar -xf lnmp.tar.gz
cd lnmp_soft/
./install_lnmp.sh
systemctl restart mariadb ; systemctl enable mariadb #本地安装mysql
mysql
    create database tukudb;
    GRANT all ON *.* TO piwigo@'172.18.0.2' identified by '123456';
    GRANT all ON *.* TO piwigo@'172.18.0.3' identified by '123456';


two.制作nginx镜像

docker run --privileged -d centos /sbin/init #手动制作
docker exec -it c1 bash #c1为容器编号,进入容器
[docker1]:
yum repolist
yum -y install openssh-server openssh-clients net-tools
systemctl restart sshd
systemctl enable sshd
echo "123456" | passwd --stdin root
systemctl status sshd
yum -y install php php-fpm php-mysql php-gd

scp -r lnmp_soft 172.18.0.2:/root/
[docker1]:
ssh 172.18.0.2    #c1容器
cd lnmp_soft/
./install_lnmp.sh     #安装nginx
systemctl start nginx
systemctl enable nginx
rm -rf lnmp_soft    #删除节省空间

scp /usr/local/nginx/conf/nginx.conf 118.89.142.169:/usr/local/nginx/conf/
scp /var/ftp/dir/php.ini 118.89.142.169:/etc/
scp nginx.service 172.18.0.2:/usr/lib/systemd/system/
ssh-keygen
ssh-copy-id 172.18.0.2
ssh 172.18.0.2
[docker1]:
systemctl restart nginx
systemctl enable nginx
systemctl restart php-fpm
scp /usr/local/nginx 172.18.0.1:/usr/local/nginx    #重要!用来做公共文件
rm -rf /usr/local/nginx

docker ps
docker stop c1
docker commit -p c1 nginx-v1    #将c1容器制作成镜像
docker run --privileged -d -e "container=docker" -v /usr/local/nginx:/usr/local/nginx nginx-v1 /usr/sbin/init    #把本地挂载过去
scp meiupic_v2.2.0.zip 172.18.0.2:/usr/local/nginx/html/    #在容器中安装

ssh 172.18.0.2
[docker1]:
cd /usr/local/nginx/html/
unzip meiupic_v2.2.0.zip
rm -rf meiupic_v2.2.0.zip

docker stop e8
docker commit -p e8 nginx-v2

ssh 172.18.0.3
[docker2]:
exit    #测试ssh功能


three.做调度器

yum -y install ipvsadm    #尝试使用ipvsadm
ipvsadm --save > /etc/sysconfig/ipvsadm #手动添加文件
systemctl restart ipvsadm ; systemctl enable ipvsadm ;
systemctl restart ipvsadm
ipvsadm -A -t 100.100.2.148:80 -s wrr    #nat模式
ipvsadm -a -t 100.100.2.148:80 -r 172.18.0.2
ipvsadm -a -t 100.100.2.148:80 -r 172.18.0.3
ipvsadm-save -n > /etc/sysconfig/ipvsadm
systemctl stop ipvsadm    #不成功,外网无法访问

yum -y install squid
vim /etc/squid/squid.conf    #有的修改,没有的添加
    http_access allow al
    http_port 80 vhost
    visible_hostname web1.cn
    cache_peer 172.18.0.2   parent 80       0       originserver
    cache_peer 172.18.0.3   parent 80       0       originserver
    cache_mem 128 MB
    cache_dir ufs /var/spool/squid 200 16 128
    coredump_dir /var/spool/squid

systemctl start squid
netstat -anptu | grep 80        #一定要有显示才行


four.配置

随便机器http://xx.xx.xx.xx    #进行网页配置
[docker1]:
awk '{print $1}' 1.txt    #1.txt为网页操作时哪些文件需要权限 复制
awk '{print $1}' 1.txt > 2.txt
rm -rf 1.txt
cd /usr/local/nginx/html/
for i in $(cat 2.txt); do chmod -R 777 $i; done


five.总结

只是简单运用,实际上包会很大,不符合docker的轻量。




posted on 2017-07-24 16:32  日行一善6  阅读(169)  评论(0)    收藏  举报

导航