记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。
 
0

Centos7安装LAMP环境与zabbix6

一,系统信息与配置

1,系统部署信息

  1. 主机系统: centos7.9 ,最小化安装。
  2. LAMP版本: apache 2.4.54 ,php7.4.2(php也可以采用php7最新版本),采用源码编译安装;MySQL8.0.29采用glibc包安装,不用编译安装。
  3. zabbix版本: zabbix_server端采用6.0LTS版本源码安装,zabbix_agent根据客户机情况安装。
  4. 应用部署目录: 主机数据盘挂载到/data,apache安装到/data/httpd目录,php安装到/data/php74目录,MySQL8安装到/data/mysql8目录,zabbix安装到/data/zabbix目录
  5. apache httpd程序进程运行账号: apache,MySQL8数据库进程运行账号: mysql ,zabbix程序运行账号: zabbix

2, 系统环境配置

#关掉防火墙,sellinux,这里不再讲

[root@os-247 ~]#	yum install -y epel-release
[root@os-247 ~]#	yum install libxml2-devel libcurl-devel libevent-devel \
			apr-devel apr-util-devel bzip2-devel libjpeg-devel freetype-devel \
			libpng-devel gmp-devel openssl-devel libicu-devel oniguruma-devel libxslt-devel
[root@os-247 ~]#    yum install openssl11-devel
[root@os-247 ~]#    yum groups install "Development Tools"

# 安装LAMP依赖环境与编译开发环境

[root@os-247 ~]#     useradd -M -s /sbin/nologin apache
[root@os-247 ~]#     useradd -M -s /sbin/nologin mysql
[root@os-247 ~]#     useradd -M -s /sbin/nologin zabbix

#配置程序运行账号

 

二,apache部署

1,apache安装

[root@os-247 ~]#	wget https://repo.huaweicloud.com/apache/httpd/httpd-2.4.54.tar.gz
[root@os-247 ~]#	tar -zxvf httpd-2.4.54.tar.gz
[root@os-247 ~]#	 ./configure --prefix=/data/httpd --enable-so --enable-ssl --enable-cgi \
--enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=worker
[root@os-247 ~]#	 make
[root@os-247 ~]#	 make install

#编译完成,根据编译过程报错情况解决编译问题。

[root@os-247 ~]# 	echo "PATH=/data/httpd/bin:\$PATH" > /etc/profile.d/httpd.sh
[root@os-247 ~]#	source /etc/profile.d/httpd.sh

# 添加http命令环境变量

2,apache2服务脚本

# 以下是启动服务脚本内容
[root@os-247 ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
Documentation=man:httpd.service(8)

[Service]
Type=forking
ExecStart=/data/httpd/bin/httpd -k start
ExecReload=/data/httpd/bin/httpd -k graceful
ExecStop=/data/httpd/bin/httpd -k graceful-stop

[Install]
WantedBy=multi-user.target


[root@os-247 ~]# systemctl daemon-reload

[root@os-247 ~]# systemctl enable httpd 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@os-247 ~]# systemctl start httpd 

#最后启动服务

 

 

三,MySQL8部署

1,安装mysql8

[root@os-247 ~]#   wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
[root@os-247 ~]#   tar zxvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz -C /data/
[root@os-247 ~]#   cd /data/
[root@os-247 ~]#    mv mysql-8.0.29-linux-glibc2.12-x86_64 mysql8
[root@os-247 ~]#    cd mysql8/
[root@os-247 ~]#    mkdir {data,logs,tmp,sbin}
[root@os-247 ~]#    useradd -M -s /sbin/nologin mysql
[root@os-247 ~]#    chown -R mysql:mysql /data/mysql8/logs
[root@os-247 ~]#    chown -R mysql:mysql /data/mysql8/tmp
[root@os-247 ~]#    bin/mysqld --user=mysql --basedir=/data/mysql8/ --datadir=/data/mysql8/data --initialize 
# 记录好初始化的密码
[root@os-247 mysql8]# cat /data/mysql8/my.cnf 
[client]
#password = your_password
port = 3306
#socket = /data/mysql8/tmp/mysql.sock
[mysqld]
#skip-grant-tables
port = 3306
user = mysql
#socket = /data/mysql8/tmp/mysql.sock
basedir= /data/mysql8
datadir = /data/mysql8/data
# log-error= /data/mysql8/logs/error.log
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
tmp_table_size = 64M
default_authentication_plugin = mysql_native_password
# lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 10000
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
binlog_expire_logs_seconds = 600000
slow_query_log=1
slow-query-log-file= /data/mysql8/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""
innodb_data_home_dir = /data/mysql8/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql8/data
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2
mysqlx = 0

[mysqldump]
quick
max_allowed_packet = 500M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

2,配置启动脚本与环境变量

#配置开机启动服务脚本
[root@os-247 mysql8]#   cp support-files/mysql.server  /etc/init.d/
[root@os-247 mysql8]#   cat /etc/init.d/mysqld 
basedir=/data/mysql8
datadir=/data/mysql8/data

[root@os-247 mysql8]#   chkconfig mysqld on

[root@os-247 mysql8]#  echo "PATH=/data/mysql8/bin:\$PATH" > /etc/profile.d/mysql8.sh
[root@os-247 mysql8]#  source /etc/profile.d/mysql8.sh

[root@os-247 mysql8]#   /etc/init.d/mysqld start

# 添加mysql命令环境变量

[root@os-247 mysql8]#  cat /etc/ld.so.conf.d/mysql8.conf 
		/data/mysql8/lib
#添加mysql8的共享库目录,避免php无法安装。

[root@os-247 mysql8] ldconfig



3,账号权限与创库

# 更新root密码后才可以使用,并创建zabbix相关数据库与账号密码

/etc/init.d/mysqld start
#启动数据库服务.

mysql -u root -p  
#提示输入密码

#首次登陆root需要修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc132451@';	
# 修改密码,密码形式过于简单则会报错

mysql> use mysql;
mysql> update user set host = '%'  where user ='root';
# 修改root账号远程登陆权限。

mysql> flush privileges;
#再使用[flush privileges]从mysql数据库的grant表中重新加载权限数据

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> CREATE USER `zabbix`@`%` IDENTIFIED WITH mysql_native_password BY '123456' PASSWORD EXPIRE NEVER;

mysql> grant all privileges on  zabbix.* to zabbix@'%' with grant option;

mysql> flush privileges;

#完成数据库与权限账号创建

 

四,php7部署

1,php安装

[root@os-247 php-7.4.2]#  wget http://www.php.net/distributions/php-7.4.2.tar.xz
[root@os-247 php-7.4.2]#  tar xvf php-7.4.2.tar.xz 
[root@os-247 php-7.4.2]#  cd php-7.4.2/

# 编译参数根据需要配置
[root@os-247 php-7.4.2]# ./configure --prefix=/data/php74 --with-apxs2=/data/httpd/bin/apxs \
--with-fpm-user=apache --with-fpm-group=apache --enable-fpm --with-config-file-path=/data/php74/etc \
--disable-debug --disable-rpath --with-gettext --with-gmp --with-iconv --with-openssl --with-zlib \
--with-layout=GNU --enable-exif --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--enable-shmop --enable-calendar --enable-xml  --with-mysqli --enable-intl --enable-soap --with-xsl --enable-mbstring \
--enable-pcntl --enable-gd --enable-pdo --enable-simplexml --with-curl --with-mhash --enable-bcmath --enable-opcache \
--enable-ctype  --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-freetype --with-jpeg \
--without-sqlite3 --without-pdo-sqlite

# 根据主机CPU逻辑核心数配置参数
[root@os-247 php-7.4.2]# make -j 2

[root@os-247 php-7.4.2]# make install 
Installing PHP SAPI module:       apache2handler
/data/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp7.la /data/httpd/modules
/usr/lib64/apr-1/build/libtool --mode=install install libphp7.la /data/httpd/modules/
libtool: install: install .libs/libphp7.so /data/httpd/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /data/httpd/modules/libphp7.la
libtool: install: warning: remember to run `libtool --finish /data/php-7.4.2/libs'
chmod 755 /data/httpd/modules/libphp7.so
[activating module `php7' in /data/httpd/conf/httpd.conf]
Installing shared extensions:     /data/php74/lib/php/20190902-zts/
Installing PHP CLI binary:        /data/php74/bin/
Installing PHP CLI man page:      /data/php74/share/man/man1/
Installing PHP FPM binary:        /data/php74/sbin/
Installing PHP FPM defconfig:     /data/php74/etc/
Installing PHP FPM man page:      /data/php74/share/man/man8/
Installing PHP FPM status page:   /data/php74/share/php/fpm/
Installing phpdbg binary:         /data/php74/bin/
Installing phpdbg man page:       /data/php74/share/man/man1/
Installing PHP CGI binary:        /data/php74/bin/
Installing PHP CGI man page:      /data/php74/share/man/man1/
Installing build environment:     /data/php74/lib/php/build/
Installing header files:          /data/php74/include/php/
Installing helper programs:       /data/php74/bin/
  program: phpize
  program: php-config
Installing man pages:             /data/php74/share/man/man1/
  page: phpize.1
  page: php-config.1
/data/php-7.4.2/build/shtool install -c ext/phar/phar.phar /data/php74/bin
ln -s -f phar.phar /data/php74/bin/phar
Installing PDO headers:           /data/php74/include/php/ext/pdo/


[root@os-247 php-7.4.2]# cp php.ini-production /data/php74/etc/php.ini

#复制配置文件,并修改以下内容,根据zabbix配置文件修改
[root@os-247 php-7.4.2]# cat /data/php74/etc/php.ini
short_open_tag = On
max_execution_time = 300
max_input_time = 300
post_max_size = 64M



# PHP Fatal error:  Uncaught Error: Call to undefined function imagecreatetruecolor()  ,这个报错是因为php编译参数中未加 --enable-gd 
# HP Warning:  imagettftext(): any2eucjp(): invalid code in input string ,这个报错是因为编译php的时候 --enable-gd-jis-conv 开启这个选项,
重新编译 php 取消这个参数,这也是php7低版本的bug,建议使用最新版本的php7

2,apache修改配置

[root@os-247 htdocs]# cat /data/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

#修改以上apache配置文件

[root@os-247 htdocs]# systemctl restart httpd
# 重启httpd服务

3,测试php程序

[root@os-247 htdocs]# cat /data/httpd/htdocs/phpinfo.php 
<?php
phpinfo();
?>
    
#创建phpinfo文件,打开URL,显示正常,说明php环境安装成功。

 

五,zabbix安装配置

 

1,导入数据到mysql

1,创建数据库与账号密码,授权.
	#之前已配置,这里不用配置

1)create database zabbix character set utf8 collate utf8_bin;
2)CREATE USER 'zabbix'@'%' IDENTIFIED BY '密码';
3)flush privileges;
4)grant all privileges on zabbix.* to zabbix@'%' with grant option;
5)ALTER USER 'zabbix'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
6)flush privileges;

2,导入zabbix配置数据

将下载好的zabbix安装包解压,在database/mysql目录下,有3个脚本
schema.sql images.sql data.sql

mysql -uzabbix -p123456 -hlocalhost zabbix < schema.sql
mysql -uzabbix -p123456 -hlocalhost zabbix < images.sql
mysql -uzabbix -p123456 -hlocalhost zabbix < data.sql

注:顺序不能变

 

2,安装zabbix服务器端软件

1,创建zabbix用户

[root@os-247 zabbix]# groupadd zabbix #创建用户组zabbix
[root@os-247 zabbix]# useradd zabbix -g zabbix -s /bin/false #创建用户zabbix,并且把用户zabbix加入到用户组zabbix中


[root@os-247 zabbix]# yum install -y epel-release 
[root@os-247 zabbix]# yum install -y openssl11 openssl11-devel

[root@os-247 zabbix]# cat /etc/ld.so.conf.d/mysql8.conf 
/data/mysql8/lib

[root@os-247 zabbix]# ldconfig

#在CentOS7中,默认情况下/ lib和/ usr / lib下的文件作为共享库包括在内,将mysql8的lib库文件加到搜索路径中,不然zabbix_server启动时找不到mysql相关库文件

[root@os-247 zabbix]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.12.tar.gz
[root@os-247 zabbix]# tar zxvf zabbix-6.0.12.tar.gz
[root@os-247 zabbix]# cd  zabbix-6.0.12
[root@os-247 zabbix-6.0.12]# ./configure --prefix=/data/zabbix --enable-server --enable-agent --with-mysql=/data/mysql8/bin/mysql_config --with-libcurl --with-libxml2
[root@os-247 zabbix-6.0.12]# make && make install
[root@os-247 zabbix]# chwon -R zabbix:zabbix /data/zabbix/logs

#复制启动服务脚本
[root@os-247 zabbix] cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/
[root@os-247 zabbix] cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

#修改启动脚本
[root@os-247 ~]# cat /etc/init.d/zabbix_server 
ZABBIX_BIN="/data/zabbix/sbin/zabbix_server"

[root@os-247 ~]# cat /etc/init.d/zabbix_agentd 
ZABBIX_BIN="/data/zabbix/sbin/zabbix_agentd"

#启动服务
[root@os-247 zabbix] /etc/init.d/zabbix_server start

[root@os-247 zabbix]  /etc/init.d/zabbix_agent start

#配置好zabbix_server.conf与zabbix_agent.conf后,就可以启动相关服务。


3,zabbix_server.conf配置内容

ListenPort=10051

LogFile=/data/zabbix/logs/zabbix_server.log

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

4,zabbix_agent.conf配置内容

 


LogFile=/data/zabbix/logs/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server

 

5,配置UI管理界面

 

mv ui /data/httpd/htdocs/zabbix
chown -R apache:apache  /data/httpd/htdocs/zabbix

#复制源码包中的ui目录到网站目录,并修改权限。
# 关于中文乱码,可以更换字体或是php7的bug问题

 

6,配置web界面

根据web界面显示内容与报错调整相关配置。




转载请标明出处【Centos7安装LAMP环境与zabbix6】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论