以下安裝說明僅供參考,請(qǐng)根據(jù)實(shí)際情況修改配置,進(jìn)行軟件編譯安裝
軟件安裝也可以參考阿里云的"建站教程":
云服務(wù)器ECS自助建站的流程_云服務(wù)器 ECS-阿里云幫助中心
ssl證書配置參考:
SSL 證書 Nginx 服務(wù)器 SSL 證書安裝部署-證書安裝-文檔中心-騰訊云
一、linux
環(huán)境:Centos 7.6 64位
【注】
1、文件權(quán)限、用戶組
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
# 服務(wù)器原有配置:./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
# 創(chuàng)建軟連接
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
# nginx配置:如nginx.conf ssl
# 啟動(dòng)
nginx -c /usr/local/nginx/conf/nginx.conf
# 查看幫助
# nginx -h
# kill所有nginx進(jìn)程
# kill $(ps aux|grep '[n]ginx'|awk '{print $2}')
nginx增加geoip模塊
# yum安裝geoip
yum -y install GeoIP GeoIP-devel GeoIP-data
# 進(jìn)入源碼目錄進(jìn)行編譯,示例:
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
# 只要執(zhí)行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相關(guān)配置,其余不變
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
# 檢查數(shù)據(jù)庫(kù)文件是否有,如有刪除(linux系統(tǒng)自帶)
# 檢查:rpm -qa | grep mysql
# 刪除:rm -e --nodeps
# 創(chuàng)建mysql用戶
# useradd -s /sbin/nologin -M mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
# 創(chuàng)建mysql相關(guān)文件
mkdir -p /usr/local/mysql/data/ /usr/local/mysql/var/log/ /usr/local/mysql/var/run/
# 創(chuàng)建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';
# 配置環(huán)境變量
# export PATH=$PATH:/usr/local/mysql/bin
# vi /etc/profile
# 配置生效
# source /etc/profile
# 加入系統(tǒng)進(jìn)程
# cp -f /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
# 啟動(dòng)服務(wù)
# systemctl enable mysql.server
# systemctl start mysql.server
# 或者/usr/local/mysql/support-files/mysql.server start
# 進(jìn)入mysql,修改密碼
# mysql -u用戶名 -P端口 -p密碼
# set password=password('root');
# grant all privileges on *.* to root@'%' identified by 'root';
# flush privileges;
四、mysql定時(shí)備份
# crontab定時(shí)任務(wù)
# 每天凌晨2點(diǎn)執(zhí)行mysql數(shù)據(jù)備份
0 2 * * * /root/crontab/mysql/mysql_dump_script.sh
# 定時(shí)執(zhí)行腳本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
# 進(jìn)入目錄
cd redis-6.2.6
# 編譯
make
# 安裝
make install PREFIX=/usr/local/redis
# 創(chuàng)建etc、data目錄
mkdir /usr/local/redis/etc
mkdir /usr/local/redis/data
# 復(fù)制redis.conf到/usr/local/redis/etc目錄下
cp redis.conf /usr/local/redis/etc/
# 編輯redis.conf文件,配置redis為后臺(tái)啟動(dòng)
# 將 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
# 創(chuàng)建軟連接
ln -s /usr/local/redis/bin/* /usr/local/bin/
# 啟動(dòng)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
# 進(jìn)入目錄
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/
cp php.ini-production /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
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
# 創(chuàng)建軟連接
ln -s /usr/local/php/bin/php /usr/local/bin/php
# 啟動(dòng)php-fpm
/usr/local/php/sbin/php-fpm
# nginx進(jìn)行配置,curl進(jìn)行訪問
# 示例: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
# 移動(dòng)目錄
mv go /usr/local/go
# 配置環(huán)境變量
# export PATH=$PATH:/usr/local/go/bin
# vi /etc/profile
# 配置生效
# source /etc/profile
# 查看go環(huán)境配置信息:go env
# 查看系統(tǒng)環(huán)境變量:echo $PATH
八、docker
參考:
如何部署并使用Docker_云服務(wù)器 ECS-阿里云幫助中心
九、ssl證書部署
參考:
SSL 證書 Nginx 服務(wù)器 SSL 證書安裝部署-證書安裝-文檔中心-騰訊云
十、ftp服務(wù)
參考:
如何在CentOS 7系統(tǒng)中搭建FTP站點(diǎn)?_云服務(wù)器 ECS-阿里云幫助中心文章來源:http://www.zghlxwxcb.cn/news/detail-592156.html
如何搭建FTP服務(wù)器 - 服務(wù)器 - 億速云文章來源地址http://www.zghlxwxcb.cn/news/detail-592156.html
# 請(qǐng)根據(jù)實(shí)際情況配置ftp
# 安裝vsftp
yum install vsftpd -y
# 創(chuàng)建test用戶,默認(rèn)家目錄為/home/test,并且不能通過shell進(jìn)行登錄
useradd -s /sbin/nologin test
# 防止出現(xiàn)“530 Login incorrect”問題,有兩種方式進(jìn)行修改
#
# 方式一:編輯/etc/pam.d/vsftpd文件
# 可以對(duì)“auth required pam_shells.so”這行添加“#”,進(jìn)行注釋
# 或者將其改為“auth required pam_nologin.so”
# 對(duì)下面這行添加#,進(jìn)行注釋
#
# 方式二:
# 編輯/etc/shells文件,末尾追加/sbin/nologin
/sbin/nologin
# 防止ftp訪問其他目錄,編輯/etc/vsftpd/vsftpd.conf文件
chroot_local_user=YES ## 原本就有,取掉注釋就好
allow_writeable_chroot=YES ## 添加
# 啟動(dòng)
service vsftpd start
到了這里,關(guān)于在centos7系統(tǒng)源碼安裝nginx+mysql+php+go的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!