2022-10-27 15:40:12
浏览数 (1)
编译安装 Nginx
代码语言:javascript
复制# 创建用户和组
groupadd nginx
useradd -s /sbin/nologin nginx
# 编译安装
./configure --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_sub_module --with-http_stub_status_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-http_auth_request_module
make && make install
chown -R nginx.nginx /usr/local/nginx/
# 添加启动脚本
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
# 启动
systemctl daemon-reload
systemctl start nginx
编译安装 MySQL
代码语言:javascript
复制# 创建用户和组
groupadd mysql
useradd -r -g mysql mysql
# 创建数据目录并授权
mkdir /data/mysql
chown -R mysql.mysql /data/mysql/
# 编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
# 初始化
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --datadir=/data/mysql --basedir=/usr/local/mysql
cp support-files/my-large.conf /etc/my.cnf
mysql_secure_installation
# 添加启动脚本
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld
TimeoutSec=600
Restart=always
PrivateTmp=false
# 启动
systemctl daemon-reload
systemctl start mysqld
编译安装 PHP
代码语言:javascript
复制# 安装依赖
yum install zlib zlib-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg* libpng* freetype freetype-devel libzip libzip-devel libmcrypt libmcrypt-devel mhash mhash-devel
# 编译安装
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir=/usr --with-gd --enable-sysvshm --with-iconv --with-zlib --with-zlib-dir --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-jpeg-dir --with-png-dir --with-curl --with-jpeg-dir --with-freetype-dir --with-mhash --with-mcrypt --with-bz2 --with-pdo-mysql=/usr/local/mysql/ --enable-fastcgi
make && make install
# 复制配置文件
cp /usr/local/src/php-5.6.31/php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/src/php-5.6.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
chmod x /etc/init.d/php-fpm
chkconfig php-fpm on
# 设置用户和组
vim /usr/local/php/etc/php-fpm.d/www.conf
user = nginx
group = nginx
vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid
# 添加启动脚本
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 启动
systemctl daemon-reload
systemctl start php-fpm