CentOS7.4 源码编译安装LNMP环境

字数 205阅读 18

PHP7.2.16 NGINX 1.15.6 MYSQL 5.7.24

执行脚本

#!/bin/bash
#安装PHP依赖
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers  libxslt libxslt-devel libzip vim
cd /usr/local/src
#下载php安装包
wget http://cn2.php.net/distributions/php-7.2.16.tar.gz
tar -zxf php-7.2.16.tar.gz
cd php-7.2.16
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install
#php-fpm的文件
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf


# 添加php环境变量(CentOS7.4 的环境下)
# vim ~/.bashrc  最后添加两行 PATH=$PATH:/usr/local/php56/bin export PATH 然后保存退出  source /etc/bashrc


### NGXIN
###### 安装nginx依赖
yum install -y wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
#下载nginx安装包
wget http://nginx.org/download/nginx-1.15.6.tar.gz
tar -zxf nginx-1.15.6.tar.gz
cd nginx-1.15.6
#创建nginx所属角色分组且不允许登陆
groupadd www
useradd -g www www -M -s /sbin/nologin
#运行 ./configure  --prefix=/usr/local/nginx  检测程序文件;如果是手动安装可以先执行然后查看缺少的环境
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
make && make install

#开机自启nginx ./nginx (文件 在下方)
cp ./nginx /lib/systemd/system/nginx.service
systemcel enable nginx.service


#安装mysql的环境依赖包
yum -y install gcc-devel gcc-c++-devel autoconf* automake* zlib* libxmlncurses-devel ncurses libgcrypt libtool* cmake openssl openssl-devel bisonbison-devel perl-Data-Dumper boost boost-doc boost-devel
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
tar -zxf  mysql-boost-5.7.24.tar.gz
cd mysql-5.7.24
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
mkdir -pv /opt/mysql/conf
chown -R mysql:mysql /opt/mysql
mkdir -pv /data/mysql
chown -R mysql:mysql /data/mysql
rm -rf /etc/my.cnf

cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/opt/mysql/conf -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DSYSTEMD_PID_DIR=/opt/mysql -DMYSQL_USER=mysql -DWITH_SYSTEMD=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -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 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost
make -j$(cat /proc/cpuinfo| grep "processor"| wc -l) && make install
cp ./scripts/mysqld.service /usr/lib/systemd/system
systemctl enable mysqld.service
cat > /etc/profile.d/mysql.sh << EOF
PATH=/opt/mysql/bin:$PATH
export PATH
EOF
source /etc/profile
#初始化数据
/opt/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/data/mysql

nginx文件

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

nginx 文件说明

Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

Mysql相关说明

mysql安装执行完毕后,需要
mysql_secure_installation 执行一系列相关操作设置密码
然后登陆 mysql -uroot -pxxxx
具体可以看 我的另一篇文章