Teach you how to deploy and build LNMP and Zabbix

About Zabbix:

zabbix (pronounced with zæbix) is an enterprise-level open source solution that provides distributed system monitoring and network monitoring functions based on a WEB interface.
Zabbix can monitor various network parameters to ensure the safe operation of the server system; and provides a flexible notification mechanism to allow system administrators to quickly locate/solve various problems.
Zabbix consists of 2 parts, zabbix server and optional component zabbix agent.
Zabbix server can provide functions such as monitoring of remote server/network status, data collection and other functions through SNMP, zabbix agent, ping, port monitoring, etc. It can run on Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, on platforms such as OS X.

Firewall configuration

1. Firewall configuration

#Firewall configuration written by system-config-securitylevel
#Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

2. Close SELINUX, vim /etc/selinux/config

SELINUX=enforcing #Comment out
SELINUXTYPE=targeted #Comment out
SELINUX=disabled #Add

setenforce 0 #Make the configuration take effect immediately
Teach you how to deploy and build LNMP and Zabbix

Preparation before compilation

1. Uninstall mysql, http and openssl that comes with the system

rpm -e --nodeps mysql httpd

2. Install the compilation tools and library files (use the yum command to install)

yum install -y apr autoconf automake bison bzip2 bzip2 cloog-ppl compat cpp curl curl-devel fontconfig fontconfig-devel freetype freetype freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng libpng-devel libjpeg libsepol-devel libselinux-devel libstdc++-devel libtool libgomp libxml2 libxml2-devel libXpm libX libtiff libtiff make mpfr ncurses ntp openssl nasm nasm openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel

Start compiling and installing LAMP

1. Install cmake

tar zxvf cmake-3.0.2.tar.gz
cd cmake-3.0.2
./configure
make
make install

2. Install MySQL

groupadd mysql #Add mysql group
useradd -g mysql mysql -s /bin/false #Create user mysql and join the mysql group, do not allow mysql users to log in directly to the system
mkdir -p /data/mysql #Create MySQL database storage directory
chown -R mysql:mysql /data/mysql #Set MySQL database storage directory permissions
mkdir -p /usr/local/mysql #Create MySQL installation directory
tar zxvf mysql-5.5.22.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql - DMYSQL_UNIX_ADDR = / tmp / mysql.sock -DDEFAULT_CHARSET = gbk -DDEFAULT_COLLATION = gbk_chinese_ci -DEXTRA_CHARSETS = all -DWITH_MYISAM_STORAGE_ENGINE = 1 -DWITH_INNOBASE_STORAGE_ENGINE = 1 -DWITH_ARCHIVE_STORAGE_ENGINE = 1 -DWITH_BLACKHOLE_STORAGE_ENGINE = 1 -DWITH_MEMORY_STORAGE_ENGINE = 1 -DWITH_FEDERATED_STORAGE_ENGINE = 1 -DWITH_READLINE = 1 -DENABLED_LOCAL_INFILE =1 -DMYSQL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/etc -DWITH_SSL=yes
make
make install

rm -rf /etc/my.cnf #Delete the default configuration file of the system (if there is no default, you don’t need to delete it)
cd /usr/local/mysql/scripts/ #Enter the MySQL installation directory./mysql_install_db
--user=mysql --basedir =/usr/local/mysql --datadir=/data/mysql #Generate mysql system database
ln -s /usr/local/mysql/my.cnf /etc/my.cnf #Add soft connection to /etc directory
cp / usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld #Add Mysql to the system to start
chmod 755 /etc/init.d/mysqld #Increase execution permission
chkconfig mysqld on # add boot

vim /etc/rc.d/init.d/mysqld #Edit startup file
basedir=/usr/local/mysql
datadir=/data/mysql

service mysqld start #Start mysql service

vim /etc/profile #Add the mysql service to the system environment variable: add the following line at the end
export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile #Make the configuration take effect immediately

The following two lines link the myslq library file to the default location of the system, so that you do not need to specify the mysql library file address when compiling software such as PHP.
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql

mkdir /var/lib/mysql #Create a directory
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #Add a soft link
mysql_secure_installation #Set the Mysql password, press Y and enter the password twice as prompted

编译注解:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql #安装目录
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock #Unix socket 文件路径,自定义此路径防报错
-DDEFAULT_CHARSET=gbk #默认字符
-DDEFAULT_COLLATION=gbk_chinese_ci #校验字符
-DEXTRA_CHARSETS=all #安装所有扩展字符集
-DWITH_MYISAM_STORAGE_ENGINE=1 #安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 #安装 innodb 存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 #安装 archive 存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 #安装 blackhole 存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 #安装 frderated 存储引擎
-DWITH_READLINE=1 #快捷键功能
-DENABLED_LOCAL_INFILE=1 #允许从本地导入数据
-DMYSQL_DATADIR=/data/mysql #数据库存放目录
-DMYSQL_USER=mysql #数据库属主
-DMYSQL_TCP_PORT=3306 #数据库端口
-DSYSCONFDIR=/etc #MySQL 配辑文件
-DWITH_SSL=yes #数据库 SSL

3. Install pcre

tar zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure --prefix=/usr/local/pcre
make && make install

4. Install openssl

tar zxvf openssl-1.0.1j.tar.gz
cd openssl-1.0.1j
./config --prefix=/usr/local/openssl
make && make install

vim /etc/profile #Add the openssl service to the system environment variable: add the following line at the end
export PATH=$PATH:/usr/local/openssl/bin

source /etc/profile #Make the configuration take effect immediately

5. Install zlib

tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make && make install

6. Install Nginx

groupadd www
useradd -g www www -s /bin/false
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/opt/openssl-1.0.1j --with-zlib=/opt/zlib-1.2.11 --with-pcre=/opt/pcre-8.38
make && make install
#把Nginx加入系统启劢
cp /opt/nginx /etc/rc.d/init.d/nginx
#增加执行权限
chmod 755 /etc/init.d/nginx
#加入开机启劢
chkconfig nginx on
#启动Nginx服务
service nginx start
注意:--with-openssl=/usr/local/openssl-1.0.1j --with-zlib=/usr/local/zlib-1.2.11 --with-pcre=/usr/local/pcre-8.38 指向的是源码包解压的路径,而不是安装的路径,否则会报错

7. Install yasm

tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install

8. Install libmcrypt

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install

9. Install libvpx

tar -xjf libvpx-v1.3.0.tar.bz2
cd libvpx-1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make && make install

10. Install tiff

tar zxvf tiff-4.0.4.tar.gz
cd tiff-4.0.4
./configure --prefix=/usr/local/tiff --enable-shared
make && make install

11. Install libpng

tar zxvf libpng-1.6.34.tar.gz
cd libpng-1.6.34
./configure --prefix=/usr/local/libpng --enable-shared
make && make install

12. Install freetype

tar zxvf freetype-2.5.4.tar.gz
cd freetype-2.5.4
./configure --prefix=/usr/local/freetype --enable-shared --without-png
make && make install

13. Install jpeg

tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-shared
make && make install

14. Install libgd

tar zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
make && make install

15. Install t1lib

tar zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make without_doc
make install

16. Install php

注意:如果系统是 64 位,请执行以下两条命令,否则安装 php 会出错(32 位系统不需要执行)
cp -frp /usr/lib64/libltdl.so* /usr/lib/
cp -frp /usr/lib64/libXpm.so* /usr/lib/

tar -zvxf php-5.6.3.tar.gz
cd php-5.6.3
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype
make && make install
cp /opt/php-7.2.3/php.ini-production /usr/local/php/etc/php.ini #Copy the php configuration file to the installation directory
rm -rf /etc/php.ini #Delete The system comes with a configuration file
ln -s /usr/local/php/etc/php.ini /etc/php.ini #Add a soft link to the /etc directory
cp /usr/local/php/etc/php-fpm.conf .default /usr/local/php/etc/php-fpm.conf #Copy template file as php-fpm configuration file
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/ local/php/etc/php-fpm.d/www.conf #Copy the template file
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #Add a soft link to / etc directory

vim /usr/local/php/etc/php-fpm.conf #edit
user = www #set php-fpm running account to www, line 148
group = www #set php-fpm running group to www, line 149
pid = run/php-fpm.pid #Cancel the preceding semicolon, line 25

Set php-fpm to boot
cp /opt/php-7.2.3/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #Copy php-fpm to startup Directory
chmod +x /etc/rc.d/init.d/php-fpm #Add execution permission
chkconfig php-fpm on #Set startup startup

vim /usr/local/php/etc/php.ini #Edit the configuration file
to find: disable_functions = #Line 305
Modified to: disable_functions =passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space , checkdnsrr, checkdnsrr, getservbyname, etservbyport , disk_total_space, posix_ctermid, posix_get_last_error, posix_getcwd, posix_getegid, posix_geteuid, posix_getgid, posix_getgrgid, posix_getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getpgrp, posix_getpid, osix_getppid, posix_getpwnam, posix_getpwuid, posix_getrlimit, posix_getsid, posix_getuid, posix_isatty ,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #List
the functions that PHP can disable. If some programs need to use this function, you can delete and cancel the disable.
Find: ;date.timezone = #Modify line 928
to: date.timezone = PRC #Cancel the preceding semicolon, set the time zone
to find: expose_php = On #Modify line 366
to: expose_php = Off #Prohibit the display of php version information
Find: short_open_tag = Off #Modify line 202
to: short_open_tag = ON #Support php short tag
find: ;opcache.enable=0 #Modify line 1878
to opcache.enable=1 #Cancel the previous semicolon, PHP supports opcode caching
Found: ;opcache.enable_cli=0 #Modify line 1881
to: opcache.enable_cli=1 #Cancel the previous semicolon, PHP supports opcode caching
Add in the last line: zend_extension=opcache.so #Enable opcode caching

Configure nginx to support php
vim /usr/local/nginx/conf/nginx.conf
Modify the /usr/local/nginx/conf/nginx.conf configuration file, you need to do the following modifications
user www www; #First line user remove the comment, modify Nginx The running group is www www;
the user and group configuration in /usr/local/php/etc/php-fpm.conf must be the same, otherwise php will run wrong
index index.html index.htm index.php; #Add index.php, Line 45
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ { #Uncomment the previous, line 65
root html; #Uncomment the previous, line 66
fastcgi_pass 127.0.0.1 :9000; #Cancel the previous comment, line 67
fastcgi_index index.php; #Cancel the previous comment, line 68
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #Cancel the previous comment, line 69
include fastcgi_params; #Cancel the previous comment , line 70
} # uncomment previous, line 71
#Cancel the comment of the FastCGI server part of the location, pay attention to the parameter of the fastcgi_param line, change it to $document_root$fastcgi_script_name, or use the absolute path

/etc/init.d/nginx restart #Restart nginx
service php-fpm start #Start php-fpm

php test

cd /usr/local/nginx/html/ #Enter the nginx default website root directory
rm -rf /usr/local/nginx/html/* #Delete the default test page
vi index.php #Create a new index.php file
<?php
$conn =mysql_connect('127.0.0.1','root','');
if ($conn){
echo "LNMP platform connect to mysql is successful!";
}else{
echo "LNMP platform connect to mysql is failed!";
}
phpinfo();
?>
:wq! #Save and exit
chown www.www /usr/local/nginx/html/ -R #Set directory owner
chmod 700 /usr/local/nginx/html/ -R #Set directory permissions
Teach you how to deploy and build LNMP and Zabbix

Install phpMyAdmin to manage MySQL

1. Unzip phpMyAdmin to the root directory of your website: /usr/local/nginx/html/

tar zxvf phpMyAdmin-4.3.11.1-all-languages.tar.gz -C /usr/local/nginx/html/

2. Rename after decompression: phpMyAdmin

cd /usr/local/nginx/html/
mv phpMyAdmin-4.3.11.1-all-languages phpMyAdmin

3. Modify the config.default.php file

cd /usr/local/nginx/html/phpMyAdmin/libraries/
Edit the config.default.php file and find the following items in turn:
Default configuration
$cfg['PmaAbsoluteUri'] = ''; #Line 39
$cfg['Servers '][$i]['host'] = 'localhost'; #line 117
$cfg['Servers'][$i]['port'] = ''; #line 124
$cfg['Servers' ][$i]['user'] = 'root'; #line 252
fg['Servers'][$i]['password'] = ''; #line 259
$cfg['Servers'][ $i]['auth_type'] = 'cookie'; #Line 230
Modify the configuration
$cfg['PmaAbsoluteUri'] = '192.168.30.199/phpMyAdmin ';
$cfg['Servers'][$i]['host' ] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '123456';
$cfg['Servers'][$i]['auth_type'] = 'cookie';

配置解释
填写 phpmyadmin 的访问网址。
填写 mysql 服务器的 IP,如果 phpMyAdmin 和 mysql 是在同一台服务器,用默认 localhost。因为我的主机名是 yunwei.localadmin 所以我用 127.0.0.1。如果不在一起,就用数据库 IP 地址。
mysql 端口号,默认 3306,可以不填。
填写 mysql 用户名。
填写 mysql 用户名的密码。
在此有四种模式可供选择,cookie,http,HTTP,config
config 方式即输入 phpmyadmin 的访问网址即可直接进入,无需输入用户名和密码,是不安全的,不推荐使用。
当该项设置为 cookie,http 或 HTTP 时,登录 phpmyadmin 需要数据用户名和密码进行验证,,具体如下:
PHP 安装模式为 Apache,可以使用 http 和 cookie;
PHP 安装模式为 CGI,可以使用 cookie

.
4. service nginx restart #Restart nginx service

Zabbix compile and install

1. Create a zabbix database and create a zabbix account

mysql -u root -p #Enter the mysql console, the password is empty
create database zabbix character set utf8; #Create a database zabbix, and the database code uses utf8 #Create
a new account zabbix, the password is: 123456. The new account has all permissions on the zabbix database, and allows the account zabbix to connect to the database from the local machine
zabbix grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '123456' with grant option;
flush privileges; # Refresh system authorization table

2. Import the zabbix database

tar zxvf zabbix-2.2.6.tar.gz #Unzip
ls /opt/zabbix-2.2.6/database/mysql #List files, you can see that there are three files: schema.sql, images.sql, data.sql
mysql -u root -p #Enter MySQL console
use zabbix #Enter database
source /opt/zabbix-2.2.6/database/mysql/schema.sql #Import script file to zabbix database
source /opt/zabbix-2.2.6/ database/mysql/images.sql #Import script file to zabbix database
source /opt/zabbix-2.2.6/database/mysql/data.sql #Import script file to zabbix database
flush privileges; #Refresh system authorization table

3. Install zabbix

groupadd zabbix #Create user group zabbix
useradd zabbix -g zabbix -s /in/falsbe #Create user zabbix and add user zabbix to user group zabbix
yum install net-snmp-deve #Install dependency packages
cd /opt/zabbix- 2.2.6 #Enter the installation directory./configure
--prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with -mysql=/usr/local/mysql/bin/mysql_config
make && make install

4. Add the port corresponding to the zabbix service

vi /etc/services #编辑,在最后添加以下代码
#Zabbix
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper

5. Modify the zabbi_server configuration file

vi /usr/local/zabbix/etc/zabbix_server.conf
DBHost=127.0.0.1 #Database IP line 77, do not use the host name here
DBName=zabbix #Database name, line 87
DBUser=zabbix #Database account, the first Line 103
DBPassword=123456 #Database password, line 111

6. Modify the zabbi_agentd configuration file

vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server=127.0.0.1 #Modify Zabbix Server server IP, line 81
ServerActive=127.0.0.1 #Modify Zabbix Server server IP, line 122
Hostname=Zabbix server Line 133

7. Add a startup script

cp /opt/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_server
/etc/rc.d/init.d/zabbix_server
#Server cp /opt/zabbix-2.2.6/misc/init. d/fedora/core/zabbix_agentd
/etc/rc.d/init.d/zabbix_agentd #Client
chmod +x /etc/rc.d/init.d/zabbix_server #Add script execution permission
chmod +x /etc/rc. d/init.d/zabbix_agentd #Add script execution permission
chkconfig zabbix_server on #Add startup startup
chkconfig zabbix_agentd on #Add startup startup

8. Modify the zabbix installation directory in the zabbix startup script

vi /etc/rc.d/init.d/zabbix_server #Edit server configuration file
BASEDIR=/usr/local/zabbix/ #zabbix installation directory

vi /etc/rc.d/init.d/zabbix_agentd #Edit client configuration file
BASEDIR=/usr/local/zabbix/ #zabbix installation directory

9. Configure the web site

cp -r /opt/zabbix-2.2.6/frontends/php/ /usr/local/nginx/html/zabbix/
chown www.www -R /usr/local/nginx/html/zabbix/
service zabbix_server start #启劢 zabbix 服务端
service zabbix_agentd start #启劢 zabbix 客户端

10. Modify php configuration file parameters

vi /etc/php.ini
#Edit and modify post_max_size =16M #POST method submission maximum limit, line 663
max_execution_time =300 #Script timeout, line 375
max_input_time =300 #Line 385

vi /usr/local/php/etc/php-fpm.conf #Edit and modify
request_terminate_timeout = 300 #Line 446

service php-fpm restart #Restart php-fpm

Web final configuration

Visit the URL http://IP/zabbix
Teach you how to deploy and build LNMP and Zabbix
Teach you how to deploy and build LNMP and Zabbix
Teach you how to deploy and build LNMP and Zabbix
Teach you how to deploy and build LNMP and Zabbix
Teach you how to deploy and build LNMP and Zabbix
Teach you how to deploy and build LNMP and Zabbix

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325386949&siteId=291194637