CentOS 7.6编译安装LNMP

一、前期准备
1.服务器以最小化方式安装CentOS 7.6
2.配置本地源及安装epel源
#cd /etc/yum.repos.d
#vi CentOS-Base.repo
增加enable=1
#yum install wget
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#yum makecache
#yum install epel-release
#yum repolist
3.#yum install gcc gcc-c++ cmake
4.#yum install kernel kernel-devel,再重启服务器。 //升级内核
5.#yum update //系统升级。
注:#yum remove NetworkManager
#systemctl stop NetworkManager
#systemctl disable NetworkManager
6.编译安装cmake-3.10.2,//请参考https://blog.51cto.com/191226139/2066186
7.安装ntpd时间服务器
8.Yum remove packages…
httpd httpd-tools mysql mysql-libs php-mysql php-cli php-gd php-common php
特别执行#yum remove mysql-libs //将删除crontabs,后面再安装crontabs,记得开启crond服务
9.Yum installing dependent packages…
flex bison file libtool libtool-ltdl autoconf patch wget crontabs libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libzip libzip-devel libevent libevent-devel ncurses ncurses-devel curl libcurl-devel libcurl e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel gmp-devel pspell-devel libcap diffutils ca-certificates net-tools libc-client libc-client-devel psmisc libXpm-devel git c-ares-devel libicu libicu-devel libxslt libxslt-devel xz expat expat-devel libaio libaio-devel rpcgen libtirpc-devel perl bison bison-devel libcurl-devel libcurl libarchive-devel boost boost-devel lsof pcre pcre-devel libmcrypt libmcrypt-devel libvpx mhash t1lib
二 编译安装LNMP
(一)编译安装Mariadb
1.安装依赖包
#yum install ncurses-devel libaio-devel openssl-devel -y
#cmake --version
cmake version 3.10.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
2.创建用于mysql的组和账号
#groupadd -r mysql
#useradd -r -g mysql -s /sbin/nologin -M mysql
#id mysql
uid=998(mysql) gid=996(mysql) groups=996(mysql)
3.编译安装mariadb
#cd /data/lnmpsoft
#ls
mariadb-10.2.19.tar.gz
#tar -zxvf mariadb-10.2.19.tar.gz -C /usr/local/src
#mkdir /usr/local/src/db-build
#mkdir /usr/local/mariadb-10.2.19
#chown root:root /usr/local/mariadb-10.2.19
#mkdir /var/run/mysql
#chown mysql:mysql /var/run/mysql
#cd /usr/local/src/db-build
#cmake /usr/local/src/mariadb-10.2.19
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-10.2.19 \ -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DMYSQL_USER=mysql
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
-DENABLED_LOCAL_INFILE=1
-DENABLE_DOWNLOADS=1
-DEXTRA_CHARSETS=all
-DSYSCONFDIR=/etc
-DWITHOUT_TOKUDB=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MRG_MyISAM_STORAGE_ENGINE=1
-DWITH_CSV_STORAGE_ENGINE=1
-DWITH_SEQUENCE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_ARIA_STORAGE_ENGINE=1
-DWITH_PERFORMANCE_SCHEMA_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LOBWRAP=0
-DMYSQL_MAINTAINER_MODE=0
-DWITH_DEBUG=0
此处为编译mariadb,可在mysql-bianyi中复制。
#make && make install
#ln -s /usr/local/mariadb-10.2.19 /usr/local/mysql
4.添加PATH至环境变量中
#echo ‘PATH=/usr/local/mysql/bin:$PATH ’ >> /etc/profile.d/mysql.sh
检查文件
#cat /etc/profile.d/mysql.sh
加载环境变量文件并检查
#source /etc/profile.d/mysql.sh
#echo $PATH
检查mysql版本
#mysql -V
mysql Ver 15.1 Distrib 10.2.19-MariaDB, for Linux (x86_64) using readline 5.1
5.创建数据库存放文件夹并修改权限
#mkdir -pv /data/mysqldb/3306/{log,data,pid,tmp}
#chown -R mysql:mysql /data/mysqldb/
#chmod -R 770 /data/mysqldb/
6.复制及修改配置文件my.cnf
#cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
#vim /etc/my.cnf
[mysqld]
port = 3306
socket = /var/run/mysql/mysql.sock
pid-file = /data/mysqldb/3306/pid/mysql.pid
datadir = /data/mysqldb/3306/data
tmpdir = /data/mysqldb/3306/tmp
innodb_file_per_table = 1
skip_name_resolve = 1
log-error = /data/mysqldb/3306/log/error.log
7.安装数据库相关文件
#cd /usr/local/mysql/
查看下安装程序的安装参数
#/usr/local/mysql/scripts/mysql_install_db --help

#./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb-10.2.19 --datadir=/data/mysqldb/3306/data
[Warning] ‘THREAD_CONCURRENCY’ is deprecated and will be removed in a future release.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

‘/usr/local/mariadb-10.2.19/bin/mysqladmin’ -u root password ‘new-password’
‘/usr/local/mariadb-10.2.19/bin/mysqladmin’ -u root -h dellcentos6.cqdzzx.cn password ‘new-password’

Alternatively you can run:
‘/usr/local/mariadb-10.2.19/bin/mysql_secure_installation’

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd ‘/usr/local/mariadb-10.2.19’ ; /usr/local/mariadb-10.2.19/bin/mysqld_safe --datadir=’/data/mysqldb/3306/data’

You can test the MariaDB daemon with mysql-test-run.pl
cd ‘/usr/local/mariadb-10.2.19/mysql-test’ ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB’s strong and vibrant community:
https://mariadb.org/get-involved/
8.复制启动服务脚本至/etc/init.d目录并启动
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig mysqld on
#service mysqld start
Starting MariaDB.190521 15:07:45 mysqld_safe Logging to ‘/data/mysqldb/3306/log/error.log’.
190521 15:07:45 mysqld_safe Starting mysqld daemon with databases from /data/mysqldb/3306/data
SUCCESS!
另,在CentOS7中,最好是用systemd方式来启动mariadb。
#cd /usr/lib/systemd/system/
#vim mysqld.service
[Unit]
Description=MariaDB Server
After=network.target
After=syslog.target

[Service]
LimitNOFILE=10000
Type=simple
PIDFile=/data/mysqldb/3306/pid/mysqld.pid
ExecStart=/usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mariadb-10.2.19 --datadir=/data/mysqldb/3306/data
ExecStop=/bin/kill -9 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
9.进行安全配置
#/usr/local/mysql/bin/mysql_secure_installation

Enter current password for root 默认为空
Set root password 设置mysql root密码
Remove anonymous users 是否移除匿名用户登录
Disallow root login remotely 是否禁止root远程登录
Remove test database and access to it? 是否移除test数据和test账号
Reload privilege tables now? 是否立即更新权限
Thanks for using MariaDB!
(二)编译安装nginx
1.安装依赖包
#yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel
2.创建用于nginx,php的组和账号
#groupadd -r www
#useradd -r -g www -s /sbin/nologin -M www
3.编译安装nginx
#useradd -r -g www -s /sbin/nologin -M www
#chown root:root /usr/local/nginx
#mkdir -pv /data/nginx_tmp/{client_body_temp,proxy_temp,
fcgi_temp,uwsgi_temp,scgi_temp}
#chown -R www:www /data/nginx_tmp
#cd /usr/local/src/nginx-1.14.0
#./configure
–prefix=/usr/local/nginx
–user=www
–group=www
–with-http_stub_status_module
–with-http_ssl_module
–with-http_v2_module
–with-http_flv_module
–with-http_mp4_module
–with-http_gzip_static_module
–with-http_sub_module
–with-stream
–with-stream_ssl_module
–http-client-body-temp-path=/data/nginx_tmp/client_body_temp/
–http-proxy-temp-path=/data/nginx_tmp/proxy_temp/
–http-fastcgi-temp-path=/data/nginx_tmp/fcgi_temp/
–http-uwsgi-temp-path=/data/nginx_tmp/uwsgi_temp/
–http-scgi-temp-path=/data/nginx_tmp/scgi_temp/
–with-openssl=
–with-pcre
#make && make install
4.cd /usr/lib/systemd/system/
vim nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecReload=/bin/kill -HUP $MAINPID
#ExecStop=/bin/kill -s QUIT $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
5.#systemctl start nginx.service
#systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
6.#firewall-cmd --zone=public --add-port=80/tcp --permanent 开启80端口
#firewall-cmd --reload 重新载入
#firewall-cmd --zone=public --query-port=80/tcp 查看80端口是否开启
yes
(三)编译安装php
1.安装依赖库
#yum install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel libXpm-devel mhash libmcrypt libmcrypt-devel libvpx t1lib libicu-devel glibc
2.编译安装php-7.1.29
#cd /usr/local/src
#tar -zxvf php-7.1.29.tar.gz -C /usr/local/src
#mkdir /usr/local/php7
#cd /usr/local/src/php-7.1.29
#./configure --prefix=/usr/local/php7
–with-config-file-path=/usr/local/php7/etc
–with-config-file-scan-dir=/usr/local/php7/conf.d
–with-mysql-sock=/var/run/mysql/mysql.sock
–enable-fpm
–with-fpm-user=www
–with-fpm-group=www
–enable-mysqlnd
–with-mysqli=mysqlnd
–with-pdo-mysql=mysqlnd
–with-iconv-dir=/usr/local/libiconv
–with-freetype-dir=
–with-jpeg-dir
–with-png-dir
–with-zlib
–with-libxml-dir=
–enable-xml
–disable-rpath
–enable-bcmath
–enable-shmop
–enable-sysvsem
–enable-inline-optimization
–with-curl
–enable-mbregex
–enable-mbstring
–enable-intl
–with-mcrypt
–enable-ftp
–with-gd
–enable-gd-native-ttf
–with-openssl
–with-mhash
–enable-pcntl
–enable-sockets
–with-xmlrpc
–enable-zip
–enable-soap
–with-gettext
–enable-opcache
–with-xsl
–enable-shared
–enable-libxml
–enable-session
–with-xpm-dir=
#make && make install
3.配置php
⑴.cp /usr/local/src/php-7.1.29/php.ini-production /usr/local/php7/etc/php.ini
⑵.vim /usr/local/php7/etc/php.ini
①找到cgi.fix_pathinfo配置项并修改为0
cgi.fix_pathinfo=0
②找到 extension_dir 修改扩展目录位置并修改如下
extension_dir = “/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/”
③找到 timezone 修改时区如下:
date.timezone = PRC

PRC就是英文People’s Republic of China,中华人民共和国
④开启OPcache
跳转到文件的最后一行(shift+G), 输入以下内容:
zend_extension=opcache.so
⑤修改session的目录配置
#mkdir -p /var/lib/php7/session
#chown -R www:www /var/lib/php7/session
#vim /usr/local/php7/etc/php.ini
找到 session.save_path 修改为如下内容:

session.save_path = “/var/lib/php7/session”
⑶添加php-fpm管理相关的配置文件到系统配置目录/etc/init.d
①# cp /usr/local/src/php-7.1.29/sapi/fpm/php-fpm.service
/usr/lib/systemd/system
②cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
③cp /usr/local/php7/etc/php-fpm.d/www.conf.default
/usr/local/php7/etc/php-fpm.d/www.conf
⑷添加php系统环境变量
#vim /etc/profile.d/php.sh
添加内容如下:

export PATH= P A T H : / u s r / l o c a l / p h p 7 / b i n / : / u s r / l o c a l / p h p 7 / s b i n / 或 P A T H = / u s r / l o c a l / p h p 7 / b i n / : / u s r / l o c a l / p h p 7 / s b i n / : PATH:/usr/local/php7/bin/:/usr/local/php7/sbin/或 PATH=/usr/local/php7/bin/:/usr/local/php7/sbin/: PATH:/usr/local/php7/bin/:/usr/local/php7/sbin/PATH=/usr/local/php7/bin/:/usr/local/php7/sbin/PATH
#source /etc/profile.d/php.sh 使用source立即生效刚刚添加的php环境变量
⑸设置php开机启动
#systemctl start php-fpm.service
#systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值