常規(guī)應(yīng)用服務(wù)配置

說明

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

Application

Nginx (v1.16)

· 安裝相關(guān)依賴

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 權(quán)限(添加 suid 權(quán)限让蕾,讓普通用戶調(diào)用 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/

· 創(chuàng)建主機(jī)配置文件目錄以及證書文件目錄:

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

· 修改配置文件

· 測(cè)試驗(yàn)證配置并啟動(dòng):

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

·安裝依賴并配置相關(guān)目錄:

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

· 加入開機(jī)自啟動(dòng):

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

· 初始化數(shù)據(jù):

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

· 編輯啟動(dòng)腳本

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(重點(diǎn)修改字段)
        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

· 加入服務(wù)管理:

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/

· 啟停服務(wù)

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

· 創(chuàng)建服務(wù)目錄結(jié)構(gòu)

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
(重點(diǎn)修改以下5個(gè)字段)

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

· 啟停服務(wù):

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

· 安裝相關(guān)依賴:

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

· 添加管理啟動(dòng)腳本:

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/

· 測(cè)試配置與啟動(dòng)服務(wù):

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}

· 安裝擴(kuò)展包

##從官網(wǎng)下載指定擴(kuò)展包

##解壓至php源碼包下的ext目錄

##進(jìn)入解壓目錄并執(zhí)行以下命令
/opt/services/php/bin/phpize #用phpize生成configure配置文件
./configure --with-php-config=/opt/services/php/bin/php-config #配置
make #編譯
make install #安裝,成功后產(chǎn)生Installing shared extensions

##加入擴(kuò)展信息
vim /opt/services/php/etc/php.ini
extension="***.so"

· 可能出現(xiàn)的錯(cuò)誤信息以及解決辦法

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

驗(yàn)證:`
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
  
## 驗(yàn)證:
    node -v
    npm -v

# 安裝 cnpm:
    npm install cnpm -g --registry=https://r.npm.taobao.org
  
## 驗(yàn)證:
    cnpm -v
pm2
npm install -g pm2
pm2 start "進(jìn)程名稱"
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
···
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末或听,一起剝皮案震驚了整個(gè)濱河市探孝,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌誉裆,老刑警劉巖顿颅,帶你破解...
    沈念sama閱讀 211,561評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異足丢,居然都是意外死亡粱腻,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,218評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門斩跌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來绍些,“玉大人,你說我怎么就攤上這事耀鸦〖砼” “怎么了?”我有些...
    開封第一講書人閱讀 157,162評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵揭糕,是天一觀的道長(zhǎng)萝快。 經(jīng)常有香客問我,道長(zhǎng)著角,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,470評(píng)論 1 283
  • 正文 為了忘掉前任旋恼,我火速辦了婚禮吏口,結(jié)果婚禮上奄容,老公的妹妹穿的比我還像新娘。我一直安慰自己产徊,他們只是感情好昂勒,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,550評(píng)論 6 385
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著舟铜,像睡著了一般戈盈。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上谆刨,一...
    開封第一講書人閱讀 49,806評(píng)論 1 290
  • 那天塘娶,我揣著相機(jī)與錄音,去河邊找鬼痊夭。 笑死刁岸,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的她我。 我是一名探鬼主播虹曙,決...
    沈念sama閱讀 38,951評(píng)論 3 407
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼番舆!你這毒婦竟也來了酝碳?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,712評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤恨狈,失蹤者是張志新(化名)和其女友劉穎疏哗,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體拴事,經(jīng)...
    沈念sama閱讀 44,166評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡沃斤,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,510評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了刃宵。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片衡瓶。...
    茶點(diǎn)故事閱讀 38,643評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖牲证,靈堂內(nèi)的尸體忽然破棺而出哮针,到底是詐尸還是另有隱情,我是刑警寧澤坦袍,帶...
    沈念sama閱讀 34,306評(píng)論 4 330
  • 正文 年R本政府宣布十厢,位于F島的核電站,受9級(jí)特大地震影響捂齐,放射性物質(zhì)發(fā)生泄漏蛮放。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,930評(píng)論 3 313
  • 文/蒙蒙 一奠宜、第九天 我趴在偏房一處隱蔽的房頂上張望包颁。 院中可真熱鬧瞻想,春花似錦、人聲如沸娩嚼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,745評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽岳悟。三九已至佃迄,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間贵少,已是汗流浹背呵俏。 一陣腳步聲響...
    開封第一講書人閱讀 31,983評(píng)論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留春瞬,地道東北人柴信。 一個(gè)月前我還...
    沈念sama閱讀 46,351評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像宽气,于是被迫代替她去往敵國和親随常。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,509評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容