2019年9月26日 星期四

Docker Concept

1. Example 1
Docker 不是虚拟机,容器中的应用都应该以前台执行,而不是像虚拟机、物理机里面那样,用 systemd去启动后台服务,容器内没有后台服务的概念。
一些初学者将 CMD 写为:
CMD service nginx start
然后发现容器执行后就立即退出了。甚至在容器内去使用 systemctl 命令结果却发现根本执行不了。这就是因为没有搞明白前台、后台的概念,没有区分容器和虚拟机的差异,依旧在以传统虚拟机的角度去理解容器。
正确的做法是直接执行 nginx 可执行文件,并且要求以前台形式运行。比如:
CMD ["nginx", "-g", "daemon off;"]


2.  EXPOSE

EXPOSE
 指令是声明运行时容器提供服务端口,这只是一个声明,
在运行时并不会因为这个声明应用就会开启这个端口的服务。在 Dockerfile 中写入这样的声明有两个好处,一个是帮助镜像使用者理解这个镜像服务的守护端口,以方便配置映射;另一个用处则是在运行时使用随机端口映射时,也就是 docker run -P时,会自动随机映射 EXPOSE 的端口。
要将 EXPOSE 和在运行时使用 -p <宿主端口>:<容器端口> 区分开来。-p,是映射宿主端口和容器端口,换句话说,就是将容器的对应端口服务公开给外界访问,而 EXPOSE 仅仅是声明容器打算使用什么端口而已,并不会自动在宿主进行端口映射



3. WORKDIR 
格式为 WORKDIR <工作目录路径>
使用 WORKDIR 指令可以来指定工作目录(或者称为当前目录),以后各层的当前目录就被改为指定的目录,如该目录不存在,WORKDIR 会帮你建立目录。
之前提到一些初学者常犯的错误是把 Dockerfile 等同于 Shell 脚本来书写,这种错误的理解还可能会导致出现下面这样的错误:
RUN cd /app
RUN echo "hello" > world.txt
如果将这个 Dockerfile 进行构建镜像运行后,会发现找不到 /app/world.txt 文件,或者其内容不是 hello。原因其实很简单,在 Shell 中,连续两行是同一个进程执行环境,因此前一个命令修改的内存状态,会直接影响后一个命令;而在 Dockerfile 中,这两行 RUN 命令的执行环境根本不同,是两个完全不同的容器。这就是对 Dockerfile 构建分层存储的概念不了解所导致的错误。
之前说过每一个 RUN 都是启动一个容器、执行命令、然后提交存储层文件变更。第一层 RUN cd /app 的执行仅仅是当前进程的工作目录变更,一个内存上的变化而已,其结果不会造成任何文件变更。而到第二层的时候,启动的是一个全新的容器,跟第一层的容器更完全没关系,自然不可能继承前一层构建过程中的内存变化。
因此如果需要改变以后各层的工作目录的位置,那么应该使用 WORKDIR 指令



4.  study
https://jeffreyfritz.com/2018/09/deploying-asp-net-core-with-net-framework-using-docker/

https://www.jinnsblog.com/2018/12/docker-dockerfile-guide.html

https://blog.alexellis.io/run-iis-asp-net-on-windows-10-with-docker/

http://www.codedata.com.tw/social-coding/docker-layman-abc/

https://columns.chicken-house.net/2018/05/12/msa-labs2-selfhost/


https://skychang.github.io/2015/07/30/%E8%AE%93-ASP-NET-MVC-%E5%9F%B7%E8%A1%8C%E6%96%BC-Docker/

2019年9月25日 星期三

apache redis guidline



https://blog.gxxsite.com/laravel-redis-cache-clear-session-queue/

https://matomo.org/faq/how-to/faq_20521/


https://github.com/MISP/misp-book/issues/36

https://www.cloudways.com/blog/redis-for-queuing-in-laravel-5/


https://www.objectrocket.com/blog/how-to/top-5-redis-use-cases/


# apache mpm_prefork
https://serverfault.com/questions/269674/why-is-apache-running-so-many-processes-excessive-ram-here

https://stackoverflow.com/questions/15922194/problems-with-apache-servers-and-a-lot-of-httpd-processes

https://serverfault.com/questions/823121/why-is-apache-spawning-so-many-processes

https://serverfault.com/questions/365205/why-are-there-many-httpd-process-on-the-machine-while-i-only-started-one-apache

https://stackoverflow.com/questions/36924952/ah00161-server-reached-maxrequestworkers-setting-consider-raising-the-maxreque

https://serverfault.com/questions/684424/how-to-tune-apache-on-ubuntu-14-04-server

docker apache notice the tmpfs



1.  Problem

Apache 2.4 AH01762 & AH01760: failed to initialize shm (Shared Memory Segment)




2. solution
$ mkdir /run/httpd



3. reason
为了让容器能够访问数据而不需要永久地写入数据,可以使用 tmpfs 挂载,该挂载仅存储在主机的内存中(如果内存不足,则为 swap)。当容器停止时,tmpfs 挂载会被移除。如果提交容器,则不会保存 tmpfs 挂载



4. ref

https://ma.ttias.be/apache-2-4-ah01762-ah01760-failed-to-initialize-shm-shared-memory-segment/
https://bugzilla.redhat.com/show_bug.cgi?id=1215667

# tmpfs
https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
https://zh.wikipedia.org/zh-tw/Tmpfs
https://adon988.logdown.com/posts/7801999-docker-tmpfs

https://blog.csdn.net/kikajack/article/details/79475168
https://unix.stackexchange.com/questions/13972/what-is-this-new-run-filesystem

2019年9月16日 星期一

docker reference


1. docker good book
https://www.jinnsblog.com/2018/10/docker-container-command.html

https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes

https://philipzheng.gitbooks.io/docker_practice/content/container/run.html

http://www.runoob.com/docker/docker-commit-command.html

http://www.runoob.com/docker/docker-install-apache.html

https://ithelp.ithome.com.tw/articles/10186431

https://skychang.github.io/2015/07/30/%E5%BB%BA%E7%AB%8B%E8%87%AA%E5%B7%B1%E7%9A%84-Docker-image/

https://www.scalyr.com/blog/create-docker-image/

https://joshhu.gitbooks.io/dockercommands/content/DockerImages/CommandArgs.html

# docker paty2
https://medium.com/@VisonLi/docker-%E5%85%A5%E9%96%80-%E7%AD%86%E8%A8%98-part-2-91e4dfa2b365

# simple learn docker
https://philipzheng.gitbooks.io/docker_practice/content/container/daemon.html

https://joshhu.gitbooks.io/dockercommands/content/Parameters/Parameters.html

2. docker php
https://medium.com/@vi1996ash/steps-to-build-apache-web-server-docker-image-1a2f21504a8e
https://medium.com/faun/how-to-build-a-docker-container-from-scratch-docker-basics-a-must-know-395cba82897b
https://www.ibm.com/developerworks/community/blogs/8ff122ba-5fbc-4844-8f62-340d437131ee/entry/How_to_build_your_own_Apache_HTTP_server_on_Docker?lang=en

https://github.com/docker-library/httpd/blob/17166574dea6a8c574443fc3a06bdb5a8bc97743/2.4/httpd-foreground

https://serverfault.com/questions/901810/cant-start-httpd-service-in-docker-image

https://phoenixnap.com/kb/how-to-restart-apache-centos-linux

https://phoenixnap.com/kb/how-to-restart-apache-centos-linux


3. apache centos7
https://blog.yslifes.com/archives/2523
https://www.rosehosting.com/blog/how-to-install-php-7-2-on-centos-7/
http://blog.cspc123.com/?p=168



4.  docker content
https://qiita.com/vc7/items/82863c4bd1f70f102b36

https://stackify.com/docker-performance-improvement-tips-and-tricks/

https://www.ithome.com.tw/news/103247

# docker cenos7 image
https://hub.docker.com/_/centos

# docker hello wold
https://medium.com/@VisonLi/docker-%E5%85%A5%E9%96%80-%E7%AD%86%E8%A8%98-part-2-91e4dfa2b365

# docker compose
http://blog.maxkit.com.tw/2017/03/docker-compose.html

https://stackoverflow.com/questions/34482018/docker-compose-up-does-not-start-a-container

https://yami.io/ubuntu-docker/

https://medium.com/@giorgioto/docker-compose-yml-from-v1-to-v2-3c0f8bb7a48e

https://dev.to/kbariotis/dont-just-docker-compose-up-gff

# docker overivew
https://blog.techbridge.cc/2018/09/07/docker-compose-tutorial-intro/



5. Httpd
https://github.com/hhcordero/docker-centos-apache-dev/blob/master/Dockerfile

http://www.inanzzz.com/index.php/post/rhsb/running-apache-server-as-foreground-on-ubuntu-with-dockerfile

https://github.com/hhcordero/docker-centos-apache-dev/blob/master/httpd-foreground

# httpd security
https://www.tecmint.com/apache-security-tips/



6. http://www2.lssh.tp.edu.tw/~hlf/class-1/linux/file_permission.htm
咦!似乎好像是可以喔!因為有可讀[ r ]存在嘛!『錯!』答案是非 root 這個帳號的其他使用者均不可進入 .ssh 這個目錄,為什麼呢?因為 x 與 目錄 的關係相當的重要,如果您在該目錄底下不能執行任何指令的話,那麼自然也就無法執行 ls, cd 等指令,所以囉,也就無法進入了,因此,請特別留意的是,如果您想要開放某個目錄讓一些人進來的話,請記得將該目錄的 x 屬性給開放呦! 


https://shian420.pixnet.net/blog/post/344938711-%5Blinux%5D-chmod-%E6%AA%94%E6%A1%88%E6%AC%8A%E9%99%90%E5%A4%A7%E7%B5%B1%E6%95%B4%21

https://www.thegeekstuff.com/2016/04/docker-compose-up-stop-rm/



7.

2019年9月5日 星期四

Load balance mech


KeepliveD
1.  https://www.keepalived.org/
2. https://access.redhat.com/documentation/zh-tw/red_hat_enterprise_linux/7/html/load_balancer_administration/ch-initial-setup-vsa


3. https://dawho.tw/
4. http://gcharriere.com/blog/?p=339

5. http://mylinuxcloudnotes.blogspot.com/2015/08/centos7-keepalived.html
6. https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/408407/

7.http://icodding.blogspot.com/2015/08/mysql-replicationmaster-slave.html

8.https://geekflare.com/open-source-load-balancer/
9. https://geekflare.com/open-source-load-balancer/#Pen

10.https://access.redhat.com/documentation/zh-tw/red_hat_enterprise_linux/7/pdf/load_balancer_administration/Red_Hat_Enterprise_Linux-7-Load_Balancer_Administration-zh-TW.pdf


11. https://www.nginx.com/blog/scaling-mysql-tcp-load-balancing-nginx-plus-galera-cluster/

12. https://linuxhandbook.com/load-balancing-setup/

13.https://severalnines.com/blog/using-nginx-database-load-balancer-galera-cluster

14. https://dasunhegoda.com/nginx-reverse-proxying-load-balancing/1248/

15. https://www.manpc.tk/wordpress/2016/06/03/nginx-load-balancer%E5%B9%B3%E8%A1%A1%E8%B2%A0%E8%BC%89for-mysql-or-mariadb-galera-cluster/

16https://www.nginx.com/blog/mysql-high-availability-with-nginx-plus-and-galera-cluster/