服务部署安装

Summary: Author: 张亚飞 | 阅读时间: 6 minute read | Published: 2015-03-08
Filed under Categories: DevOpsTags: Linux, Server, Software, DevOps,

服务器集成环境安装…

#[挂载数据盘]

ssh 103.37.147.250 -l root

#[修改主机名]

/etc/hostname

ms

/etc/hosts

#172.16.27.224  coam.cloud.mos  coam
103.37.147.250  ms.cloud.mos    ms
reboot

#[配置用户]

  • 首先修改默认 root 密码
passwd
  • 添加用户…
mkdir -p /data/home/coam
adduser coam -home /data/home/coam
passwd coam
  • root 用户分配 sudo 权限

/etc/sudoers

# User privilege specification
root ALL=(ALL:ALL) ALL
coam ALL=(ALL) ALL

#[分配用户目录权限]

  • 重建用户权限
chown -R coam.coam /data/home/coam
chmod -R 755 /data/home/coam
  • 重建用户 SSH 登录权限
chown -R coam.coam /data/home/coam/.ssh
chmod -R 755 /data/home/coam/.ssh

#[配置 SSH 登录]

/etc/ssh/sshd_config

#!/usr/bin/env bash

#Port 22
Port 22312

#PermitRootLogin yes
PermitRootLogin no

#AuthorizedKeysFile     %h/.ssh/authorized_keys
AuthorizedKeysFile     %h/.ssh/authorized_keys

AddressFamily inet
#SyslogFacility AUTHPRIV
#PasswordAuthentication yes
reboot
ssh 103.37.147.250 -l coam -p22312

#[配置镜像源]

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

# 预发布软件源,不建议启用
#deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

# mainline
#deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
#deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx
# nginx 官方源 stable
deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx

更新源后提示错误:

W: GPG error: http://nginx.org/packages/mainline/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62

执行如下代码:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv ABF5BD827BD9BF62
sudo apt update

#[安装 Nginx]

  1. 添加官方源
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
  1. 添加 sudo vi /etc/apt/sources.list 镜像源地址

/etc/apt/sources.list

# mainline
#deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
#deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx
# stable
deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx
  1. 更新源
sudo apt update
  1. 获取 Nginx 源码并且安装系统依赖
# Install package creation tools
sudo apt install -y dpkg-dev

sudo mkdir /opt/data/nginx
cd /opt/data/nginx

# Get Nginx (ppa:nginx/stable) source files
sudo apt source nginx

# Install the build dependencies
sudo apt build-dep nginx
  1. 安装 lua 依赖…
sudo apt install lua5.1
sudo apt install liblua5.1-dev

注意:暂且只能通过以上方式安装 lua5.1 版本…

  1. 获取 Nginx 模块插件…

/opt/data/ngx-m

git clone https://github.com/simpl/ngx_devel_kit.git
git clone https://github.com/openresty/lua-nginx-module.git
git clone https://github.com/openresty/echo-nginx-module.git
  • 2.获取扩展模快 [pagespeed]

/opt/data/ngx-m/pagespeed

cd /opt/data/ngx-m/pagespeed
sudo wget https://github.com/pagespeed/ngx_pagespeed/archive/latest-stable.tar.gz
sudo tar -zxvf latest-stable.tar.gz
cd ngx_pagespeed-latest-stable

/opt/data/ngx-m/pagespeed/ngx_pagespeed-latest-stable/

NPS_VERSION=1.11.33.4
sudo wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
sudo tar -xzvf ${NPS_VERSION}.tar.gz

/opt/data/nginx/nginx-1.11.5/debian/rules

config.status.nginx: config.env.nginx
        cd $(BUILDDIR_nginx) && \
        CFLAGS="" ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt="$(CFLAGS)" --with-ld-opt="$(LDFLAGS)" \
        --add-module=/opt/data/ngx-m/ngx_devel_kit --add-module=/opt/data/ngx-m/lua-nginx-module --add-module=/opt/data/ngx-m/echo-nginx-module --add-module=/opt/data/ngx-m/pagespeed/ngx_pagespeed-latest-stable
        touch $@
  • 开始编译安装 Nginx

/opt/data/nginx/nginx-1.12.0

sudo dpkg-buildpackage -b -uc -us
cd /opt/data/nginx/
sudo dpkg --install nginx_1.12.0-1~xenial_amd59.deb

#[安装 LetsEncrypt]

LetsEncrypt 证书签发及使用问题

sudo pip install --upgrade pip
sudo pip install virtualenv
$ git clone https://github.com/letsencrypt/letsencrypt.git
$ cd letsencrypt
$ sudo ./letsencrypt-auto --help

#[安装 PHP]

首先确保已安装 python-software-properties 才能添加 PPA ,执行以下命令:

sudo apt update
sudo apt install software-properties-common
sudo apt install python-software-properties
sudo apt install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.1-fpm
sudo service php7.1-fpm restart

php -v
PHP 7.1.5-1+deb.sury.org~xenial+2 (cli) (built: May 22 2017 12:48:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5-1+deb.sury.org~xenial+2, Copyright (c) 1999-2017, by Zend Technologies
  • 安装扩展组件…
sudo apt install -y php7.1-common php7.1-cli php7.1-fpm php7.1-dev php7.1-mbstring php7.1-imagick php7.1-gd php7.1-curl php7.1-sqlite3 php7.1-json php7.1-tidy php7.1-mysql php7.1-intl php7.1-gmp
sudo apt install gcc libpcre3-dev
sudo git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/build
sudo ./install
sudo apt install pkg-config
sudo apt install php-pear
sudo pecl install mongodb
  • 安装 memcached 扩展
sudo apt install php7.1-memcached
  • 安装 redis 扩展

源码安装: phpredis/phpredis

sudo wget https://github.com/phpredis/phpredis/archive/3.1.2.tar.gz
tar zxvf 3.1.2.tar.gz
cd phpredis
sudo phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

sudo ./configure --with-php-config=/usr/bin/php-config
sudo make
sudo make install
wget http://pecl.php.net/get/zip-1.13.5.tgz
tar -zxvf zip-1.13.5.tgz
cd zip-1.13.5
phpize
./configure
make
sudo make install
  • 以上命令将会生成so文件 /usr/lib/php/20151012/zip.so

安装 Swoole 扩展

/opt/data

wget https://github.com/swoole/swoole-src/archive/v2.0.8.tar.gz
sudo tar -zxvf v2.0.8.tar.gz
cd swoole-src-*
sudo phpize
sudo ./configure --enable-async-redis
sudo make
sudo make install
  • 以上命令将会生成so文件 /usr/lib/php/20151012/swoole.so
Uncaught Error: Class 'swoole_redis' not found

编译时需要添加参数 –enable-async-redis

安装 Xhprof 扩展

/opt/data

git clone https://github.com/longxinH/xhprof.git ./xhprof
cd xhprof/extension/
sudo phpize
./configure --with-php-config=/usr/bin/php-config
make && sudo make install

#[安装 Mysql]

  • 安装编译源码需要的包
sudo apt install build-essential
sudo apt install make cmake gcc g++ bison libncurses5-dev
sudo apt install libssl-dev
  • 下载 boost 依赖…

/opt/data

wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
sudo tar -zxvf boost_1_59_0.tar.gz
sudo mkdir /usr/local/boost/
sudo cp -r boost_1_59_0 /usr/local/boost/
  • 源码编译安装 Mysql …
sudo wget https://github.com/mysql/mysql-server/archive/mysql-5.7.18.tar.gz
tar zxvf mysql-5.7.18.tar.gz
cd mysql-server-mysql-5.7.18/
mkdir build

/opt/data/mysql-server-mysql-5.7.18/build

sudo cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DMYSQL_DATADIR=/data/home/coam/data/mysql \
    -DSYSCONFDIR=/etc/mysql \
    -DMYSQL_TCP_PORT=3306 \
    -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
    -DINSTALL_LIBDIR=/usr/lib/mysql \
    -DINSTALL_PLUGINDIR=/usr/lib/mysql/plugin \
    -DWITH_SYSTEMD=1 \
    -DENABLE_DOWNLOADS=1 \
    -DWITH_EMBEDDED_SERVER=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_EXTRA_CHARSETS=complex \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
    -DDOWNLOAD_BOOST=1 \
    -DWITH_BOOST=/usr/local/boost/boost_1_59_0 \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DEXTRA_CHARSETS=all \
    -DWITH_SSL=system \
    -DWITH_READLINE=1 \
    -DENABLE_PROFILING=0
  • 最后编译安装…
sudo make
sudo make install

make install 后会自动创建如下目录文件

  • /usr/local/mysql

  • /usr/lib/mysql

  • /usr/lib/mysql/plugin

  • 添加 mysql 用户

groupadd mysql
useradd -r -g mysql mysql
  • 创建 MySQL 的数据及配置目录
cd /data/home/data
mkdir mysql
chown -R mysql.mysql mysql
mkdir /etc/mysql
mkdir /etc/mysql/conf.d
chown -R mysql.mysql /etc/mysql
mkdir /var/run/mysqld
chown mysql:mysql /var/run/mysqld
  • 添加MySQL服务
cp /usr/local/mysql/lib/systemd/system/mysqld.service /lib/systemd/system/
sudo systemctl start mysqld
  • 注意: cmake 添加编译参数 [-DWITH_SYSTEMD=1] 后已经不能使用原来的 [sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql] 方式管理启动 Mysql 了,否则报错:
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
sudo systemctl status mysql
May 27 10:26:19 ms mysql[23618]:  * Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

bin/mysqld_safe 在 5.7.xx 版本中已经被移除; 将 support-files/mysql.server 用作 init.d 下的脚本用于维护 mysql 服务的方式在已经支持 systemd 的系统中已经不合适了;

  • 以下才是正确姿势…
cp /usr/local/mysql/lib/systemd/system/mysqld.service /lib/systemd/system/
sudo systemctl status mysqld

#[安装 Redis]

源码编译安装 redis-server:

wget http://download.redis.io/releases/redis-stable.tar.gz
sudo tar -zxvf redis-stable.tar.gz
cd redis-stable
sudo make
sudo make install

后台启动 * 如果需要后台启动,则可以使用 redis 提供的 install_server.sh 脚本:

cd utils
sudo ./install_server.sh

#[安装 MongoDB]

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt update
sudo apt install -y mongodb-org

#[安装 MemCached]

sudo apt install memcached

#[安装 Ejabberd]

注意编译安装前修改的几个地方:

/ejabberd/rebar.config

{xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "1.1.11"}}}

/ejabberd/deps/cache_tab/src/ets_cache.erl

-module(ets_cache).
-compile(no_native).
-behaviour(gen_server).

通过调用 SsInstall.sh 的安装方法 SsInstallEjabberd 将会分别安装到以下相关目录:

配置文件 /etc/ejabberd/
Install ejabberd binary, header and runtime files in /lib/ejabberd/
Install the administration script: /sbin/ejabberdctl
ejabberd 帮助文档 /share/doc/ejabberd/
Create a spool directory: /var/lib/ejabberd/
日志文件: /var/log/ejabberd/
  • 17.04
Fri Jun 09 17:37:27 coam@as:~$ sudo find / -name ejabberd*
/usr/local/sbin/ejabberdctl # 启动文件
/usr/local/lib/ejabberd-0.0 # 程序文件
/usr/local/share/doc/ejabberd # 文档文件
/usr/local/var/log/ejabberd 日志文件
/usr/local/var/lib/ejabberd # 数据文件
/usr/local/etc/ejabberd #配置文件

其它扩展插件也都安装到 [/usr/local/lib/*] 下:

Fri Jun 09 17:42:13 coam@ms:/usr/local/lib$ ll
drwxr-xr-x  5 root root     4096 Jun  9 17:41 cache_tab-1.0.8/
drwxr-xr-x  5 root root     4096 Jun  9 17:41 ejabberd-0.0/
drwxr-xr-x  3 root root     4096 Jun  9 17:41 elixir-1.2.6/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 epam-1.0.2/
drwxr-xr-x  5 root root     4096 Jun  9 17:41 eredis-1.0.8/
drwxr-xr-x  5 root root     4096 Jun  9 17:41 esip-1.0.11/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 ezlib-1.0.2/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 fast_tls-1.0.12/
drwxr-xr-x  5 root root     4096 Jun  9 17:41 fast_xml-1.1.23/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 fast_yaml-1.0.10/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 goldrush-0.1.8/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 iconv-1.0.5/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 jiffy-0.14.8/
drwxr-xr-x  5 root root     4096 Jun  9 17:41 lager-3.2.1/
drwxr-xr-x  3 root root     4096 Jun  9 17:41 luerl-0.3/
drwxr-xr-x  3 root root     4096 Jun  9 17:41 meck-0.8.4/
drwxr-xr-x  3 root root     4096 Jun  9 17:41 moka-1.0.5c/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 p1_mysql-1.0.3/
drwxr-xr-x  3 root root     4096 Jun  9 17:41 p1_oauth2-0.6.1/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 p1_utils-1.0.9/
drwxr-xr-x  3 root root     4096 Jun  9 17:41 rebar_elixir_plugin-0.1.0/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 samerlib-0.8.0c/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 stringprep-1.0.9/
drwxr-xr-x  4 root root     4096 Jun  9 17:41 stun-1.0.10/
drwxr-xr-x  5 root root     4096 Jun  9 17:41 xmpp-1.1.11/
...
drwxr-xr-x  9 root root     4096 May 27 17:21 erlang/
...
lrwxrwxrwx  1 root root       18 Jun  4 22:10 libyaml-0.so.2 -> libyaml-0.so.2.0.5*
-rwxr-xr-x  1 root root   439416 Jun  4 22:10 libyaml-0.so.2.0.5*
-rw-r--r--  1 root root   770832 Jun  4 22:10 libyaml.a
-rwxr-xr-x  1 root root      947 Jun  4 22:10 libyaml.la*
lrwxrwxrwx  1 root root       18 Jun  4 22:10 libyaml.so -> libyaml-0.so.2.0.5*

#[安装 Emqttd]

#[其它系统必备软件]

  • Java
sudo apt install openjdk-8-jre
sudo apt install openjdk-8-jdk
  • ErlangOTP

/opt/data

sudo apt install g++ gcc make libncurses5-dev libssl-dev
wget http://erlang.org/download/otp_src_19.3.tar.gz
tar zxvf otp_src_19.3.tar.gz
./configure
sudo make -j4
sudo make install
  • Git
sudo apt install git

Comments

Cor-Ethan, the beverage → www.iirii.com