Tencent Cloud Server Centos7.7 Build Lnmp

Posted by William on Fri, 29 Nov 2019 09:10:54 +0100

Query system information

cat /etc/redhat-release
// Return
## CentOS Linux release 7.7.1908 (Core)

yum Mirror Switch to NetEase

  1. Download new sources and backup local sources
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
mv CentOS-Base.repo CentOS-Base.repo.bak
mv CentOS6-Base-163.repo CentOS-Base.repo
  1. yum source update
yum clean all && yum makecache && yum update -y

Install Nginx-1.16.1

  1. Verify that the gcc g++ development class library is properly installed
# Install make
yum -y install gcc automake autoconf libtool make
# Install g++.
yum -y install gcc gcc-c++
  1. Install nginx build
yum -y install openssl openssl-devel
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
  1. Download and install nginx
# Download nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz
# Unzip and enter the unzipped folder
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
# To configure
# Note: In order to use Nginx's mod_zip module for package download in PHP, I install git first, then nginx, then I have to go back and install it again before this step. If this function is not needed, you can remove the parameters after. /configure
./configure --with-http_ssl_module --add-module=src/mod_zip
# install
make && make install
  1. Start/Restart/Close/Test nginx
# open
/usr/local/nginx/sbin/nginx
# Restart (modifying profile requires testing)
/usr/local/nginx/sbin/nginx -s reload
# Close
/usr/local/nginx/sbin/nginx -s stop
# Test (after modifying the configuration file, you can test it)
/usr/local/nginx/sbin/nginx -t 

Install Git-2.24

  1. Install Dependent Packages
yum -y install zlib-devel curl-devel openssl-devel perl cpio expat-devel gettext-devel openssl zlib autoconf tk perl-ExtUtils-MakeMaker
  1. Download and install Git
wget https://github.com/git/git/archive/v2.24.0.tar.gz
tar zxvf v2.24.0.tar.gz
cd git-2.24.0
autoconf
./configure
make & make install
  1. Then modify the /etc/ld.so.conf file to add a line at the end:
# Open File
vi /etc/ld.so.conf
# Add the following to the last line
/usr/local/lib
# Save and Exit
wq!
  1. test
git --version
# Browser test to open server address

Install php7.2.19

  1. Go to the official website to download the compressed package, upload to the server to unzip the file, and enter
# Or download the source file installation directly from the server
wget http://cn2.php.net/distributions/php-7.2.24.tar.gz
# Unzip (downloaded files below default to usr/local folder)
tar -zxvf php-7.2.24.tar.gz
# Get into
cd php-7.2.24
  1. Configure installation parameters
# Generate configure file packages
autoconf
# Configuration (here if the server fails to install the corresponding dependencies, such as Mysql, it is not too late to install MySQL before returning to install php)
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-curl \
--with-freetype-dir=/usr/include/freetype2/freetype \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--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-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-fileinfo \
--disable-inline-optimization

Note: There is a problem here, error: unrecognized options: --sockets, check the compressed ext package, found no sockets, compared with the same version installed by other servers, found decompressed, then go to PHP official website to check the version, found that the latest PHP 7.2.19 has changed php-7.2.24

  1. Compile Installation
make && make install
  1. Generate Configuration File
# Generate php.ini
cp /root/php-7.2.24/php.ini-development /usr/local/php7/etc/php.ini
# Generate www.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
# Generate php-fpm.conf
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
  1. Modify the port of php-fpm
vi /usr/local/php7/etc/php-fpm.d/www.conf
# Modify listen 127.0.0.1:9000 port to 9001
# User and user_group are modified as appropriate
  1. Modify nginx configuration file
vi /usr/local/nginx/conf/nginx.conf
# Modify one of the sites'fastcgi_pass 127.0.0.1:9000 ports to 9001
  1. Open the second php-fpm and restart nginx
/usr/local/php7/sbin/php-fpm
/usr/local/nginx/sbin/nginx -s -reload

Install Mysql

Note: mysql inside centos7 yum source has replaced mysql with MariaDB, and the default corresponds to mysql 5.5, where the latest version of MariaDB10.4 is installed

  1. View mariadb status in yum source, uninstall old source
rpm -qa | grep mariadb
# The results are as follows
  1. Create MariaDB.repo in the yum.repos.d directory
cd /etc/yum.repos.d/
touch MariaDB.repo
vim MariaDB.repo
# Add the following
# MariaDB 10.4 CentOS repository list - created 2019-11-19 09:14 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
  1. Install MariaDB 10.4
yum install MariaDB-server MariaDB-client
  1. Set up boot-up and other
systemctl start mariadb #Start Services

systemctl enable mariadb #Set up boot-up

systemctl restart mariadb #Restart
systemctl stop mariadb.service #Stop MariaDB
  1. Simple configuration for MariaDB
    https://blog.csdn.net/uisoul/article/details/85223270
mysql_secure_installation
Enter current password for root (enter for none):<–Initial run direct return
Set root password? [Y/n] <– Is it set root User password, enter y And return or direct return

New password: <– Set up root User's password

Re-enter new password: <– Enter your password again
Remove anonymous users? [Y/n] <– Do you want to delete anonymous users? Y,Enter

Disallow root login remotely? [Y/n] <–Is Prohibited root Remote login,N,Enter,

Remove test database and access to it? [Y/n] <– Delete or not test Database, n,Enter

Reload privilege tables now? [Y/n] <– Whether to reload the permission table, return
mysql -u root -p
vi /etc/my.cnf
# Add the following:
[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
vi /etc/my.cnf.d/client.cnf
# Add in [client]
default-character-set=utf8
vi /etc/my.cnf.d/mysql-clients.cnf
# Add in [mysql]
default-character-set=utf8
# restart
systemctl restart mariadb
# Testing
mysql> show variables like "%character%";show variables like "%collation%";

Create an External Network Connectable User

grant all privileges on *.* to tm@'%' identified by 'tianming2015';
flush privileges;

Test the connection remotely, connect (check the firewall if you can't)!stop

Install redis

  1. Download & Unzip
# download
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
# decompression
tar -zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
  1. install
# Specify directory
make PREFIX=/usr/local/redis install
  1. Go to the installation directory and copy the configuration file to the installation directory
cd /usr/local/redis
mkdir conf
cp /root/redis-3.0.0/redis.conf  /usr/local/redis/bin
  1. Start redis
# Modify the redis.conf configuration file to start daemonize yes in back-end mode
vim /usr/local/redis/bin/redis.conf
# Modify the following options
daemonize yes
requirepass 123456 //Set Password
# Launch redis by executing the following command:
cd /usr/local/redis/bin
./redis-server redis.conf
  1. Connect and close tests
# Connect redis
/usr/local/redis/bin/redis-cli
# Turn off redis
cd /usr/local/redis
./bin/redis-cli shutdown
# Force termination of redis
pkill redis-server
  1. Start-up settings
vim /etc/rc.local
//Add to
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis-conf

Install Node.js

  1. Download & Unzip
# download
wget https://npm.taobao.org/mirrors/node/v9.9.0/node-v9.9.0-linux-x64.tar.xz
# decompression
tar -xvf  node-v9.9.0-linux-x64.tar.xz
cd  node-v9.9.0-linux-x64/bin && ls
# Result: node and npm
# Testing 
./node -v   // Display version number, installation successful
# Move node.js to/usr/local directory
mv /root/node-v9.9.0-linux-x64 /usr/local/
  1. Make a soft chain so that node and npm commands can be executed in any directory
ln -s /usr/local/node-v9.9.0-linux-x64/bin/node /usr/local/bin/node
ln -s /usr/local/node-v9.9.0-linux-x64/bin/npm /usr/local/bin/npm
  1. Install Taobao Mirror
cd /usr/local/node-v9.9.0-linux-x64/bin
npm install -g cnpm --registry=https://registry.npm.taobao.org
# Establish Soft Chain
ln -s /usr/local/node-v9.9.0-linux-x64/bin/cnpm /usr/local/bin/cnpm
  1. Install pm2 to keep processes resident
cnpm install pm2
ln -s /usr/local/node-v9.9.0-linux-x64/bin/pm2 /usr/local/bin/pm2
pm2 start xx.js 

Install Supervisor

  1. install
yum install python-setuptools
easy_install supervisor
  1. Create global profile
echo_supervisord_conf > /etc/supervisord.conf
supervisord -c /etc/supervisord.conf
  1. Modify Profile
vi /etc/supervisord.conf
# Add the following under include
[include] 
files = /usr/local/share/supervisor/*.conf
# Create log file
vi /usr/local/share/supervisor/redisQueue.log
  1. Under the /usr/local/share file, add the file process you want to guard in the following format
[program:casecloud-queue-listen]
command=php /var/www/casecloud/server/artisan queue:work redis --tries=3 --timeout=300
user = root
directory=/var/www/casecloud/server
autostart=true
autorestart=true
startsecs=3
stdout_logfile=/usr/local/share/supervisor/redisQueue.log

Description: command = followed by the shell you want to guard.

  1. Related Commands
supervisorctl reload # restart
supervisorctl status # View running
supervisorctl help   # Help
  1. Turn on after shutdown
supervisord

Install ftp

  1. install
yum -y install vsftpd
  1. Modify Configuration and Open
vi /etc/vsftpd/vsftpd.conf
# modify
anonymous_enable=NO
# Add a line at the end (after adding users, you cannot upload files, after setting user permissions, you will not be able to log in. Add the following to resolve)
allow_writeable_chroot=YES
  1. Increase ftp users
useradd -d /www/../oa/ -s /sbin/nologin cp
# Assign users to directories
chown cp -R /www/../oa/
  1. Test Connection
#Note that setting ftp transfer mode as active

Topics: Linux Redis Nginx MariaDB PHP