docker题外话:
centos7安装supervisor:
源码编译安装:
下载源码文件:supervisor-3.3.1.tar.gz下载地址:https://pypi.python.org/pypi/supervisor 1
2
3
4
5
6
7
8
9
10
11
12
13
14
安装:
[iyunv@cenots7 src]# tar -zxf supervisor-3.3.1.tar.gz
[iyunv@cenots7 src]# cd supervisor-3.3.1/
[iyunv@cenots7 supervisor-3.3.1]# python setup.py install
检查是否安装成功:
登陆python控制台输入import supervisor 查看是否能成功加载
[iyunv@cenots7 supervisor-3.3.1]# python
Python 2.7.5 (default, Sep 15 2016, 22:37:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import supervisor
>>>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
生成配置文件:
[iyunv@cenots7 supervisor-3.3.1]# mkdir /etc/supervisor
[iyunv@cenots7 supervisor-3.3.1]# echo_supervisord_conf > /etc/supervisor/supervisord.conf
[iyunv@cenots7 supervisor-3.3.1]# grep -E -v '^;|^$' /etc/supervisor/supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
1
2
3
4
5
6
7
8
9
10
11
12
启动服务:
[iyunv@cenots7 tmp]# supervisord -c /etc/supervisor/supervisord.conf
关闭服务:
[iyunv@cenots7 tmp]# supervisorctl shutdown
Shut down
查看状态:
[iyunv@cenots7 tmp]# supervisorctl status
启动或停止某一个服务:
supervisorctl stop|start program_name
yum直接安装:
说明:
Docker 容器在启动的时候开启单个进程,比如,一个 ssh 或者 apache 的 daemon 服务。但我们经常需要在一个机器上开启多个服务,这可以有很多方法,最简单的就是把多个启动命令放到一个启动脚本里面,启动的时候直接启动这个脚本,另外就是安装进程管理工具
使用进程管理工具 supervisor 来管理容器中的多个进程。使用 Supervisor 可以更好的控制、管理、重启我们希望运行的进程
在这里我们演示一下容器中如何同时使用 ssh 和 tomcat 服务
配置:
首先创建Dockerfile文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[iyunv@cenots7 shencj]# vim Dockerfile
# centos:ssh
#
# VERSION 0.0.1
FROM centos
MAINTAINER shencj "732233048@qq.com"
#ssh
RUN yum install -y openssh openssh-server openssh-clients
RUN mkdir /var/run/sshd
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
RUN sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
RUN /bin/echo 'root:123456' |chpasswd
RUN /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g' /etc/pam.d/sshd
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" > /etc/default/local
#tomcat
ADD apache-tomcat-7.0.41.tar.gz /usr/local/src/
COPY jdk-7u80-linux-x64.rpm /usr/local/src/
WORKDIR /usr/local/src/
RUN rpm -ivh jdk-7u80-linux-x64.rpm
ENV JAVA_HOME /usr/java/jdk1.7.0_80
ENV PATH $PATH:$JAVA_HOME/bin
ENV CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#RUN java -version
RUN mkdir -p /usr/local/tools
RUN cp -r apache-tomcat-7.0.41 /usr/local/tools/tomcat7_8080
#supervisor
RUN rpm -Uvh https://mirrors.ustc.edu.cn/fedo ... ease-7-8.noarch.rpm
RUN yum update;yum -y install supervisor
RUN mkdir -p /etc/supervisor/
COPY supervisord.conf /etc/supervisor/
EXPOSE 22 8080
CMD supervisord -c /etc/supervisor/supervisord.conf
#CMD ["supervisord","-c","/etc/supervisor/supervisord.conf"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[iyunv@cenots7 shencj]# vim supervisord.conf
[unix_http_server]
file=/var/run/supervisor/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/var/run/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
[program:sshd]
command=/usr/sbin/sshd -D
[program:tomcat]
command=/usr/local/tools/tomcat7_8080/bin/catalina.sh run
注意:
serverurl=unix:///var/run/supervisor/supervisor.sock : 这个建议不要修改
nodaemon=true : 设置为true
command=/usr/local/tools/tomcat7_8080/bin/catalina.sh run :这个必须这样写(supervisor管理tomcat必须这样启动,其他方式好像都有问题),参考:http://serverfault.com/questions ... cat-with-supervisor
创建镜像:
[iyunv@cenots7 shencj]# docker build -t shencj/centos-ssh-tomcat:v1 .
运行容器:
1
2
3
[iyunv@cenots7 shencj]# docker run -d --name ssh-tomcat --restart=always -p 4426:22 -p 82:8080 shencj/centos-ssh-tomcat:v1
cc8006c07f6c703c476c69ecc3699f0c9a1e5f456949e65a8e92b55dafa8be1e
[iyunv@cenots7 shencj]#
查看容器:
1
2
3
[iyunv@cenots7 shencj]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc8006c07f6c shencj/centos-ssh-tomcat:v1 "/bin/sh -c 'supervis" 56 seconds ago Up 54 seconds 0.0.0.0:4426->22/tcp, 0.0.0.0:82->8080/tcp ssh-tomcat
登录容器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@cenots7 shencj]# ssh localhost -p 4426
root@localhost's password:
[iyunv@cc8006c07f6c ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 03:56 ? 00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
root 7 1 0 03:56 ? 00:00:00 /usr/sbin/sshd -D
root 8 1 3 03:56 ? 00:00:03 /usr/java/jdk1.7.0_80/bin/java -Djava.util.logging.config.file=/usr/local/tools/tomcat7_8080/conf/logging.properties -Djava.util.logging.manager=org.apa
root 30 7 0 03:58 ? 00:00:00 sshd: root@pts/0
root 32 30 0 03:58 pts/0 00:00:00 -bash
root 45 32 0 03:58 pts/0 00:00:00 ps -ef
[iyunv@cc8006c07f6c ~]# supervisorctl status
sshd RUNNING pid 7, uptime 0:02:58
tomcat RUNNING pid 8, uptime 0:02:58
访问tomcat:
http://ip:82
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com