常规应用服务配置

说明

· OS:Ubuntu 16.04
· Packages_DIR:/opt/services/
· Project_DIR:/opt/sites/
· User:op

Application

Nginx (v1.16)

· 安装相关依赖

sudo apt-get install -y libpcre3 libpcre3-dev openssl libssl-dev libxml2-dev

· 下载并解压源码包

wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar xvzf nginx-1.16.0.tar.gz

· 编译

./configure --prefix=/opt/services/nginx \
    --conf-path=/opt/services/nginx/config/nginx.conf \
    --error-log-path=/opt/services/nginx/logs/error.log \
    --pid-path=/opt/services/nginx/nginx.pid \
    --lock-path=/opt/services/nginx/nginx.lock \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_gzip_static_module \
    --with-http_sub_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_random_index_module \
    --with-http_v2_module

make && make install

· 修改 nginx 权限(添加 suid 权限,让普通用户调用 root)

sudo chown root /opt/services/nginx/sbin/nginx
sudo chmod u+s /opt/services/nginx/sbin/nginx

· 加入全局命令:

sudo ln -s /opt/services/nginx/sbin/nginx /usr/local/bin/

· 创建主机配置文件目录以及证书文件目录:

mkdir -p /opt/services/nginx/config/vhosts/ssl

· 修改配置文件

· 测试验证配置并启动:

nginx -t && nginx
MySQL(v5.7.24)

·安装依赖并配置相关目录:

sudo apt-get install -y build-essential cmake libncurses5-dev libpcre3 libpcre3-dev openssl libssl-dev libxml2-dev
sudo mkdir -p {/opt/services/mysql/mysql/tmp,/opt/services/mysql/mysqldata,/opt/services/mysql/mysql/etc,/opt/services/mysql/mysqllog/binlog,/opt/services/mysql/mysqllog/relay}
sudo chown -R op:op /opt
touch /opt/services/mysql/mysqllog/error.log
sudo mkdir /var/run/mysqld
sudo chown op:op /var/run/mysqld

· 下载并解压源码包:

wget https://dev.mysql.com/get/mysql-boost-5.7.24.tar.gz
tar xvzf mysql-boost-5.7.24.tar.gz

· 加入开机自启动:

sudo vim /etc/rc.local
    [ -d /var/run/mysqld ] || (mkdir /var/run/mysqld && chown op:op /var/run/mysqld)

· 编译安装:

    cmake -DCMAKE_INSTALL_PREFIX=/opt/services/mysql/mysql \
    -DMYSQL_DATADIR=/opt/services/mysql/mysqldata \
    -DSYSCONFDIR=/opt/services/mysql/mysql/etc \
    -DWITH_BOOST=boost \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
    -DMYSQL_TCP_PORT=4408 \
    -DENABLED_LOCAL_INFILE=1 \
    -DENABLE_DOWNLOADS=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DEXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_DEBUG=0 \
    -DMYSQL_MAINTAINER_MODE=0 \
    -DWITH_SSL:STRING=bundled \
    -DWITH_ZLIB:STRING=bundled

    make && make install

· 编辑 my.cnf 文件:

vim /opt/services/mysql/mysql/etc/my.cnf

[mysqld]
user=op
port=4408
server-id=1
relay-log = mysql-relay-bin
log-bin=/opt/services/mysql/mysqllog/binlog/binlog
binlog-format = ROW
max_binlog_size = 200M
expire_logs_days = 7
 
relay-log = /opt/services/mysql/mysqllog/relay/relay-bin
relay-log-index = /opt/services/mysql/mysqllog/relay/relay-bin.index
 
gtid_mode=ON
log-slave-updates=ON
enforce-gtid-consistency=ON
 
slave-parallel-type = LOGICAL_CLOCK
slave_parallel_workers = 16
master_info_repository = TABLE
relay_log_info_repository = TABLE
relay_log_recovery = ON
 
slow-query-log=1
long_query_time=1
innodb_buffer_pool_dump_now = on
innodb_buffer_pool_load_now = on
innodb_buffer_pool_dump_at_shutdown = on
innodb_buffer_pool_load_at_startup = on
 
pid-file=/var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
#wait_timeout = 180
#interactive_timeout = 28800
wait_timeout = 31536000
interactive_timeout = 31536000
max_connections = 10000
max_allowed_packet = 1024M
max_user_connections = 13000
innodb_thread_concurrency = 24
innodb_buffer_pool_size = 1024M
innodb_log_buffer_size = 20M
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_log_files_in_group = 3
sync_binlog = 0
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
query_cache_type = 1
query_cache_size = 128M
#query_cache_size = 1G
query_cache_limit = 2M
query_cache_min_res_unit = 1336
key_buffer_size = 256M
read_buffer_size = 64M
read_rnd_buffer_size = 32M
sort_buffer_size = 16M
max_tmp_tables = 256M
tmp_table_size = 256M
#table_open_cache = 10000
table_open_cache = 4096
thread_cache_size = 30
max_heap_table_size = 128M
query_cache_min_res_unit = 1336
 
general_log = OFF
general_log_file = /opt/services/mysql/mysqllog/access.log
log-error = /opt/services/mysql/mysqllog/error.log
slow-query-log-file = /opt/services/mysql/mysqllog/slow.log
 
#sql_mode = ''
sql-mode=NO_AUTO_VALUE_ON_ZERO
character-set-server=utf8mb4
#collation-server=utf8_bin
default-storage-engine=INNODB
innodb_log_file_size=2GB
innodb-file-format=Barracuda
innodb-default-row-format=DYNAMIC
transaction-isolation=READ-COMMITTED
innodb-large-prefix=ON

· 初始化数据:

/opt/services/mysql/mysql/bin/mysqld --initialize-insecure --user=op --basedir=/opt/services/mysql/mysql --datadir=/opt/services/mysql/mysqldata

· 编辑启动脚本

sudo cp /opt/services/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
sudo chmod +x /etc/init.d/mysqld
sudo vim /etc/init.d/mysqld(重点修改字段)
        basedir=/opt/services/mysql/mysql
        datadir=/opt/services/mysql/mysqldata
        mysqld_pid_file_path=/var/run/mysqld/mysqld.pid

sudo vim /etc/systemd/system/mysqld.service
        [Unit]
        Description=mysql-5.7.24
        After=syslog.target network.target remote-fs.target nss-lookup.target
 
        [Service]
        Type=forking
        ExecStart=/etc/init.d/mysqld start
        ExecStop=/etc/init.d/mysqld stop
        PrivateTmp=true
 
        [Install]
        WantedBy=multi-user.target

· 加入服务管理:

sudo systemctl enable mysqld.service

· 加入全局命令:

sudo ln -s /opt/services/mysql/mysql/bin/mysql /usr/local/bin/
sudo ln -s /opt/services/mysql/mysql/bin/mysqldump /usr/local/bin/

· 启停服务

sudo systemctl start mysqld.service
sudo systemctl stop mysqld.service
Redis(v.5.0.5)

· 下载并解压源码包

wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar xvzf redis-5.0.5.tar.gz

· 创建服务目录结构

mkdir -p /opt/services/redis/{bin,data,etc,logs}
make && make PREFIX=/opt/services/redis install

·加入全局命令:

sudo ln -s /opt/services/redis/bin/redis-server /usr/local/bin/
sudo ln -s /opt/services/redis/bin/redis-cli /usr/local/bin/

· 编辑配置文件:

vim /opt/services/redis/etc/redis.conf
(重点修改以下5个字段)

daemonize yes
pidfile /var/run/redis/redis_6379.pid
logfile /opt/services/redis/logs/redis.log
dir /opt/services/redis/data
appendonly yes

· 启停服务:

/opt/services/redis/bin/redis-server /opt/services/redis/etc/redis.conf
redis-cli shutdown
PHP(v7.1.30)

· 安装相关依赖:

sudo apt-get install -y autoconf  openssl libssl-dev libxml2-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev libreadline-dev libxslt1-dev libmemcached-dev 
sudo apt-get install -y libmagickwand-dev libmagickcore-dev

· 下载并解压源码包

wget https://www.php.net/distributions/php-7.1.30.tar.gz
tar xvzf php-7.1.30.tar.gz

· 编译安装

./configure  --prefix=/opt/services/php \
--with-config-file-path=/opt/services/php/etc \
--with-openssl \
--with-kerberos \
--with-xmlrpc \
--with-mysql-sock \
--with-mysqli \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-zlib \
--with-iconv \
--with-bz2 \
--with-curl \
--with-cdb \
--with-pcre-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-libmbfl \
--with-onig \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-readline \
--with-libxml-dir \
--with-xsl \
--with-pear \
--enable-fpm  \
--enable-cgi \
--enable-soap \
--enable-bcmath \
--enable-calendar \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-ftp \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--enable-pdo \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-zip \
--enable-mysqlnd-compression-support \
--enable-libxml \
--enable-inline-optimization \
--enable-opcache \
--enable-pcntl \
--enable-xml \
--enable-intl

make && make install

· 添加管理启动脚本:

sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo chmod +x /etc/init.d/php-fpm

· 加入全局命令:

sudo ln -s /opt/services/php/bin/php /usr/bin/

· 测试配置与启动服务:

cp /opt/services/php/etc/php-fpm.conf.default  /opt/services/php/etc/php-fpm.conf
cp  /opt/services/php/etc/php-fpm.d/www.conf.default   /opt/services/php/etc/php-fpm.d/www.conf
cp $解压目录/php.ini-production  /opt/services/php/etc/php.ini
/opt/services/php/sbin/php-fpm -y /opt/services/php/etc/php-fpm.conf -c /opt/services/php/etc/php.ini -t
/etc/init.d/php-fpm start{stop|restart}

· 安装扩展包

##从官网下载指定扩展包

##解压至php源码包下的ext目录

##进入解压目录并执行以下命令
/opt/services/php/bin/phpize #用phpize生成configure配置文件
./configure --with-php-config=/opt/services/php/bin/php-config #配置
make #编译
make install #安装,成功后产生Installing shared extensions

##加入扩展信息
vim /opt/services/php/etc/php.ini
extension="***.so"

· 可能出现的错误信息以及解决办法

1.configure: error: Cannot find OpenSSL’s libraries

sudo apt-get install openssl
sudo find / -name libssl.so -exec ln -sv {} /usr/lib/ \;

2.error: Please reinstall the BZip2 distribution.

sudo apt-get install libbz2-dev -y

3.error: cURL version 7.10.5 or later is required to compile php with cURL support

sudo apt-get remove curl -y
sudo apt-get install curl -y
sudo apt-get install libcurl4-openssl-dev -y
  1. error: jpeglib.h not found.
sudo apt-get install libjpeg-dev -y

5.error:png.h not found.

sudo apt-get install libpng-dev -y

6.error: freetype-config not found.

sudo apt-get -y install libfreetype6-dev

7.error: mcrypt.h not found. Please reinstall libmcrypt.

sudo apt-get -y install libmcrypt-dev

8.error: Please reinstall readline - I cannot find readline.h

sudo apt-get install libreadline-dev -y

9.error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

sudo apt-get install libxslt-dev -y
composer(v1.8.6)
php -r "copy('[https://install.phpcomposer.com/installer',](https://install.phpcomposer.com/installer',) 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/bin/composer

验证:`
composer -V`
nodejs(v10.15.3)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash &>/dev/null
source ~/.nvm/nvm.sh
nvm install 10.15.3
nvm alias default 10.15.3
  
## 验证:
    node -v
    npm -v

# 安装 cnpm:
    npm install cnpm -g --registry=https://r.npm.taobao.org
  
## 验证:
    cnpm -v
pm2
npm install -g pm2
pm2 start "进程名称"
pm2 save
pm2 restart/stop/delete "id"
pipenv
sudo apt install -y make build-essential git libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
 
vim ~/.bashrc
    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
 
source $HOME/.bashrc
  
## 安装 pipenv
pip/pip3 install pipenv
···
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容