在centos7系统源码安装nginx+mysql+php+go

以下安装说明仅供参考,请根据实际情况修改配置,进行软件编译安装

软件安装也可以参考阿里云的"建站教程":

云服务器ECS自助建站的流程_云服务器 ECS-阿里云帮助中心

ssl证书配置参考:

SSL 证书 Nginx 服务器 SSL 证书安装部署-证书安装-文档中心-腾讯云

一、linux

环境:Centos 7.6 64位

【注】

1、文件权限、用户组

2、端口开放

二、nginx

# 编译工具
yum -y install gcc gcc-c++ autoconf automake make

# 依赖
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

# 添加www用户
groupadd -f www
useradd -g www www

# 安装nginx
wget https://nginx.org/download/nginx-1.18.0.tar.gz

# 解压
tar -xf nginx-1.18.0.tar.gz

# 切换目录
cd nginx-1.18.0

# 服务器原有配置:./configure --prefix=/usr/local/nginx --with-http_ssl_module
# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module
make && make install

# 创建软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

# nginx配置:如nginx.conf ssl

# 启动
nginx -c /usr/local/nginx/conf/nginx.conf

# 查看帮助
# nginx -h

# kill所有nginx进程
# kill $(ps aux|grep '[n]ginx'|awk '{print $2}')

nginx增加geoip模块

# yum安装geoip
yum -y install GeoIP GeoIP-devel GeoIP-data

# 进入源码目录进行编译,示例:
cd /root/nginx-1.18.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module --with-http_geoip_module

# 只要执行make,千万不要make install!!!
make

# 备份
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-old

# 替换
cp objs/nginx /usr/local/nginx/sbin/

修改nginx.conf配置

# 示例:nginx.conf增加geoip相关配置,其余不变

http {
    geoip_country /usr/share/GeoIP/GeoIP.dat;
    geoip_city /usr/share/GeoIP/GeoIPCity.dat;
 
    server {
        # 示例
        location ^~ /myip {
            default_type text/plain;
            return 200 "$remote_addr $geoip_country_name $geoip_city  $geoip_latitude $geoip_longitude";
        }
    }
}

重启nginx

nginx -s stop
nginx -c /usr/local/nginx/conf/

三、mysql

# 安装libaio
yum install -y libaio

# 下载地址:https://downloads.mysql.com/archives/community/
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

# 解压
tar -xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

# 切换目录
cd /usr/local/

# 重命名
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql

# 检查数据库文件是否有,如有删除(linux系统自带)
# 检查:rpm -qa | grep mysql
# 删除:rm -e --nodeps

# 创建mysql用户
# useradd -s /sbin/nologin -M mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql

# 创建mysql相关文件
mkdir -p /usr/local/mysql/data/ /usr/local/mysql/var/log/ /usr/local/mysql/var/run/

# 创建mysql.pid、mysql.sock文件
touch /tmp/mysql.sock /usr/local/mysql/var/log/error.log /usr/local/mysql/var/run/mariadb.pid

# 修改用户及用户组
chown -R mysql.mysql /usr/local/mysql

# mysql配置
# \cp -f my.cnf /etc/my.cnf

# 安装mysql
# /usr/local/mysql/bin/mysqld_safe --initialize --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# /usr/local/mysql/bin/mysqld_safe --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

# ALTER USER USER() IDENTIFIED BY 'root';
# 配置环境变量
# export PATH=$PATH:/usr/local/mysql/bin
# vi /etc/profile

# 配置生效
# source /etc/profile

# 加入系统进程
# cp -f /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server

# 启动服务
# systemctl enable mysql.server
# systemctl start mysql.server

# 或者/usr/local/mysql/support-files/mysql.server start

# 进入mysql,修改密码
# mysql -u用户名 -P端口 -p密码
# set password=password('root');
# grant all privileges on *.* to root@'%' identified by 'root';
# flush privileges;

四、mysql定时备份

# crontab定时任务
# 每天凌晨2点执行mysql数据备份
0 2 * * * /root/crontab/mysql/mysql_dump_script.sh


# 定时执行脚本mysql.backup.sh
#!/bin/bash
DATE=`date +"%Y%m%d"`
/usr/local/mysql/bin/mysqldump -uroot -proot --databases test > 'test_'${DATE}'.sql'

五、redis

# 下载
wget http://download.redis.io/releases/redis-6.2.6.tar.gz

# 解压
tar -xf redis-6.2.6.tar.gz

# 进入目录
cd redis-6.2.6

# 编译
make

# 安装
make install PREFIX=/usr/local/redis

# 创建etc、data目录
mkdir /usr/local/redis/etc
mkdir /usr/local/redis/data

# 复制redis.conf到/usr/local/redis/etc目录下
cp redis.conf /usr/local/redis/etc/

# 编辑redis.conf文件,配置redis为后台启动
# 将 daemonize no 改成 daemonize yes
# 将 dir ./ 改成 /usr/local/redis/data
# 将 requirepass foobared 改成 requirepass 123456
# 将 maxmemory-policy noeviction 改成 maxmemory-policy allkeys-lru
# vi /usr/local/redis/etc/redis.conf
sed -ir 's/daemonize no/daemonize yes/g' /usr/local/redis/etc/redis.conf
sed -ir 's/dir \.\//dir \/usr\/local\/redis\/data/g' /usr/local/redis/etc/redis.conf
sed -ir 's/# requirepass foobared/requirepass 123456/g' /usr/local/redis/etc/redis.conf

# 创建软连接
ln -s /usr/local/redis/bin/* /usr/local/bin/

# 启动redis-server
redis-server /usr/local/redis/etc/redis.conf

六、php

# 安装libxml2、libcurl、png、freetype、libxslt、libzip、cmake
yum install -y libxml2-devel libcurl-devel libpng-devel freetype-devel libxslt-devel

# 查看libzip版本:rpm -qa |grep libzip
# 查看cmake版本:cmake -version
# 卸载libzip、cmake
# yum remove libzip cmake

pwd=`pwd`

# 安装libzip
# 参考:https://www.cnblogs.com/itbsl/p/10208926.html
wget https://libzip.org/download/libzip-1.8.0.tar.gz --no-check-certificate
tar -xf libzip-1.8.0.tar.gz
cd libzip-1.8.0
mkdir build
cd build
cmake ..
make && make install

# 切换回原目录
cd $pwd

# 安装cmake
# 参考:https://blog.csdn.net/weixin_28909289/article/details/116680815
wget https://cmake.org/files/v3.18/cmake-3.18.6.tar.gz
tar -xf cmake-3.18.6.tar.gz
cd cmake-3.18.6
./bootstrap && make && make install

# 切换回原目录
cd $pwd

# 下载
wget https://www.php.net/distributions/php-7.3.4.tar.gz

# 解压
tar -xf php-7.3.4.tar.gz

# 进入目录
cd php-7.3.4

# 安装
./configure  --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --with-curl=/usr/local/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

# ======================================================================================================================
# 或者
# 参考:https://blog.csdn.net/weixin_40699635/article/details/115294390
# 参考:https://developer.aliyun.com/article/920010
yum install -y libxml2-devel libcurl-devel libpng-devel freetype-devel libxslt-devel libicu-devel bzip2 bzip2-devel gmp-devel libmcrypt libmcrypt-devel openldap openldap-devel libc-client-devel

./configure  --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --with-bz2 \
    --with-curl=/usr/local/curl \
    --with-freetype-dir \
    --with-gd \
    --with-gettext \
    --with-gmp \
    --with-iconv-dir \
    --with-imap \
    --with-imap-ssl \
    --with-kerberos \
    --with-ldap \
    --with-libdir=lib64 \
    --with-libxml-dir \
    --with-mcrypt \
    --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-calendar \
    --enable-exif \
    --enable-intl \
    --enable-inline-optimization \
    --enable-libxml \
    --enable-mbregex \
    --enable-mbstring \
    --enable-opcache \
    --enable-pcntl \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --enable-sysvsem \
    --enable-wddx \
    --enable-xml \
    --enable-zip
# ======================================================================================================================

make && make install

# php配置
\cp -Rf etc/* /usr/local/php/etc/
mkdir -p /usr/local/php/var/log /usr/local/php/var/run
touch /usr/local/php/var/log/php-fpm.log /usr/local/php/var/run/php-fpm.pid

# 创建软连接
ln -s /usr/local/php/bin/php /usr/local/bin/php

# 启动php-fpm
/usr/local/php/sbin/php-fpm

# nginx进行配置,curl进行访问
# 示例:curl 127.0.0.1/index.php

七、go

# 下载
wget https://studygolang.com/dl/golang/go1.17.3.linux-amd64.tar.gz

# 解压
tar -xf go1.17.3.linux-amd64.tar.gz

# 移动目录
mv go /usr/local/go

# 配置环境变量
# export PATH=$PATH:/usr/local/go/bin
# vi /etc/profile

# 配置生效
# source /etc/profile

# 查看go环境配置信息:go env
# 查看系统环境变量:echo $PATH

八、docker

参考:

如何部署并使用Docker_云服务器 ECS-阿里云帮助中心

九、ssl证书部署

参考:

SSL 证书 Nginx 服务器 SSL 证书安装部署-证书安装-文档中心-腾讯云

十、ftp服务

参考:

如何在CentOS 7系统中搭建FTP站点?_云服务器 ECS-阿里云帮助中心

如何搭建FTP服务器 - 服务器 - 亿速云

# 请根据实际情况配置ftp
# 安装vsftp
yum install vsftpd -y
 
# 创建test用户,默认家目录为/home/test,并且不能通过shell进行登录
useradd -s /sbin/nologin test
 
 
# 防止出现“530 Login incorrect”问题,有两种方式进行修改
#
# 方式一:编辑/etc/pam.d/vsftpd文件
# 可以对“auth       required     pam_shells.so”这行添加“#”,进行注释
# 或者将其改为“auth       required    pam_nologin.so”
# 对下面这行添加#,进行注释
#
# 方式二:
# 编辑/etc/shells文件,末尾追加/sbin/nologin
/sbin/nologin
 
 
# 防止ftp访问其他目录,编辑/etc/vsftpd/vsftpd.conf文件
chroot_local_user=YES  ## 原本就有,取掉注释就好
allow_writeable_chroot=YES  ## 添加
 
 
# 启动
service vsftpd start
 

你可能感兴趣的:(centos,nginx,mysql,php)