Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the basic environment for CentOS LEMP system installation, compilation and installation

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

CentOS LEMP system installation, compilation and installation of the basic environment is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

CentOS LEMP builds a high-performance WEB server (third edition).

I. CentOS LEMP system installation

1. System partition recommended / boot 100m (about 100m) SWAP physical memory 2 times (if your physical memory is greater than 4G, allocate 4G) / partition 15~20G/usr/local 20g (for installing software) / data all remaining space. [note] specific partitions should be divided according to related business, specific installation this article does not introduce the installation process to select the least package, using text mode installation, please do not install graphics.

two。 System initialization system initialization script (turn off unwanted services according to specific requirements) # shinit_network.sh / / download the scripts.tar.gz package provided in this article, you can find this script.

II. Basic environment for CentOS LEMP compilation and installation

1. CentOS LEMP installation preparation

1.1CentOS LEMP system package installation specification system convention software source code package storage location / usr/local/src source code package compilation installation location (prefix) / usr/local/software_name script and maintenance program location / usr/local/sbinMySQL database location / data/mysql/data (can be set on a case-by-case basis) website root directory / data/www/wwwroot (can be set on a case-by-case basis) virtual host log Root directory / data/logs (can be set according to circumstances) Nginx running account www:wwwinstall_software_name.sh / / stores compilation parameter scripts. It is customary to store all compilation scripts in install_software_name.sh to facilitate upgrading and updating the software.

Create a website account and related storage directory # add_user.sh / usr/sbin/groupadd www/usr/sbin/useradd-g www wwwmkdir-p / data/www/wwwrootchmod + w / data/www/wwwrootchown www:www / data/www/wwwroot-R copy code

1.2CentOS LEMP system environment deployment and adjustment check whether the system is normal # tail-N100 / var/log/messages (check for system-level error messages) # dmesg (check for hardware devices with error messages) # ifconfig (check whether the network card is set correctly) # ping www.linuxtone.org (check whether the network is normal)

1.3CentOS LEMP uses the development package required for yum program installation (the following is the standard RPM package name) to add domestic mirror source acceleration software installation and download speed, please refer to: http://bbs.linuxtone.org/thread-158-1-1.html

Yum-y install ntp vim-enhanced gcc gcc-c++gcc-g77 flex bison autoconf automake bzip2-devel "ncurses-devel openssl-devel libtool*zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel" fontconfig-devel freetype-devel libXpm-develgettext-devel curl curl-devel pam-devel "e2fsprogs-devel krb5-devel libidnlibidn-devel copy code

1.4 timing correct server clock, timing synchronization with China National time Service Center time service server # crontab-e join one line: 153 * / usr/sbin/ntpdate 210.72.145.44 > / dev/null 2 > & 1 copy code

# vi list fill in the download address list in the list file. Official download package name: # nginx ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gzhttp://sysoev.ru/nginx/nginx-0.7.30.tar.gz#PHP-GD-LIB

Http://www.libgd.org/releases/gd-2.0.35.tar.bz2

Http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz

Http://jaist.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.bz2

Http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1228695303&big_mirror=0

Http://jaist.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2.6.7.tar.gz

# MySQL http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30.tar.gz/from/http://mysql.cdpa.nsysu.edu.tw/

# php http://cn.php.net/get/php-5.2.8.tar.bz2/from/cn2.php.net/mirror

Http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz

# PHP-EXT http://pecl.php.net/get/memcache-2.2.4.tgz

Http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

Http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2 copy Code # wget-I list

two。 Compile and install package source code compile and install required package (Source)

1.1 compile and install Nginx tar zxvf pcre-7.8.tar.gzcd pcre-7.8./configure & & make & & makeinstall copy Code tar zxvf nginx-0.7.30.tar.gzcd nginx-0.7.30./configure-- user=www-- group=www--prefix=/usr/local/nginx/-- with-http_stub_status_module--with-openssl=/usr/lib make & & makeinstall copy Code

1.2 compile and install GD and related LIB. Tar jxvf gd-2.0.35.tar.bz2cd gd-2.0.35./configure-- prefix=/usr/local/gd2&& make&& make installtar zxvf libiconv-1.12.tar.gz copy code cd libiconv-1.12./configure-- prefix=/usr & & make&& make installtar jxvf libmcrypt-2.5.8.tar.bz2 copy code cd libmcrypt-2.5.8./configure-- prefix=/usr & & make&& make install

Copy code tar zxvf mhash-0.9.9.tar.gzcd mhash-0.9.9./configure-- prefix=/usr & & make&& make install copy code # vi / etc/ld.so.conf add / usr/lib include ld.so.conf.d/*.conf/usr/lib copy code # ldconfig

[note] the ldconfig command is mainly used to search the directories listed in the default directory (/ lib and / usr/lib) and the dynamic library configuration file / etc/ld.so.conf, which you need to run manually when you install a new dynamic link library. Tar zxvf mcrypt- 2.6.7.tar.gz [code] cd mcrypt-2.6.7/configure-- prefix=/usr & & make&& make install copy code

1.3 the specific script for compiling and installing MySQL#sh install_mysql.sh// is as follows: CHOST= "x86_64-pc-linux-gnu" CFLAGS= "- march=nocona-O3-pipe" CXXFLAGS= "${CFLAGS}". / configure "

"--prefix=/usr/local/mysql"

"--localstatedir=/data/mysql/data"

"--with-comment=Source"

"--with-server-suffix=-Linuxtone.Org"

"--with-mysqld-user=mysql"

"--without-debug"

"--with-big-tables"

"--with-charset=gbk"

"--with-collation=gbk_chinese_ci"

"--with-extra-charsets=all"

"--with-pthread"

"--enable-static"

"--enable-thread-safe-client"

"--with-client-ldflags=-all-static"

"--with-mysqld-ldflags=-all-static"

"--enable-assembler"

"--with-plugins=all"

"- without-ndb-debug"

Make

Make install

Useradd mysql-d / data/mysql-s/sbin/nologin

/ usr/local/mysql/bin/mysql_install_db--user=mysql

Cd / usr/local/mysql

Chown-R root:mysql.

Mkdir-p / data/mysql/data

Chown-R mysql/data / mysql/data

Cp share/mysql/my-huge.cnf / etc/my.cnf

Cp share/mysql/mysql.server/etc/rc.d/init.d/mysqld

Chmod 755 / etc/rc.d/init.d/mysqld

Chkconfig-add mysqld

/ etc/rc.d/init.d/mysqld start

Cd / usr/local/mysql/bin

For i in *; do ln-s / usr/local/mysql/bin/$i/usr/bin/$i; done copy code [Note] configure the hostname correctly before compiling mysql, otherwise it will not start normally.

For example: [root@lempmysql-5.1.30] # cat / etc/hosts # Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 localhost.localdomainlocalhost192.168.1.104 lemp.linuxtone.org

Copy code [Note] replace your / etc/my.cnf with the my.cnf in the scripts.tar.gz package provided with this article, and make relevant adjustments according to your hardware parameters, and you can make preliminary performance tuning with the tuning-primer.sh in the package.

1.4 compile and install PHP-FastCGI tar jxvf php-5.2.8.tar.bz2gzip-cd php-5.2.8-fpm-0.5.10.diff.gz | patch-d php-5.2.8- p1cd php-5.2.8 copy code # sh install_php.sh// specific script is as follows: CHOST= "i686-pc-linux-gnu" CFLAGS= "- march=prescott-O3-pipe-fomit-frame-pointer" CXXFLAGS= "${CFLAGS}". / configure "

"--prefix=/usr/local/php-fcgi"

"--enable-fastcgi"

"--enable-fpm"

"--enable-discard-path"

"--enable-force-cgi-redirect"

"--with-config-file-path=/usr/local/php-fcgi/etc"

"--enable-zend-multibyte"

"--with-mysql=/usr/local/mysql"

"--with-libxml-dir"

"--with-xmlrpc"

"--with-gd=/usr/local/gd2"

"--with-jpeg-dir"

"--with-png-dir"

"--with-bz2"

"--with-freetype-dir"

"--with-iconv-dir"

"--with-zlib-dir"

"--with-curl"

"--with-curlwrappers"

"--with-openssl"

"--with-mcrypt"

"--with-mhash"

"--enable-pcntl"

"--enable-sockets"

"--enable-sysvsem"

"--enable-inline-optimization"

"--enable-soap"

"--enable-gd-native-ttf"

"--enable-ftp"

"--enable-mbstring"

"--enable-exif"

"--disable-debug"

"- disable-ipv6"

# sed-I 's#-lz-lm-lxml2-lz-lm-lxml2-lz-lm-lcrypt#&-liconv#' Makefile

MakeZEND_EXTRA_LIBS='-liconv'

Make install

Cp php.ini-dist/usr/local/php-fcgi/etc/php.ini

Copy the code

1.5 compile and install the PHP extension

Tar zxvf memcache-2.2.4.tgz

Cd memcache-2.2.4

/ usr/local/php-fcgi/bin/phpize

. / configure--with-php-config=/usr/local/php-fcgi/bin/php-config

Make & & make install

Copy the code

Tar jxvf eaccelerator-0.9.5.3.tar.bz2

Cd eaccelerator-0.9.5.3

/ usr/local/php-fcgi/bin/phpize

. / configure-- enable-eaccelerator=shared--with-php-config=/usr/local/php-fcgi/bin/php-config

Make & & make install

Copy the code

Tar zxvf PDO_MYSQL-1.0.2.tgz

Cd PDO_MYSQL-1.0.2

/ usr/local/php-fcgi/bin/phpize

. / configure-- with-php-config=/usr/local/php-fcgi/bin/php-config--with-pdo-mysql=/usr/local/mysql

Make & & make install

Copy the code

1.6 configure php.ini

# sh init_php.sh

/ / execute PHP configuration script

[note] this script is provided in the download package. Mainly to add automatic add PHP extension and PHP security-related settings, users can edit this file to make adjustments according to the specific situation.

# vi / usr/local/php-fcgi/etc/php.ini / / add in *

[eAccelerator]

Extension= "eaccelerator.so"

Eaccelerator.shm_size= "32"

Eaccelerator.cache_dir= "/ cache_tmpfs/eaccelerator"

Eaccelerator.enable= "1"

Eaccelerator.optimizer= "1"

Eaccelerator.check_mtime= "1"

Eaccelerator.debug= "0"

Eaccelerator.filter= ""

Eaccelerator.shm_max= "0"

Eaccelerator.shm_ttl= "0"

Eaccelerator.shm_prune_period= "0"

Eaccelerator.shm_only= "0"

Eaccelerator.compress= "1"

Eaccelerator.compress_level= "9"

Copy the code

1.7 install ZendOptimizer-3.3.3

Tar zxvf ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz

Cd ZendOptimizer-3.3.3-linux-glibc23-x86_64

. / install

Copy the code

After decompressing, enter the directory. / install, security prompt to select the relevant directory and configuration file storage directory.

1.8 configure php-fpm.conf

Rm-rf / usr/local/php-fcgi/etc/php-fpm.conf

Upload the php-fpm.conf file provided in this article to this directory.

/ usr/local/php-fcgi/sbin/php-fpm start / / start the service to see if there is an error, and continue without error.

1.9 configure nginx/conf

# cd / usr/local/nginx

# mv conf conf_old

# mkdir-p conf/ {vhost,conf_example}

Copy the code

# replace the conf directory provided with the current conf directory. In the downloaded scripts.tar.gz package.

Introduction to the directory structure:

/ usr/local/nginx/conf / / Store the master configuration file

/ usr/local/nginx/conf/vhost / / stores the virtual host configuration file.

/ usr/local/nginx/conf/conf_example / / stores some classic configuration examples {virtual host, hotlink protection, access control, redirection, load balancing, etc.}

[root@lempmysql] # / usr/local/nginx/sbin/nginx-t / / verify whether there is a configuration syntax error.

2009-01-06 09:36:12 [info] 23353#0: the configuration file/usr/local/nginx//conf/nginx.conf syntax is ok

2009-01-06 09:36:12 [info] 23353#0: the configuration file/usr/local/nginx//conf/nginx.conf was tested successfully

Copy the code

# chmod afigx / etc/init.d/nginx / / upload the nginx script provided by the text to the / etc/init.d/ directory

[note] this script already contains the management of php-fpm. All services can be managed by using this script directly.

# / etc/init.d/nginx stop / / stop nginx service

# / etc/init.d/nginx start / / start the nginx service

Copy the code

2.0 validate service environment

After the virtual host is configured, edit php.ini to remove the phpinfo from the disable_functions, restart the service, and use the Phpinfo function to check the ring configuration.

Write phpinfo.php

Copy the code

Http://ip/phpinfo.php

You can view the current configuration environment. After viewing, please disable this function again for security reasons.

Third, simple server optimization

1. Simple optimization of disk Imax O

# vi / etc/fstab / / join notaime

LABEL=/data / data ext3 defaults,noatime 0 2

Copy the code

# mount-oremount / data / / remount / data partition.

two。 Simply optimize the Linux kernel parameters (for more, please make relevant adjustments according to the server condition)

# vi/etc/sysctl.conf

Net.ipv4.tcp_fin_timeout = 30

Net.ipv4.tcp_keepalive_time = 300

Net.ipv4.tcp_syncookies = 1

Net.ipv4.tcp_tw_reuse = 1

Net.ipv4.tcp_tw_recycle = 1

Net.ipv4.ip_local_port_range = 5000 65000

Copy the code

# sysctl-p

Copy the code

3. Other optimizations are adjusted according to specific conditions and hardware conditions.

For more optimization, please refer to http://www.linuxtone.org/forum-31-1.html or contact us.

Fourth, relevant reference and introduction.

1.Nginx Tips (Nginx application skills including optimization) http://bbs.linuxtone.org/thread-1241-1-1.html

2.CentOS LEMP to build High performance WEB Server (second Edition) http://bbs.linuxtone.org/thread-123-1-1.html

3. If you want to build an available cluster solution, please refer to http://www.linuxtone.org/thread-1402-1-1.html

4. If you want to learn about server monitoring, please refer to http://www.linuxtone.org/forum-20-1.html

Fifth, download related software packages and scripts

All scripts and configuration examples in the http://www.linuxtone.org/lemp/scripts.tar.gz article.

If you find all http://www.linuxtone.org/lemp/lemp.tar.gz packages cannot be downloaded, please go to the official download.

6. answer to common mistakes (questions) [keep every day] add:

1. What is the difference between eaccelerator and xcache?

When too many PHP binaries are cached, eAccelerator outperforms Xcache in performance after surpassing shm_size

2. According to the document, the installation is completed and the result is 502Bad Gateway?

Please check the relevant sections of http://www.linuxtone.org

3. Nginxstatus interpretation

Active connections-the number of active connections initiated to the backend

Server accepts handled requests-nginx handled a total of 43629083 connections and successfully created 43629083 handshakes

(proved that there was no failure in the middle), a total of 259552136 requests were processed

Reading-the number of Header messages read to the client by nginx

Writing-the number of Header messages returned by nginx to the client

Waiting-when keep-alive is enabled, this value is equal to active-(reading + writing), which means that Nginx has been processed

The resident connection is waiting for the next request instruction. When the access efficiency is high and the request is processed quickly, it is normal to have a large number of Waiting.

If there are a large number of reading + writing, the concurrent traffic is very large and is in the process of being processed.

4. Can EA or xcache and zend be used together?

Sure

5. Follow the script to execute sed-I-e's / ^ Lang =. * / LANG= "en" /'/ etc/sysconfig/i18n.

You may encounter the following error:

Perl: warning: Please checkthat your locale settings:

LANGUAGE = (unset)

LC_ALL = (unset)

LANG = "en_US.UTF-8:en_US:en_US.ISO-8859-1"

Are supported and installed on your system.

Perl: warning: Falling back to the standard locale (C).

Solution:

LC_ALL=C;exportLC_ALL; LC_CTYPE=C; exportLC_ CTYPE

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report