目录
centos7.9系统安装部署zabbix5.0的脚本(建议使用)
zabbix部署(版本为zabbix_server (Zabbix) 3.0.32)
记录zabbix的环境搭建(zabbix3.4)
lnmp:linux nginx mysql php
lamp:linux apache mysql php
查看系统:
[root@localhost conf.d]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost conf.d]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
删除原有的httpd,mysql,php,zabbix等软件 #未安装可跳过
[root@localhost ~]# rpm -qa|grep httpd
#删除mysql
[root@localhost ~]# rpm -qa|grep mysql
mysql57-community-release-el7-10.noarch
mysql-community-libs-5.7.39-1.el7.x86_64
mysql-community-client-5.7.39-1.el7.x86_64
mysql-community-devel-5.7.39-1.el7.x86_64
mysql-community-common-5.7.39-1.el7.x86_64
mysql-community-libs-compat-5.7.39-1.el7.x86_64
mysql-community-server-5.7.39-1.el7.x86_64
php71w-mysqlnd-7.1.33-1.w7.x86_64
[root@localhost ~]# rpm -e `rpm -qa|grep mysql` --nodeps
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
warning: file /usr/lib64/mysql/libmysqlclient_r.so.18.1.0: remove failed: No such file or directory
warning: file /usr/lib64/mysql/libmysqlclient_r.so.18: remove failed: No such file or directory
[root@localhost ~]# rm -rf `find / -user mysql`;rm -rf `find / -name mysql`
[root@localhost ~]# ls /usr/share/mysql/
[root@localhost ~]# ls /var/lib/mysql/
#删除php
[root@localhost lib]# php -v
PHP 7.1.33 (cli) (built: Oct 26 2019 10:16:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies
[root@localhost lib]# rpm -qa|grep php
php71w-common-7.1.33-1.w7.x86_64
php71w-process-7.1.33-1.w7.x86_64
php71w-pecl-redis-3.1.6-1.w7.x86_64
php71w-embedded-7.1.33-1.w7.x86_64
php71w-gd-7.1.33-1.w7.x86_64
php71w-cli-7.1.33-1.w7.x86_64
php71w-pdo-7.1.33-1.w7.x86_64
php71w-pear-1.10.4-1.w7.noarch
php71w-pecl-memcached-3.0.4-1.w7.x86_64
php71w-pecl-mongodb-1.5.3-1.w7.x86_64
php71w-devel-7.1.33-1.w7.x86_64
php71w-opcache-7.1.33-1.w7.x86_64
php71w-mbstring-7.1.33-1.w7.x86_64
php71w-fpm-7.1.33-1.w7.x86_64
php71w-xml-7.1.33-1.w7.x86_64
php71w-pecl-igbinary-2.0.5-1.w7.x86_64
php71w-mcrypt-7.1.33-1.w7.x86_64
mod_php71w-7.1.33-1.w7.x86_64
[root@localhost lib]# rpm -e `rpm -qa|grep php` --nodeps
warning: /etc/php-fpm.d/www.conf saved as /etc/php-fpm.d/www.conf.rpmsave
[root@localhost lib]# rm -rf `find / -name php`;rm -rf `find / -user php`
[root@localhost lib]# rpm -qa|grep php
[root@localhost lib]#
#删除zabbix
rpm -e $(rpm -qf $(which zabbix_server))
rpm -e $(rpm -qf $(which zabbix_agent2))
rpm -e $(rpm -qf $(which zabbix_get))
rm -rf `find / -user zabbix`;rm -rf `find / -name zabbix`
关闭selinux
[root@localhost conf.d]# getenforce
Disabled
#详细步骤:
#临时关闭防火墙
[root@oldboy ~]# setenforce 0
[root@oldboy ~]# getenforce
Permissive
#永久关闭防火墙
[root@oldboy ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
-- 表示selinux安全策略功能是启用状态
# permissive - SELinux prints warnings instead of enforcing.
-- 表示selinux安全策略只是显示警告信息,不会进行安全处理
# disabled - No SELinux policy is loaded.
-- 表示selinux安全策略功能彻底禁用
SELINUX=enforcing
[root@oldboy ~]# sed -i '7s#enforcing#disabled#g' /etc/selinux/config
[root@oldboy ~]# reboot
关闭防火墙
[root@localhost conf.d]# systemctl status firewalld #systemctl stop firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@localhost conf.d]# systemctl status iptables #systemctl stop iptables
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
Active: inactive (dead)
配置yum源
#配置官方源更新地址:提前备份原来的yum源 #cp -R /etc/yum.repos.d/ /etc/yum.repos.d.bak/
[root@localhost lib]# rm -rf /etc/yum.repos.d/*
[root@localhost lib]# ll /etc/yum.repos.d/
total 0
[root@oldboy ~]# curl -s -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 配置第三方epel源更新地址:
[root@oldboy ~]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@oldboy ~]# yum clean all #清除YUM缓存
[root@oldboy ~]# yum makecache
安装apache
[root@localhost conf.d]# yum install httpd -y
[root@localhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Mar 24 2022 14:57:57
[root@localhost conf.d]# systemctl start httpd
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-10-09 05:32:59 EDT; 4min 38s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 2500 (httpd)
安装mariadb ###Server version: 5.5.68-MariaDB MariaDB Server 进入mysql使用\s查看
[root@localhost conf.d]# yum install mariadb mariadb-server -y
[root@localhost conf.d]# systemctl start mariadb
[root@localhost ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-10-09 05:36:41 EDT; 29s ago
Process: 2630 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 2546 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
安装php
[root@localhost ~]# yum install -y php php-mysql
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
安装zabbix ###zabbix_server (Zabbix) 3.4.15 命令输入zabbix_server -V查看
#安装本体
[root@zabbix-proxy ~]# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
[root@zabbix-proxy ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
Preparing... ################################# [100%]
package zabbix-release-5.0-1.el7.noarch (which is newer than zabbix-release-3.4-2.el7.noarch) is already installed
file /etc/yum.repos.d/zabbix.repo from install of zabbix-release-3.4-2.el7.noarch conflicts with file from package zabbix-release-5.0-1.el7.noarch #提示与原来的软件包冲突
[root@zabbix-proxy ~]# rpm -qa|grep zabbix
zabbix-release-5.0-1.el7.noarch
zabbix-web-5.0.0-1.el7.noarch
[root@zabbix-proxy ~]# rpm -e `rpm -qa|grep zabbix` #删除原有软件包后再次安装
[root@zabbix-proxy ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-3.4-2.el7 ################################# [100%]
#安装zabbix的包
yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender
配置zabbix
#导入表
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.15/
[root@localhost zabbix-server-mysql-3.4.15]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[root@localhost zabbix-server-mysql-3.4.15]# gunzip create.sql.gz
[root@localhost zabbix-server-mysql-3.4.15]# ls
AUTHORS ChangeLog COPYING create.sql NEWS README
[root@localhost zabbix-server-mysql-3.4.15]# pwd
/usr/share/doc/zabbix-server-mysql-3.4.15
#创建一个zabbix库
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'root';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> use zabbix;
MariaDB [(none)]> source /usr/share/doc/zabbix-server-mysql-3.4.15/create.sql;
MariaDB [(none)]>\s
MariaDB [(none)]>\q
配置zabbix server配置文件
#分别设置localhost、数据库、用户、密码等内容
[root@localhost ~]# cd /etc/zabbix
[root@localhost ~]# vi zabbix_server.conf
#修改以下内容:
DBHost=localhost
DBUser=zabbix
DBPassword=root
DBSocket=/var/lib/mysql/mysql.sock
#运行zabbix-server服务
[root@localhost ~]# systemctl start zabbix-server.service
[root@localhost ~]# systemctl status zabbix-server.service
● zabbix-server.service - Zabbix Server
Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-10-09 05:42:41 EDT; 22s ago
Process: 3016 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 3018 (zabbix_server)
配置php
[root@localhost ~]# cd /etc/httpd/conf.d
[root@localhost ~]# vi zabbix.conf
#新增一行上海时间设置php_value date.timezone Asia/Shanghai
重启httpd服务
[root@localhost ~]# systemctl restart httpd
部署zabbix
#打开部署网页
[root@localhost conf.d]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d1:46:2e brd ff:ff:ff:ff:ff:ff
inet 192.168.220.128/24 brd 192.168.220.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fed1:462e/64 scope link
valid_lft forever preferred_lft forever
#登陆zabbix网址设置
浏览器输入http://192.168.1.95/zabbix
#部署网页设置
点击next step
next step
next step
next step
完成安装

设置中文
#点击右上角的小头像图标,如下面图中所示,就可以进入到设置界面。
设置语言,点击update按钮,就可以更新配置,回到主界面,就可以看到界面上大部分都变成了中文
修改成功
对服务器自身进行监控
#点击配置,主机,点击停用的,弹出框选择确定
#启用成功
参考原文链接:https://blog.csdn.net/u011027547/article/details/123411205
centos7.9系统安装部署zabbix5.0的脚本(建议使用)
首先删除原有httpd,mysql,php,zabbix
脚本如下:#此处数据库密码需要有大小写字母特殊符号和数字
#!/bin/bash
exec 5>&1
exec 6>&2
exec 1>/dev/null
exec 2>/dev/null
#1.卸载原有软件包
#删除mysql
rpm -e $(rpm -qa|grep mariadb) --nodeps;rm -rf `find / -user mariadb`;rm -rf `find / -name mariadb`
rpm -e $(rpm -qa|grep mysql) --nodeps;rm -rf `find / -user mysql`;rm -rf `find / -name mysql`
#删除php
rpm -e `rpm -qa|grep php` --nodeps;rm -rf `find / -user php`;rm -rf `find / -name php`
#删除zabbix
rpm -e $(rpm -qa|grep zabbix) --nodeps;rm -rf `find / -user zabbix`;rm -rf `find / -name zabbix`
#删除httpd
rpm -e $(rpm -qa|grep httpd) --nodeps;rm -rf `find / -user apache`;rm -rf `find / -name httpd`
#2.关闭selinux
setenforce 0;sed -i '7s#enforcing#disabled#g' /etc/selinux/config
#3.关闭防火墙
systemctl stop firewalld;systemctl stop iptables
systemctl disable firewalld;systemctl disable iptables
exec 1>&5
exec 2>&6
#定义函数
function fun(){
echo "欢迎进入zabbix5.0的安装部署:"
echo "1、安装zabbix:"
echo "2、安装mysql数据库:"
echo "3、退出安装!"
read -p "请选择:" num
}
#安装菜单
while true
do
fun
case $num in
1)
echo "正在安装部署zabbix,请等待..."
rpm -ivh http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sleep 3;
yum install -y zabbix-server-mysql zabbix-agent
sleep 3;
yum install -y centos-release-scl #说明见文章《SCL软件集》
sleep 3;
sed -i '11c enabled=1' /etc/yum.repos.d/zabbix.repo
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
echo "zabbix安装完成!"
sleep 3;
;;
2)
echo "正在安装部署mysql数据库,请等待..."
wget -P /usr/local/src http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
sleep 3;
rpm -ivh /usr/local/src/mysql57-community-release-el7-8.noarch.rpm
sleep 3;
yum install -y mysql-server
sleep 3;
systemctl start mysqld && systemctl enable mysqld
echo "数据库启动成功!"
sleep 3;
result="`grep 'temporary password' /var/log/mysqld.log | tail -1`"
p1="`echo $result |awk '{print $NF}'`"
read -p "请输入数据库密码:" num1 ##此处数据库密码需要有大小写字母特殊符号和数字
mysqladmin -uroot -p"$p1" password "$num1"
echo "密码修改成功!"
echo "请输入数据库密码!"
mysql -u root -p <<EOF
create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@localhost identified by "$num1";
flush privileges;
quit
EOF
sleep 3;
echo "请输入修改后的数据库密码!"
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
echo "数据导入成功!"
sed -i "s/# DBPassword=/DBPassword=$num1/" /etc/zabbix/zabbix_server.conf
echo "数据库配置完成!"
sleep 3;
result1="`tail -1 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf | awk '{print $NF}'`"
result2="Asia/Shanghai"
sed -i 's/\;//g' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
sed -i "s#$result1#$result2#g" /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
echo "时区修改成功!"
sleep 3;
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl start zabbix-server zabbix-agent httpd rh-php72-php-fpm
echo "zabbix启动成功!"
break
;;
3)
echo "已退出安装!"
break
;;
esac
#echo -n "Enter a value to back: "
#read -n1 option
done
zabbix部署(版本为zabbix_server (Zabbix) 3.0.32)
zabbix的组成
zabbix官网: https://www.zabbix.com
zabbix 主要由2部分构成 zabbix server和 zabbix agent
zabbix proxy是用来管理其他的agent,作为代理
安装部署
1.环境检查
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# uname -r
3.10.0-1160.el7.x86_64
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2.脚本部署
服务端ip 192.168.220.118
#!/bin/bash
#clsn
#设置解析 注意:网络条件较好时,可以不用自建yum源
# echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts
#安装zabbix源、aliyun YUM源
cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak/
rm -f /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
#安装zabbix
yum install -y zabbix-server-mysql zabbix-web-mysql
#安装启动 mariadb数据库
yum install -y mariadb-server
systemctl start mariadb.service
#创建数据库
mysql -e 'create database zabbix character set utf8 collate utf8_bin;'
mysql -e 'grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix";'
#导入数据
zcat /usr/share/doc/zabbix-server-mysql-3.0.32/create.sql.gz|mysql -uzabbix -pzabbix zabbix
#配置zabbix-server连接mysql
sed -i '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
#添加时区
sed -i '18a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
#解决中文乱码
yum -y install wqy-microhei-fonts
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
#启动服务
systemctl start zabbix-server
systemctl start httpd
#写入开机自启动
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start mariadb.service
systemctl start httpd
systemctl start zabbix-server
EOF
#输出信息
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"
2.客户端ip 192.168.220.128
#!/bin/bash
#clsn
#设置解析
#echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts
#安装zabbix源、aliyu nYUM源
cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak/
rm -f /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
#安装zabbix客户端
yum install zabbix-agent -y
sed -i 's#Server=127.0.0.1#Server=192.168.220.128#' /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent.service
#写入开机自启动
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start zabbix-agent.service
EOF
3.检查联通性
服务端安装zabbix-get检测工具
yum install zabbix-get
在服务端进行测试
注意:只能在服务端进行测试
zabbix_get -s 192.168.220.128 -p 10050 -k "system.cpu.load[all,avg1]"
[root@localhost ~]# zabbix_get -s 192.168.220.128 -p 10050 -k "system.cpu.load[all,avg1]"
0.000000
zabbix_get命令
参考文章:https://www.cnblogs.com/--smile/p/11086958.html
zabbix_get命令是在server端用来检查agent端的一个命令,在添加完主机或者触发器后,不能正常获得数据,可以用zabbix_get来检查能否采集到数据,以便判断问题症结所在。
zabbix_get 参数说明:
-s --host: 指定客户端主机名或者IP
-p --port:客户端端口,默认10050
-I --source-address:指定源IP,写上zabbix server的ip地址即可,一般留空,服务器如果有多ip的时候,你指定一个。
-k --key:你想获取的key
至于使用长参数还是短的,自己选,我经常使用-s而不是-host,
如果不知道key参数可以使用 zabbix_agentd -p 寻找自己想要找的参数
[root@host~]# zabbix_agentd -p | grep system.cpu.load #zabbix_agentd命令属于软件包zabbix-agent
system.cpu.load[all,avg1] [d|0.040000]
[root@host~]# zabbix_agent2 -p|grep system.hostname #zabbix_agent2命令属于软件包zabbix-agent2
system.hostname [s|zabbix-proxy]
[root@host~]# rpm -qf `which zabbix_agent2`
zabbix-agent2-5.0.42-1.el7.x86_64
如果不知道zabbix_get在什么路径,可以使用find / -name zabbix_get查找
[root@host ~]# find / -name zabbix_get
/usr/local/zabbix/bin/zabbix_get
/data/tools/zabbix-4.0.3/src/zabbix_get
/data/tools/zabbix-4.0.3/src/zabbix_get/zabbix_get
案例:
[root@zabbix ~]# zabbix_get -s 192.168.1.7 -p 10050 -k system.cpu.load[all,avg1]
0.000000
id命令使用与-s /sbin/nologin
[root@iZbp16mm3xbwen89azh9ffZ ~]# useradd -u1111 www -s /sbin/nologin -M #不用来用户登录
[root@iZbp16mm3xbwen89azh9ffZ ~]# tail /etc/passwd
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
admin:x:1000:1000::/home/admin:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/false
nginx:x:997:995:Nginx web server:/var/lib/nginx:/sbin/nologin
test:x:1002:1002::/home/test:/bin/bash
dongm:x:1003:1004::/home/dongm:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
www:x:1111:1111::/home/www:/sbin/nologin
[root@iZbp16mm3xbwen89azh9ffZ ~]# id 1111
uid=1111(www) gid=1111(www) groups=1111(www)
[root@iZbp16mm3xbwen89azh9ffZ ~]# id www
uid=1111(www) gid=1111(www) groups=1111(www)
SCL软件集
参考文章:如何在 CentOS 上启用软件集合 (SCL)_软件包后面带scl_allway2的博客-CSDN博客
参考文章:Linux开发环境——SCL软件集_软件包后面带scl_天山老妖的博客-CSDN博客
参考文章:linux scl,scl命令_疯狂Excel的博客-CSDN博客
Red Hat Enterprise Linux (RHEL) 及其社区分支 CentOS 提供 10 年生命周期,这意味着 RHEL/CentOS 的每个版本都更新了长达 10 年的安全补丁。虽然如此长的生命周期保证了企业用户急需的系统兼容性和可靠性,但不利之处在于,随着底层 RHEL/CentOS 版本接近生命周期结束 (EOF),核心应用程序和运行时环境变得陈旧。例如,CentOS 6.5 的 EOL 日期为 2020 年 11 月 30 日,附带python2.6.6 和 MySQL 5.1.73,按照今天的标准,它们已经很老了。
另一方面,尝试手动升级 RHEL/CentOS 上的开发工具链和运行时环境可能会破坏您的系统,除非所有依赖项都得到正确解决。一般情况下,不建议手动升级,除非您知道自己在做什么。
该软件集合(SCL)库应运而生,在这种情况下,RHEL / CentOS用户的帮助。创建 SCL 的目的是为 RHEL/CentOS 用户提供一种方法,可以轻松安全地安装和使用多个(可能是更新的)应用程序和运行时环境,而不会弄乱现有系统。这与可能导致已安装软件包之间冲突的其他第三方存储库形成对比。
在本教程的其余部分,让我向您展示如何设置 SCL 存储库以及如何从 SCL 安装和启用包。
设置软件集合 (SCL) 存储库
SCL 可用于 CentOS 6.5 及更高版本。要设置 SCL,只需运行:
在 CentOS 7 及更高版本上:
# yum install centos-release-scl -y #安装完成后/etc/yum.repos.d 目录下面会多出来scl相关的yum源(CentOS-SCLo-scl-rh.repo和CentOS-SCLo-scl.repo)
在 CentOS 6.X 上:
# yum install centos-release-SCL
# rpm -qa|grep scl
centos-release-scl-rh-2-3.el7.centos.noarch
centos-release-scl-2-3.el7.centos.noarch
要从 SCL 启用和运行应用程序,您还需要安装以下软件包。包含scl命令
# yum install scl-utils -y
# yum install scl-utils-build -y
# rpm -qf `which scl`
scl-utils-20130529-19.el7.x86_64
您可以通过运行以下命令浏览 SCL 存储库中可用软件包的完整列表:
# yum list all --enablerepo='centos-sclo-rh' #手动输入,此命令输出系统仓库包括源centos-sclo-rh在内的所有软件包
现在您已经设置了 SCL,您可以继续安装 SCL 中的任何包。
从 SCL 安装和启用包
您可以使用以下命令搜索 SCL 包:
# yum list all --enablerepo='centos-sclo-rh'|grep centos-sclo-rh|grep <keyword>
假设您要安装 Python 3.5。继续像往常一样安装它:
# yum list all --enablerepo='centos-sclo-rh'|grep centos-sclo-rh|grep python
.......
rh-python35.x86_64
.......
# yum install rh-python35.x86_64 -y
安装的文件位于/opt/rh目录下
# ls -F /opt/rh
devtoolset-7/ rh-python35/
您可以随时通过运行以下命令检查从 SCL 安装的软件包列表:
# scl --list
devtoolset-7
rh-python35
SCL 的一个好处是从 SCL 安装包不会覆盖任何系统文件,并且保证不会与其他系统库和应用程序发生任何冲突。
比如python安装后查看默认版本python27,会看到默认版本还是一样的:
# python --version
Python 2.7.5
如果您想尝试已安装的 SCL 包,您需要使用以下命令在每个命令的基础上显式启用它
# scl enable <scl-package-name> <command>
例如,rh-python35为python命令启用包:
# scl enable rh-python35 'python --version'
Python 3.5.1
如果您想在启用python35包的同时运行多个命令,您实际上可以创建一个启用 SCL 的bash会话,如下所示。
# scl enable rh-python35 bash
在此bash会话中,默认值python将切换到 3.5,直到您键入exit并终止会话。
简而言之,SCL 与virtualenvPython 有点相似,但更通用,因为您可以为比 Python 多得多的应用程序启用/禁用 SCL 会话。
# scl --list
devtoolset-7
rh-php72
# scl enable rh-php72 bash
# php --version
PHP 7.2.24 (cli) (built: Nov 4 2019 10:23:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# ps -ef|grep bash
root 2020 119734 0 14:31 pts/1 00:00:00 scl enable rh-php72 bash
root 2021 2020 0 14:31 pts/1 00:00:00 /bin/bash /var/tmp/sclamnFaR
root 2024 2021 0 14:31 pts/1 00:00:00 bash
root 2933 2024 0 14:35 pts/1 00:00:00 grep --color=auto bash
root 100452 100381 0 12:31 pts/0 00:00:00 -bash
root 119734 119651 0 13:44 pts/1 00:00:00 -bash
root 128859 119651 0 14:18 pts/2 00:00:00 -bash
# echo $$
2024
# exit
exit
# scl enable rh-php72 "php --version"
PHP 7.2.24 (cli) (built: Nov 4 2019 10:23:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
有关 SCL 的更多详细说明,请参阅官方快速入门指南。
9956

被折叠的 条评论
为什么被折叠?



