環境準備
清空關閉防火牆並關閉selinux
# iptables -F
# systemctl stop firewalld
# systemctl disable firewalld
# vim /etc/selinux/config
改: SELINUX= enforcing
爲: SELINUX=disabled
# reboot #重啓系統生效
配置yum源
配置網絡yum源
(1)備份 :
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
(2)下載新的CentOS-Base.repo 到/etc/yum.repos.d/
# rpm -ivh /mnt/Packages/wget-1.14-15.el7.x86_64.rpm
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下載配置文件
配置epel源
# yum install epel-release –y
部署LNMP環境
LNMP=Linux + Nginx + MySQL + PHP
mysql-boost-5.7.27.tar.gz
nginx-1.17.4.tar.gz
pcre-8.43.tar.gz
php-7.3.10.tar.gz
安裝nginx
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel #安裝依賴包
useradd -M -s /sbin/nologin nginx #創建nginx用戶
tar xvf pcre-8.43.tar.gz -C /usr/local/src/ #上傳源碼包
上傳nginx安裝包解壓安裝
tar xvf nginx-1.17.4.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.17.4
#./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --
with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.43 --user=nginx --group=nginx #配置選項
#make && make install #編譯安裝
配置Nginx支持php文件
修改配置文件之前,先備份,養成好習慣,備份nginx.conf
# cp /usr/local/nginx/conf/nginx.conf{,.bak}
# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; 修改用戶爲nginx
啓用php的支持
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
啓動nginx服務
# /usr/local/nginx/sbin/nginx
編輯配置環境變量
# vim /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
配置服務開機自動啓動
配置開機自動啓動
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on
安裝MySQL 5.7
卸載系統自帶的mysql和boost
# yum -y remove mysql mariadb-*
# yum -y remove boost-*
開始安裝
yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel #安裝依賴包
# groupadd mysql
# useradd -M -s /sbin/nologin -r -g mysql mysql #添加用戶和組
上傳安裝包並解壓
# tar xf mysql-boost-5.7.27.tar.gz -C /usr/local/src/
# cd /usr/local/src/mysql-5.7.27/
規劃安裝目錄:
安裝目錄:/var/lib/mysql
數據目錄:/val/lib/mysql/data
mkdir -p /var/lib/mysql/data
chown -R mysql:mysql /var/lib/mysql #授權目錄mysql權限
編譯安裝
# cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql \
-DMYSQL_DATADIR=/var/lib/mysql/data \
-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 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/src/mysql-5.7.27/boost/boost_1_59_0
# make -j 4
# make install
編輯配置文件
# vim /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /var/lib/mysql
datadir = /var/lib/mysql/data
pid-file = /tmp/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8'
character-set-server = utf8
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = /var/lib/mysql/mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
配置環境變量
# vim /etc/profile.d/mysql.sh
export PATH=/var/lib/mysql/bin:$PATH #添加path路徑,讓系統讀到mysql命令
#source /etc/profile.d/mysql.sh #使其mysql.sh生效
修改mysql目錄權限
# chown -R mysql:mysql /var/lib/mysql
生成服務啓動腳本
# cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld
# chowd +x /etc/init.d/mysqld
初始化數據庫
# /var/lib/mysql/bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
啓動服務
# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
修改初始登錄密碼
Mysql5.7初始安裝後,第一次登錄需要查詢一下密碼
# grep "password" /var/log/mysql-error.log
2019-10-25T09:00:27.826152Z 1 [Note] A temporary password is generated for root@localhost: muHyi?fKy5rc
登錄修改密碼
# mysql -u root -p
Enter password: muHyi?fKy5rc
mysql> alter user 'root'@'localhost' identified by '123456';
mysql>flush privileges;
編譯安裝PHP
安裝所需依賴包
# yum -y install php-mcrypt libmcrypt libmcrypt-devel php-pear libxml2 libxml2-devel curl curl-d
evel libjpeg libjpeg-devel libpng libpng-devel freetype-devel
上傳並解壓PHP安裝包
# tar xf php-7.3.10.tar.gz -C /usr/local/src/
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/ --enable-fpm --with
-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
修改配置
# cp /usr/local/src/php-7.3.10/php.ini-production /usr/local/php/php.ini #複製php配置文件到安裝目錄
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #複製模板配置文件爲php-fpm的配置文件
修改: vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid #取消前面的分號
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改:vim /usr/local/php/etc/php-fpm.d/www.conf
user = www #設置php-fpm運行賬號爲www
group = www #設置php-fpm運行組爲www
設置php-fpm開機啓動
cp /usr/local/src/php-7.3.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #複製php-fpm到啓動目錄
chmod +x /etc/rc.d/init.d/php-fpm #添加執行權限
chkconfig php-fpm on #設置開機啓動
service php-fpm start #啓動php-fpm
重啓php和nginx。
service php-fpm restart
service nginx restart
測試:
在web目錄:/usr/local/nginx/html中新建一個phpinfo的php文件,在瀏覽器中查看。