这是一套非常经典的架构模型,也是一名运维工程师必须要掌握的一项技能。在搭建以前一定要将自己所要架构的版本与开发人员对接起来,否则会出现版本不兼容的状态。
我使用的是Linux7.6+nginx1.16.0+mysql5.7+php7.2,版本可能会有些老,但是一些企业还是会在使用,并且这些都是换汤不换药的,可以类比这些去搭建。值得注意的是,一定要注意搭建顺序,否则会发生软件相互找不到的情况。
先安装linux7.6修改主机名称,按照功能+公司域名的原则,然后关闭防火墙、设置静态IP地址、然后将网络管理器关闭、配置好yum源(我使用的是我曾经的配置过的,详细可以参考CSDN)、最后将selinux关闭。
配置主机和IP地址
# hostnamectl set-hostname web01.zld.cn
# su
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
...
IPADDR=10.1.1.11
# vim /etc/hosts
10.1.1.11 web01 web01.zld.cn
# systemctl restart network
关闭一些安全措施
# systemctl stop firewalld
# systemctl disable firewalld
# setenforce 0
# vim /etc/selinux/config
SELINUX=disabled
关闭网络管理器
# systemctl stop NetworkManager
# systemctl disable NetworkManager
时间同步
# ntpdate ntp.aliyun.com
# tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
# rm -rf /usr/local/mysql
# mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
# useradd -r -s /sbin/nologin mysql
# cd /usr/local/mysql/
# mkdir mysql-files
# chown mysql.mysql mysql-files
# chmod 750 mysql-files
# rm -rf /etc/my.cnf
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
......
.....
2024-12-25T09:04:02.905210Z 1 [Note] A temporary password is generated for root@localhost: -kYx?u,:j7WU
# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
# source /etc/profile
# cp support-files/mysql.server /etc/init.d/mysqld
# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/web01.zld.cn.err'.
SUCCESS!
# mysql -p
Enter password:临时密码
mysql> set password='123';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
# mysql_secure_installation 看清楚选项再选择,前两项可选,后边选y就可以
# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list
3-5为on就可以
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# # yum install pcre-devel zlib-devel openssl-devel -y
# tar -xf nginx-1.16.0.tar.gz
# useradd -r -s /sbin/nologin www
# cd nginx-1.16.0
[root@web01 nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_ status_module --with-http_realip_module
# make & make install
# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx Web Server
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
#systemctl start nginx
# systemctl enable nginx
# yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
# tar -xf php-7.2.12.tar.gz
# cd php-7.2.12
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
# make && make install
# cp /root/php-7.2.12/php.ini-development /usr/local/php/etc/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
# cp /root/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
# service php-fpm start
# ps -ef |grep php-fpm
# netstat -tnlp |grep 9000
# echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/profile
# source /etc/profile
# cd /usr/local/nginx
# cp conf/nginx.conf conf/nginx.conf.bak
# vim /conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root html;
location / {
index index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
# systemctl reload nginx
# vim /usr/local/nginx/html/demo.php
浏览器输入http://主机的ip地址/demo.php