5 Star 10 Fork 5

K. / ubuntu-server-deploy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

#Ubuntu服务器常用组件安装包

  • 本安装包目前包含tengine、php、memcached、mcrouter的自动下载、自动编译、自动生成配置、自动部署的功能。
  • 本安装包基于Ubuntu Server 14.04 LTS,理论上ubuntu系应该都可以使用,centos就不包括了。
  • 本安装包提供一系列的变量允许用户进行重载,以定制自己的需要的发布环境,用户重载的定义,在项目根目录下添加user目录,并在该目录下添加任意.sh的文件即可(加载模式是ls ./user/.sh,暂时无排序顺序,以后会考虑加入)。
  • 系统启动的服务,通过sysv-rc-conf进行管理。

补充说明一下,我管理的服务器比较多,我的做法是,先获取这个项目的代码到服务器git clone https://git.oschina.net/janpoem/ubuntu-server-deploy.git,然后再通过svn checkout http://anyhost/php-server/ ./user,将某个服务器的配置文件从svn中导出。之后执行所需的安装命令即可。

一般来说,都不会在一台服务器上集中全部功能组件,一般会区分如:tengine_node_blancer、tengine_php_server、memcached_cluster、memcached_router等。这个安装包的作为开源项目,只提供了一个基础的环境,而具体的服务器配置,则保存在用户自己的版本库中(这个项目的user目录已经设置了忽略)。

##todo

###phase1

  • server,服务器环境初始化,已完成。
  • tengine,tengine编译、配置初始化,已完成。
    • 增加upstream的配置需求,未完成
  • php,php编译、配置初始化,主线部分已完成
    • 增加一个需求,ext的下载和自动编译,未完成
  • memcache,安装memcached、mcrouter(facebook/folly)部署,已完成。
  • 增加go部署,未完成

###phase2

  • 将各自的脚本,整合为一个文件:deploy,执行命令的情况:deploy php install、deploy tengine rebuild等。
  • 提供一个全自动安装的机制。
  • 可能需要换成高级语言实现,bash写得实在太痛苦了。

##server.sh

./tengine.sh init|prepare|timezone|upgrade|clean|dns

这个脚本主要执行apt-get upgrade和修正服务器的时区。

  • prepare|init,初始化服务器环境,除了upgrade和修正时区以外,还会安装必须的packages,每次第一次初始化服务器环境的时候,都应该执行该操作
  • timezone,重复执行修正时区
  • upgrade,重复执行upgrade
  • clean,清除本地的修正时区和upgrade的记录
  • dns设置,Ubuntu的DNS设置是比较坑爹的事情,增加一个DNS写入的方法,该方法主要通过修改/etc/resolvconf/resolv.conf.d/head文件实现,会根据用户定义的DNS变量,注释掉该文件中正在使用的nameserver,并追加新的DNS。

用户可修改变量

#!/usr/bin/env bash
# file: user/dns.sh
# oneDNS
DNS[1]=112.124.47.27
DNS[2]=114.215.126.16

# 时区
TIMEZONE=Asia/Shanghai

# 有需要追加的安装包,请使用这个变量,但最好使用+=的方式追加。
SERVER_REQUIRE_PKGS+="...需要增加的包..."

##tengine.sh

可用的命令

./tengine.sh install|rebuild|conf|conf-all|conf-main|conf-deny|conf-common|conf-php|script|sh|test|ensite|enphpsite
  • install,编译安装tengine,如果tengine已经存在则会退出
  • rebuild,强制重新编译安装tengine,如果tengine存在,会强制覆盖(包括配置文件)
  • conf|conf-all,初始化tengine的配置文件、必须的目录,如果指定的配置文件存在,会直接删除。该操作不包含php的tengine配置
  • conf-main,初始化或重新初始化tengine的主配置文件,必须的目录等。
  • conf-deny,初始化或重新初始化deny_settings的配置文件
  • conf-common,初始化或重新初始化tengine/common的配置信息
  • conf-php,初始化或重新初始化php的tengine设置,./tengine.sh conf-php 127.0.0.1:8832 php53_settings
    • 第1个参数为fcgipass的句柄,
    • 第2个参数为将要保存的配置文件名,这个参数提供多个php版本环境共存的配置可能性。
  • script|sh,初始化或重新初始化/etc/init.d/tengine的服务启动脚本
  • test,测试当前配置环境是否生效
  • ensite,添加一个站点,./tengine.sh ensite default 80 default
    • 第1个参数为要创建的站点名称,他会根据这个名称生成配置文件,如default.conf,在未指定第3个参数,站点的目录时,他也会默认使用站点名称作为站点目录的名称。
    • 第2个参数为添加的站点的网站端口号。
    • 第3个参数为站点要创建的目录名,如果不指定,则默认使用第1个参数
  • enphpsite,添加一个支持PHP的站点,./tengine.sh enphpsite default 80 default,参数如ensite,注意,该命令会出发自动执行conf-php的命令。所以如果要确保php环境的正确性,请先提前手动执行./tengine.sh conf-php

上述的所谓重新初始化,是指,修改了配置,并按照最新的配置覆盖到指定的配置文件。

用户可修改变量

# 所需要的包的版本号……这个最好和要下载的包名称保持一致,这里需要调整一下
TENGINE_NAME=tengine-2.1.0
PCRE_NAME=pcre-8.36
ZLIB_NAME=zlib-1.2.8
OPENSSL_NAME=openssl-1.0.2a
# www_user和www_group,这个配置也对应到php编译使用
WWW_USER=www-data
WWW_GROUP=www-data
# tengine的目录,呃,这个不用怎么修改
TENGINE_CONF_DIR=/etc/tengine
# tengine pidfile 这个也不用改了吧
TENGINE_PID_FILE=/var/run/tengine.pid
# ...不说了
TENGINE_LOG_DIR=/var/log/tengine
TENGINE_TMP_DIR=/var/tmp/tengine
# ...不说了
TENGINE_TMP_CLIENT=${TENGINE_TMP_DIR}/client_body
TENGINE_TMP_PROXY=${TENGINE_TMP_DIR}/proxy
TENGINE_TMP_FCGI=${TENGINE_TMP_DIR}/fcgi
TENGINE_TMP_UWSGI=${TENGINE_TMP_DIR}/uwsgi
TENGINE_TMP_SCGI=${TENGINE_TMP_DIR}/scgi
# tengine config配置变量
TENGINE_WORK_PROS=8
TENGINE_RLIMIT=102400
TENGINE_WORKER_CONNS=102400
TENGINE_DEFAULT_MIME_TYPE=text/html
TENGINE_DEFAULT_CHARSET=text/html
TENGINE_VHOST_LOG_DIR=/var/log/vhost
TENGINE_VHOST_CONF_DIR=${TENGINE_CONF_DIR}/vhost
# www的根目录
TENGINE_WWW_HOME=/var/www

##mc.sh

memcached和mcrouter相关的安装和配置。

mcrouter,facebook团队荣誉出品,安装过程十分费劲,所以也打包在这个脚本里面了。

Mcrouter is a memcached protocol router for scaling memcached (http://memcached.org/) deployments. It's a core component of cache infrastructure at Facebook and Instagram where mcrouter handles almost 5 billion requests per second at peak.

可用的命令

./mc.sh install|conf|mcr-install|mcr-build|mcr-fb-build|mcr-conf|mcr-script|mcr-sh
  • install,安装memcached
  • conf,初始化或重新覆盖memcached的配置文件。要构造用户自定义的conf,可在user.sh中定义所需的变量(其它的配置也适用)。
  • mcr-install,安装mcrouter,其中包括编译安装double-conversion、facebook/folly,并初始化mcrouter的配置文件和服务脚本。
  • mcr-conf,生成mcrouter的配置文件,可重复执行重复生成。因为配置文件是json格式,比较奇葩,参考下面的user.sh的MCR_POOL_SERVERS
  • mcr-script|mcr-sh,生成mcrouter的服务脚本,可重复执行重复生成。
  • mcr-build,和mcr-install一样,如果要强制重新安装,需要加个任意的参数,如:./mc.sh mcr-build 1
  • mcr-fb-build,采用facebook的安装方式进行安装,facebook的安装,会需要下载gtest的项目的代码进行测试,不过国内无法正常的下载,所以使用facebook的安装方式,确保你能有效的下载到gtest。

如果你的服务器已经安装过facebook/folly,再执行mcr-install的时候,安装过程无异常,但是安装完毕,当你执行mcrouter --help,有可能会报出如下的错误:

mcrouter: error while loading shared libraries: libfolly.so.35: cannot open shared object file: No such file or directory

不管你如何重新编译安装folly,都无法解决,目前可行的方案是用facebook提供的方式进行安装,不过他会将你的gcc和g++用4.8替换掉。

如果你是全新的服务器安装,执行mcr-install都不会有这个异常出现,如果你已经自己手动编译安装过folly,则可能会出现上述的问题。发生这个问题的时候,请使用mcr-fb-build。

并且,mcr-fb-build和mcr-install安装的目标目录是不同的。

这个问题已经提交到mcrouter的issues了。https://github.com/facebook/mcrouter/issues/39

用户可修改变量

# memcached的配置
MC_HOST=127.0.0.1
MC_PORT=11211
MC_LOG_FILE=/var/log/memcached.log
MC_USER=memcache
MC_SIZE=64
# mcrouter配置
MCR_PORT=5000
MCR_CONF_FILE=/etc/mcrouter.json
MCR_LOG_FILE=/var/log/mcrouter.log
MCR_PID_FILE=/var/run/mcrouter.pid
# mcrouter pooled servers配置,这里当时没想清楚,所以实现的好,以后会改成数组的模式
MCR_POOL_SERVERS="\"${MC_HOST}:${MC_PORT}\",\"other_ip:other_port\""

###/etc/init.d/mcrouter使用说明

执行./mc.sh mcr-sh,会生成一个服务启动的脚本/etc/init.d/mcrouter,这个脚本用于日常启动、重启、停止mcrouter服务使用。

service mcrouter start|stop|restart|status|proc
  • start,启动服务
  • stop,停止服务
  • restart,重启服务
  • status,查看服务是否在运行
  • proc,输出在运行的mcrouter的进程实例列表

调试

如上所述,因为folly的这个问题,所以适当的调试是必要的。如果当你执行service mcrouter start,看到他输出了ok,并且在PIDFILE也看到了进程id,但实际上当你执行service mcrouter statusservice mcrouter proc时,却没有在运行的状态,这时多半是启动过程发生了异常。

这时你可以尝试直接执行:mcrouter --help来看看是不是有什么异常,如果help输出正常,那么就需要对/etc/init.d/mcrouter进行一些小修改:

# 上面省略....
# 在这一行开始
. /lib/lsb/init-functions

${DAEMON} ${DAEMON_ARGS}

exit 1

# 下面省略....

然后执行/etc/init.d/mcrouter来直接启动服务,你可能会看到一些其它的异常,比如他会提示你,端口被占用什么的。

当调试完毕服务已经可以正常启动了,再执行mc.sh mcr-sh,会重新生成这个服务启动脚本,并覆盖你修改的内容。

##php.sh

./php.sh install|rebuild|fpm-conf|fpm-sh|ini|bin
  • install,基本安装,如果安装目标已经存在,则会跳过编译过程。
  • rebuild,强制重新安装
  • fpm-conf,生成php-fpm的配置,配置文件存放在/php编译目录/etc/php-fpm.conf,而非/etc/php-fpm.conf
  • fpm-sh,生成php-fpm的服务脚本
  • ini,生成php.ini文件,/php编译目录/lib/php.ini
  • bin,生成相关的phpbin文件,包括php、php-fpm、phpize、php-pecl、php-pear。

用户可修改变量

以下只列出推荐用户修改的

# PHP源代码下载的目录,可以留空,会以ubuntu-server-deploy/temp作为下载目录
PHP_TEMP_DIR=
# 所需要的PHP版本,注意,目前这个编译,测试过php5.5和php5.6,其它的版本要实际测试
PHP_VER=5.5.23
# php的下载连接,注意,这里可选的有:${PHP_HK_SOURCE}、${PHP_CN_SOURCE}、${PHP_US_SOURCE}
PHP_SOURCE=${PHP_HK_SOURCE}
# php可执行命令的前缀,提供这个变量,主要为了能让系统同时存在多个php的版本,比如有些开源代码只支持php5.3...
PHP_BIN_PREFIX=php
# 需要追加apt-get的包名称,如果要多行,请用双引号包起来
PHP_REQ_PKGS=
# php编译的命令,如果不是必要,最好不要直接修改这个命令,而是使用+=的方式追加,如下:
PHP_CONF_CMD+="...追加的编译配置..."

# php日志、pid文件
PHP_FPM_LOG_DIR=/var/log/${PHP_BIN_PREFIX}-fpm
PHP_FPM_PID_FILE=/var/run/${PHP_BIN_PREFIX}-fpm.pid
PHP_FPM_ERR_FILE=${PHP_FPM_LOG_DIR}/error.log
PHP_FPM_LOG_LEVEL=warning

# FPM最大进程数、超时时间、RLIMIT
PHP_FPM_PROCESS_MAX=10
PHP_FPM_PROCESS_TIMEOUT=30
PHP_FPM_RLIMIT=65535

# FPM listen,你可以修改为unix:....
PHP_FPM_LISTEN="127.0.0.1:9902"
# listen mode
PHP_FPM_LISTEN_MODE=0666
# FPM PM设定
PHP_FPM_PM_MODE=static
PHP_FPM_PM_START=10
PHP_FPM_PM_MAX_CHILDREN=10
PHP_FPM_PM_MAX_REQUESTS=0

# php.ini设置相关
PHP_INI_MAX_EXECUTION_TIME=60
PHP_INI_MAX_INPUT_TIME=60
PHP_INI_DEFAULT_CHARSET=UTF-8
PHP_INI_POST_MAX_SIZE=10M
PHP_INI_UPLOAD_MAX_SIZE=10M

##user.sh示例

#!/usr/bin/env bash

MC_HOST=192.168.55.122
MC_PORT=11212
MC_LOG_FILE=/var/log/memcached.log
MC_USER=memcache
MC_SIZE=64

MCR_POOL_SERVERS="\"${MC_HOST}:${MC_PORT}\""

##ubuntu的中国源

如果你需要使用中国的apt-get更新源,请使用sohu源,已知163源在一些包的版本上有错误,谨慎谨慎。

sohu源

deb http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2015 曾建凯 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Ubuntu服务安装包,针对Ubuntu Server 14.04 LTS。现已支持 16.04 LTS。 展开 收起
Shell 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Shell
1
https://gitee.com/janpoem/ubuntu-server-deploy.git
git@gitee.com:janpoem/ubuntu-server-deploy.git
janpoem
ubuntu-server-deploy
ubuntu-server-deploy
master

搜索帮助