dever 6 years ago
parent
commit
cda48c5628

+ 12 - 0
README.md

@@ -207,4 +207,16 @@ dm shell
 4、增加持续集成等功能(从git上自动拉取代码并更新容器:CircleCI)
 5、增加测试工具包
 6、增加自动代理(能够通过dm直接访问google查资料)
+</pre>
+
+
+<pre>
+2018-6-14更新:
+1、增加default功能,直接使用dever run web时,只运行里面default定义的进程
+2、增加lvs
+3、增加集群(简易版本):
+dm master:开启主机
+dm slave num=5&master=192.168.0.10&port=1000:开启5个从机,主机地址为192.168.0.10,端口为1000
+
+开启后,从机自动收集信息并同步到主机上
 </pre>

+ 3 - 0
container/conf/db/mariadb/my.conf

@@ -27,6 +27,9 @@ socket          = /run/mysqld/mysqld.sock
 # The MariaDB server                                                       
 [mysqld] 
 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
+slow_query_log = ON
+long_query_time = 3
+max_connections	=	1000
 skip-name-resolve
 skip-host-cache
 user=root                 

+ 2 - 0
container/conf/db/mysql/conf.d/docker.cnf

@@ -1,3 +1,5 @@
 [mysqld]
 skip-host-cache
 skip-name-resolve
+slow_query_log = ON
+long_query_time = 3

+ 2 - 1
container/conf/web/nginx/conf.d/site.conf

@@ -34,7 +34,8 @@ server {
         # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
 
         # With php-cgi alone:
-        fastcgi_pass web-php7:9000;
+        #fastcgi_pass web-php7:9000;
+        fastcgi_pass onepage-php5:9000;
         # With php-fpm:
         #fastcgi_pass unix:/var/run/php7-fpm.sock;
         fastcgi_index index.php;

+ 5 - 6
install

@@ -5,15 +5,11 @@ check()
     yes=`which $1 | wc -l`
     echo $yes
 }
+
+# docker
 status=`check docker`
 if [ "$status" = 0 ]; then
 	curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
-	apt-get update
-	apt-get -y install apt-transport-https ca-certificates curl software-properties-common
-	curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
-	add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
-	apt-get -y update
-	apt-get -y install docker-ce
 fi
 mkdir -p /etc/docker
 tee /etc/docker/daemon.json <<-'EOF'
@@ -24,6 +20,9 @@ tee /etc/docker/daemon.json <<-'EOF'
 EOF
 service docker restart
 
+# python 
+pip install python-daemon
+
 chmod -R +x src/*.py
 chmod -R +x src/shell
 chmod -R 777 container/share/

+ 9 - 1
src/core.py

@@ -399,4 +399,12 @@ class Core(object):
 		except : 
 			return  0 
 		else : 
-			return  1
+			return  1
+
+	@staticmethod
+	def ip(ifname = 'eth0'):
+		import socket, fcntl, struct  
+		s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
+		inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))  
+		ret = socket.inet_ntoa(inet[20:24])
+		return ret

+ 0 - 0
src/docker/build/ha/haproxy/Dockerfile → src/docker/build/balance/haproxy/Dockerfile


+ 0 - 0
src/docker/build/ha/haproxy/nginx.sh → src/docker/build/balance/haproxy/nginx.sh


+ 0 - 0
src/docker/build/ha/keepalived/Dockerfile → src/docker/build/balance/keepalived/Dockerfile


+ 0 - 0
src/docker/build/ha/keepalived/nginx.sh → src/docker/build/balance/keepalived/nginx.sh


+ 7 - 0
src/docker/build/balance/lvs/Dockerfile

@@ -0,0 +1,7 @@
+FROM docker.dever.cc/os/alpine:latest
+
+MAINTAINER Rabin "https://github.com/shemic"
+
+RUN apk add --no-cache --update ipvsadm
+
+CMD ["sh"]

+ 13 - 0
src/docker/build/balance/lvs/nginx.sh

@@ -0,0 +1,13 @@
+#!/usr/bin/env sh
+set -e
+
+start_nginx()
+{
+	#exec nginx
+	nginx &
+}
+
+stop_nginx()
+{
+    nginx -s stop
+}

+ 1 - 1
src/docker/build/db/mariadb/entrypoint.sh

@@ -87,5 +87,5 @@ if [ "$1" = 'mysqld' ]; then
 	#chown -R mysql:mysql "$DATADIR"
 fi
 
-mysqld --user=root --datadir="$DATADIR"
+mysqld --user=root --datadir="$DATADIR" --init-file="/etc/mysql/my.conf"
 #exec "$@"

+ 20 - 2
src/docker/build/db/redis/Dockerfile

@@ -1,3 +1,21 @@
-FROM redis:latest
+FROM docker.dever.cc/dev/python:latest
 
-MAINTAINER Rabin "https://github.com/shemic"
+MAINTAINER Rabin "https://github.com/shemic"
+
+RUN apk add --update redis git && \
+	echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf && \
+	echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local && \
+	pip install tornado && \
+	pip install redis && \
+	pip install python-dateutil && \
+	cd /usr/local && \
+	git clone https://github.com/kumarnitin/RedisLive.git redislive && \
+	apk del git
+
+COPY redis-live.conf /usr/local/redislive/src/redis-live.conf
+COPY redis.sh /entrypoint/redis.sh
+
+EXPOSE 8888
+EXPOSE 6379
+
+CMD ["redis"]

+ 0 - 17
src/docker/build/db/redis/entrypoint.sh

@@ -1,17 +0,0 @@
-#!/bin/bash
-set -e
-
-dever_start()
-{
-	redis-server &
-	cd /usr/local/redislive/src/
-	./redis-monitor.py --duration=120 > /dev/null &
-	./redis-live.py > /dev/null &	
-}
-
-if [ "$1" = 'redis' ]; then
-	d=6379
-	dever_start $d
-fi
-
-exec sh

+ 20 - 0
src/docker/build/db/redis/redis.sh

@@ -0,0 +1,20 @@
+#!/usr/bin/env sh
+set -e
+
+start_redis()
+{
+	redis-server /etc/redis.conf &
+	cd /usr/local/redislive/src/
+	./redis-monitor.py --duration=120 > /dev/null &
+	./redis-live.py > /dev/null &	
+}
+
+stop_redis()
+{
+    nginx -s stop
+}
+
+monit_redis()
+{
+	process_monit redis-server /etc/redis.conf
+}

+ 2 - 1
src/docker/build/office/convert/Dockerfile

@@ -6,9 +6,10 @@ ENV DEMETER_HOME=/usr/local/convert
 ENV DEMETER_CONF=env
 ENV PATH=$PATH:$DEMETER_HOME
 
-RUN apk add --no-cache --update gcc curl gcc g++ python-dev py-pip && \
+RUN apk add --no-cache --update git gcc curl gcc g++ python-dev py-pip imagemagick imagemagick-dev && \
 	pip install --upgrade pip && \
 	pip install redis && \
+	pip install wand && \
 	pip install -U git+http://git.dever.cc:3000/python/demeter.git && \
 	git clone http://git.dever.cc:3000/python/convert.git $DEMETER_HOME && \
 	#chmod -R +x $DEMETER_HOME/*.py && \

+ 6 - 2
src/docker/build/service/consul/consul.sh

@@ -3,7 +3,11 @@ set -e
 
 start_consul()
 {
-	process_start consul agent -server -bootstrap-expect 1 -data-dir /root/consul/data -config-dir /root/consul/config -client 0.0.0.0
+	if [ "$1" == "server" ]; then
+		process_start consul agent -server -bootstrap-expect 1 -data-dir /root/consul/data -config-dir /root/consul/config -client 0.0.0.0
+	else
+		process_start consul agent -client -config-dir /root/consul/config -join 0.0.0.0
+	fi
 	#consul members
 }
 
@@ -14,5 +18,5 @@ stop_consul()
 
 monit_consul()
 {
-	process_monit consul
+	true
 }

+ 18 - 0
src/docker/conf/dm.conf

@@ -0,0 +1,18 @@
+[base]
+path = {base}
+network = web
+defalut = manage
+
+[master]
+image = service/consul
+port = 8500:8500
+volumes = {container}conf/service/consul:/root/consul/config
+command = consul server
+
+[slave]
+image = service/consul
+volumes = {container}conf/service/consul:/root/consul/config
+command = consul client
+
+[manage]
+port = 8088:8088

+ 6 - 2
src/docker/conf/server.conf

@@ -14,8 +14,9 @@ image = mongodb
 port = 3000:3000
 
 [redis]
-port = 6379:6379
+port = 6379:6379,8888:8888
 volumes = {container}conf/db/redis/redis.conf:/etc/redis.conf
+command = redis
 
 [consul]
 image = service/consul
@@ -28,4 +29,7 @@ port = 8071:15672
 environment = RABBITMQ_DEFAULT_USER=rabin,RABBITMQ_DEFAULT_PASS=123456,RABBITMQ_DEFAULT_VHOST=my_vhost
 
 [graphite]
-port = 8081:80,8082:81,8125:8125/udp,2003:2003,8126:8126
+port = 8081:80,8082:81,8125:8125/udp,2003:2003,8126:8126
+
+[lvs]
+command = sh

+ 7 - 4
src/docker/conf/web.conf

@@ -1,22 +1,24 @@
 [base]
 path = {base}
 network = web
+default = mysql,php7,nginx
 
 [mysql]
 port = 3309:3306
 volumes = {container}conf/db/mysql:/etc/mysql,/mysql/{name}/data:/var/lib/mysql
 environment = MYSQL_ROOT_PASSWORD=123456
 
-[#mysql]
+[mariadb]
+#使用mariadb来代替mysql
 image = mariadb
-port = 3309:3306
+port = 3310:3306
 volumes = {container}conf/db/mariadb:/etc/mysql,/mysql/{name}/data:/var/lib/mysql
 environment = MYSQL_ROOT_PASSWORD=123456
 
-[#php5]
+[php5]
 image = php5
 #port = 8081:8080
-port = 7272:7272,1236:1236,55151:55151
+#port = 7272:7272,1236:1236,55151:55151
 #link和from由于network的存在,已经不需要了
 #link = [mysql]{num}:[mysql]{num}
 #volumes_from = [mysql]{num}
@@ -33,6 +35,7 @@ alias = php,composer,pecl,apk,/install.sh->phpInstall
 [nginx]
 port = 80:80,443:443
 volumes = {container}web:/www,{container}conf/web/nginx:/etc/nginx,{container}logs/nginx/{name}/logs:/var/log/nginx
+alias = nginx
 
 [#nginx]
 #使用openresty来代替nginx,可以写lua脚本了

+ 4 - 1
src/docker/core.conf

@@ -109,4 +109,7 @@ phantomjs           = spider/phantomjs
 ;office
 libreoffice			= office/libreoffice
 pdf2htmlex			= office/pdf2htmlex
-convert				= office/convert
+convert				= office/convert
+
+;balance
+lvs					= balance/lvs

+ 13 - 1
src/main.py

@@ -14,7 +14,7 @@ class Main(object):
 	def init(self, use = 'docker'):
 		Core.path = File.path().replace('/src/', '/')
 		Args.init()
-		method = ('use', 'set', 'val', 'up', 'commit', 'path', 'shell')
+		method = ('use', 'set', 'val', 'up', 'commit', 'path', 'shell', 'master', 'ip')
 		if Args.action in method:
 			self.handle()
 		else:
@@ -74,4 +74,16 @@ class Main_Action(object):
 	def shell():
 		print Core.shell(Args.name)
 
+	@staticmethod
+	def master():
+		print Core.path + 'src/shell/dm'
+
+	@staticmethod
+	def ip():
+		if not Args.name:
+			ifname = 'eth0'
+		else:
+			ifname = Args.name
+		print Core.ip(ifname)
+
 #Main.init()

+ 5 - 2
src/tool/docker.py

@@ -33,7 +33,10 @@ class Docker(object):
 		if Args.index in self.conf['config']:
 			self.handle(method, self.conf['config'][Args.index], Args.index, Args.action)
 		else:
-			for item in self.conf['server']:
+			server = self.conf['server']
+			if 'default' in self.conf['base']:
+				server = self.conf['base']['default'].split(',')
+			for item in server:
 				if self.check(Args.index, item) == True:
 					self.handle(method, self.conf['config'][item], item, Args.action)
 	@classmethod
@@ -365,7 +368,7 @@ class Docker_Action(object):
 		state = Container.check(param['name'])
 		if state == 0:
 			Docker.hook('start', param['config'], param['name'])
-			run = ['-it', '--name='+param['name'], '--hostname='+param['name'], restart, daemon, '-v '+Core.path+'container/share:/share -v /etc/hosts:/etc/hosts.main']
+			run = ['-it', '--name='+param['name'], '--hostname='+param['name'], restart, daemon, '-v '+Core.path+'container/share:/share -v /etc/hosts:/etc/hosts.main', '--env HOSTIP="'+Core.ip()+'"']
 
 			args = Container.args()
 			for key in args: