Rootop 服务器运维与web架构

2017-04-15
发表者 Venus
docker run 常用参数介绍已关闭评论

docker run 常用参数介绍

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

  -d, --detach=false         指定容器运行于前台还是后台,默认为false
  -i, --interactive=false    打开STDIN,用于控制台交互
  -t, --tty=false            分配tty设备,该可以支持终端登录,默认为false
  -u, --user=""              指定容器的用户
  -a, --attach=[]            登录容器(必须是以docker run -d启动的容器)
  -w, --workdir=""           指定容器的工作目录
  -c, --cpu-shares=0         设置容器CPU权重,在CPU共享场景使用
  -e, --env=[]               指定环境变量,容器中可以使用该环境变量
  -m, --memory=""            指定容器的内存上限
  -P, --publish-all=false    指定容器暴露的端口
  -p, --publish=[]           指定容器暴露的端口
  -h, --hostname=""          指定容器的主机名
  -v, --volume=[]            给容器挂载存储卷,挂载到容器的某个目录
  --volumes-from=[]          给容器挂载其他容器上的卷,挂载到容器的某个目录
  --cap-add=[]               添加权限,权限清单详见:http://linux.die.net/man/7/capabilities
  --cap-drop=[]              删除权限,权限清单详见:http://linux.die.net/man/7/capabilities
  --cidfile=""               运行容器后,在指定文件中写入容器PID值,一种典型的监控系统用法
  --cpuset=""                设置容器可以使用哪些CPU,此参数可以用来容器独占CPU
  --device=[]                添加主机设备给容器,相当于设备直通
  --dns=[]                   指定容器的dns服务器
  --dns-search=[]            指定容器的dns搜索域名,写入到容器的/etc/resolv.conf文件
  --entrypoint=""            覆盖image的入口点
  --env-file=[]              指定环境变量文件,文件格式为每行一个环境变量
  --expose=[]                指定容器暴露的端口,即修改镜像的暴露端口
  --link=[]                  指定容器间的关联,使用其他容器的IP、env等信息
  --lxc-conf=[]              指定容器的配置文件,只有在指定--exec-driver=lxc时使用
  --name=""                  指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字
  --net="bridge"             容器网络设置:
                                bridge 使用docker daemon指定的网桥
                                host    //容器使用主机的网络
                                container:NAME_or_ID  >//使用其他容器的网路,共享IP和PORT等网络资源
                                none 容器使用自己的网络(类似--net=bridge),但是不进行配置
  --privileged=false         指定容器是否为特权容器,特权容器拥有所有的capabilities
  --restart="no"             指定容器停止后的重启策略:
                                no:容器退出时不重启
                                on-failure:容器故障退出(返回值非零)时重启
                                always:容器退出时总是重启
  --rm=false                 指定容器停止后自动删除容器(不支持以docker run -d启动的容器)
  --sig-proxy=true           设置由代理接受并处理信号,但是SIGCHLD、SIGSTOP和SIGKILL不能被代理

2017-04-15
发表者 Venus
搭建docker私有仓库已关闭评论

搭建docker私有仓库

系统版本:CentOS Linux release 7.2.1511 (Core)

目的:基于docker创建一个registry容器,做为docker仓库给其它机器拉取镜像用

安装iptables 如果有iptables,就略过

[root@localhost ~]# yum install -y iptables iptables-utils iptables-services
[root@localhost ~]# systemctl start iptables
[root@localhost ~]# systemctl enable iptables

# 安装docker

[root@localhost ~]# yum install -y docker

# 启动

[root@localhost ~]# systemctl start docker

# 开机启动docker服务

[root@localhost ~]# systemctl enable docker

# 查询docker 私库镜像环境名称 找官方的

[root@localhost ~]# docker search registry
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/registry The Docker Registry 2.0 implementation for... 1426 [OK]

# 拉取私库镜像

[root@localhost ~]# docker pull docker.io/registry

# 查看本地镜像

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 136c8b16df20 6 days ago 33.17 MB

# 根据本地registry镜像启动一个容器,指定容器名,主机名,挂载卷

[root@localhost ~]# docker run -d --name=docker-repo -h docker-repo -p 5000:5000 -v /home/docker_repo:/var/lib/registry 136c8b16df20

registry私库默认监听在5000端口上

# 为了测试方便,从官方拉取一个 busybox 镜像(体积小)

[root@localhost ~]# docker pull busybox
Using default tag: latest
Trying to pull repository docker.io/library/busybox ...
latest: Pulling from docker.io/library/busybox
7520415ce762: Pull complete
Digest: sha256:32f093055929dbc23dec4d03e09dfe971f5973a9ca5cf059cbfb644c206aa83f

# 查看busybox镜像

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 136c8b16df20 7 days ago 33.17 MB
docker.io/busybox latest 00f017a8c2a6 5 weeks ago 1.11 MB

# 通过docker tag将 docker.io/busybox 镜像打一个标签,该镜像标志为要推送到私有仓库

[root@localhost ~]# docker tag docker.io/busybox 192.168.1.50:5000/busybox

# 注意命名 仓库地址+镜像名

[root@VM_33_244_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 136c8b16df20 7 days ago 33.17 MB
192.168.1.50:5000/busybox latest 00f017a8c2a6 5 weeks ago 1.11 MB
docker.io/busybox latest 00f017a8c2a6 5 weeks ago 1.11 MB

#然后把 docker.io/busybox push到私有仓库中

[root@localhost ~]# docker push 192.168.1.50:5000/busybox
The push refers to a repository [192.168.1.50:5000/busybox]
c0de73ac9968: Mounted from busybox_small
latest: digest: sha256:68effe31a4ae8312e47f54bec52d1fc925908009ce7e6f734e1b54a4169081c5 size: 527

浏览器访问:
http://192.168.1.50:5000/v2/_catalog

# 删除本地busybox镜像

[root@localhost ~]# docker rmi -f 00f017a8c2a6

# 从私有仓库拉取

[root@localhost ~]# docker pull 192.168.1.50:5000/busybox
Using default tag: latest
Trying to pull repository 192.168.1.50:5000/busybox ...
latest: Pulling from 192.168.1.50:5000/busybox
04176c8b224a: Pull complete
Digest: sha256:68effe31a4ae8312e47f54bec52d1fc925908009ce7e6f734e1b54a4169081c5
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 136c8b16df20 7 days ago 33.17 MB
192.168.1.50:5000/busybox latest 00f017a8c2a6 5 weeks ago 1.11 MB

# 注意事项
需要添加私有仓库信任 否则会报一个 http: server gave HTTP response to HTTPS client 错误
把 /etc/sysconfig/docker

OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
改为:
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry=192.168.1.50:5000'

重启docker生效

registry 私库默认用/bin/sh登陆
镜像默认保存在 /var/lib/registry/docker/registry/v2/repositories 中

直接删除 上面目录下的文件夹,就可以删除镜像。

docker的端口映射是通过iptables实现,如果重启iptables,容器端口映射失效,需要重启docker服务。

2017-04-06
发表者 Venus
mysql创建用户并赋数据库权限已关闭评论

mysql创建用户并赋数据库权限

# 创建用户 venus, 密码123,限制本地登陆

CREATE USER 'venus'@'localhost' IDENTIFIED BY '123';

# 授权 SELECT,INSERT,UPDATE 3个权限 给venus用户并绑定simon库

GRANT SELECT,INSERT,UPDATE ON `simon`.* TO 'venus'@'localhost';

# 刷新权限

FLUSH PRIVILEGES;

2017-04-05
发表者 Venus
Your container doesn’t use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc, this will cause problems. See Containers and Tomcat i18n for more details.已关闭评论

Your container doesn’t use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc, this will cause problems. See Containers and Tomcat i18n for more details.

设置tomcat编码

编辑server.xml,添加一行
URIEncoding=”UTF-8″

 <Connector port="8080" protocol="HTTP/1.1"
 connectionTimeout="20000"
 redirectPort="8443" URIEncoding="UTF-8" />

重启tomcat

2017-04-01
发表者 Venus
去掉nexus访问时带nexus路径已关闭评论

去掉nexus访问时带nexus路径

[root@localhost ~]# vi /home/software/nexus/nexus-2.14.3-02/conf/nexus.properties

修改:
nexus-webapp-context-path=/nexus
为:
nexus-webapp-context-path=/

重启nexus服务。

nginx反向代理:

upstream nexus_server {
 server localhost:8083;
}

server {
 listen 80;
 server_name nexus.xxx.com;

 # individual nginx logs for this web vhost
 #access_log /var/log/nginx/crm-web/access.log;
 error_log /var/log/nginx/nexus.xxx.com_error.log;


 location / {
 proxy_pass http://nexus_server;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $http_host;
 }



}

这样访问nexus时访问http://nexus.xxx.com即可,不需要加http://nexus.xxx.com/nexus了