說明
· 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
- 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
···