分类 linux服务器 下的文章

构建php5.3.29+phalcon2的docker环境

1、拉取centos7镜像

# arm64架构CPU
docker pull arm64v8/centos:7.9.2009

# amd64架构cpu
docker pull centos:7.6.1810

2、新建一个基础容器

# arm64架构CPU
docker run --privileged=true -it arm64v8/centos:7.9.2009 /bin/bash

# amd64架构cpu
docker run --privileged=true -it arm64v8/centos:7.9.2009 /bin/bash

3、进行构建php5.3.29和phalcon2基础环境

yum install epel-release

yum groupinstall "Development Tools" -y

yum install gcc gcc-c++ make autoconf libxml2-devel bzip2-devel curl-devel \
libjpeg-devel libpng-devel freetype-devel libmcrypt-devel \
mysql-devel openssl-devel libmcrypt-devel libicu-devel -y

  • 如果是amd64 架构不要安装mysql-devel, 用一下方式安装mysql依赖包
yum remove mariadb-devel
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.62-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-shared-5.5.62-1.el7.x86_64.rpm
yum install MySQL-devel-5.5.62-1.el7.x86_64.rpm MySQL-shared-5.5.62-1.el7.x86_64.rpm

4、开始编译

# 下载php源码包
wget https://www.php.net/distributions/php-5.3.29.tar.gz
# 解压
tar -zxf php-5.3.29.tar.gz
# 进入目录
cd php-5.3.29
# 执行配置检查
./configure \
    --prefix=/usr/local/php/5.3 \
    --with-config-file-path=/usr/local/php/5.3/etc \
    --with-mysql=mysqlnd \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-openssl \
    --with-zlib \
    --with-curl \
    --with-jpeg-dir=/usr \
    --with-png-dir=/usr \
    --with-freetype-dir=/usr \
    --enable-mbstring \
    --enable-soap \
    --enable-sockets \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-shmop \
    --enable-pcntl \
    --enable-mbregex \
    --enable-exif \
    --enable-bcmath \
    --enable-calendar \
    --enable-ftp \
    --with-mcrypt \
    --with-gd \
    --with-xmlrpc \
    --enable-intl \
    --enable-fpm \
    --disable-opcache \
    --with-libdir=lib64 \
    LIBS="-lstdc++ -lpthread"

# 配置通过后开始编译
make -j$(nproc)

# make通过后直接安装
make install

# 将源码包下的php.ini-development 文件复制到/usr/local/php/5.3/etc目录
cp php.ini-development  /usr/local/php/5.3/etc/php.ini

# 将/usr/local/php/5.3/etc目录下的php-fpm.conf.default文件重命名为php-fpm.conf
mv /usr/local/php/5.3/etc/php-fpm.conf.default /usr/local/php/5.3/etc/php-fpm.conf

5、编译phalcon2.0.1扩展

# 下载phalcon源码
https://github.com/phalcon/cphalcon/archive/refs/tags/phalcon-v2.0.1.tar.gz

# 解压源码
tar -zxf phalcon-v2.0.1.tar.gz
cd cphalcon-phalcon-v2.0.1

# 进入到源码build/64bits 目录下执行 phpize命令
phpize

# 执行配置检查configure(arm64架构)
./configure --build=aarch64-unknown-linux-gnu --with-php-config=/usr/local/php/5.3/bin/php-config

# 执行配置检查configure(amd64架构)
./configure --with-php-config=/usr/local/php/5.3/bin/php-config

# 执行编译构建
make -j$(nproc)

# 执行安装
make install

# 在php.ini文件最后添加phalcon配置项
[phalcon]
extension=phalcon.so

6、编译nginx1.8.1

wget https://nginx.org/download/nginx-1.8.1.tar.gz

# 执行配置
./configure \
  --prefix=/usr/local/nginx \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --with-http_realip_module \
  --with-http_sub_module \
  --with-http_addition_module \
  --with-pcre

# 执行编译构建
make -j$(nproc)

# 执行安装
make install

# 新建conf.d 目录,用于用户映射自定义配置文件
mkdir -p /usr/local/nginx/conf/conf.d

# 配置nginx.conf,在localhost 配置项下添加php解析服务
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
    include        fastcgi_params;
}
# 在文件最后添加引入用户自定义配置文件
include conf.d/*.conf;

7、构建php-fpm+nginx启动脚本

vim /start.sh

#!/bin/bash

/usr/local/php/5.3/sbin/php-fpm &

exec /usr/local/nginx/sbin/nginx -g "daemon off;"
  • 设置环境变量
echo 'export PATH=/usr/local/php/5.3/sbin:$PATH' >> ~/.bashrc
echo 'export PATH=/usr/local/php/5.3/bin:$PATH' >> ~/.bashrc
echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> ~/.bashrc

8、提交当前docker容器为docker 镜像

docker commit [容器ID] 镜像名:版本

docker commit 4d47739c75e5 harbor.dev.10t.link:8443/library/php5.3_http_arm64v8:0.1

9、通过新打包的镜像进行创建容器服务

  • 创建docker-compose.yml 文件
services:
  php5.3_web:
    image: harbor.dev.10t.link:8443/library/php5.3_http_arm64v8:0.1
    container_name: php5.3_web2
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "18380:80"
    privileged: true
    command: ["/bin/bash", "/start.sh"]
    volumes:
      - /User/code/demo/html:/usr/local/nginx/html
      - /User/code/demo/conf:/usr/local/nginx/conf.d
    restart: unless-stopped

10、以下是一个简单的nginx配置代码

server {
    listen       80;
    server_name  demo.test.com;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

CentOS7 安装nodejs 18版本

CentOS7 安装nodejs 18版本

1、centos7中升级make到最新版本

https://www.cnblogs.com/liujiaxin2018/p/16745159.html

  • wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz --no-check-certificate

2、安装并启用 devtoolset-8

yum install devtoolset-8
scl enable devtoolset-8 bash
gcc --version

3、永久启用 devtoolset-8

echo "source /opt/rh/devtoolset-8/enable" >> ~/.bashrc
source ~/.bashrc

4、开始编译glibc-2.28


mkdir build && cd build

CFLAGS="-O2 -Wno-error=missing-attributes" ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --enable-obsolete-nsl

make

make install

  • 以上如果make install报错,那么用以下命令重试
cd glibc-2.28
mkdir build
cd build
CFLAGS="-O2 -Wno-error=missing-attributes" ../configure --prefix=/opt/glibc-2.28 --disable-profile --enable-add-ons --enable-obsolete-nsl
make -j4
sudo make install DESTDIR=/opt/glibc-2.28
export LD_LIBRARY_PATH=/opt/glibc-2.28/lib:$LD_LIBRARY_PATH

centos 使用iptables实现只允许中国IP访问服务器或者禁止访问

安装ipset

#Debian/Ubuntu系统
apt-get -y install ipset

#CentOS系统
yum -y install ipset

CentOS 7还需要关闭firewall防火墙:

systemctl stop firewalld.service
systemctl disable firewalld.service

清空之前的规则

防止设置不生效,建议清空下之前的防火墙规则
iptables -P INPUT ACCEPT
iptables -F

创建新规则

#创建一个名为cnip的规则
ipset -N cnip hash:net
#下载国家IP段,这里以中国为例
wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone
#将IP段添加到cnip规则中
for i in $(cat /root/cn.zone ); do ipset -A cnip $i; done

设置IP段白名单

#放行IP段
iptables -A INPUT -p tcp -m set --match-set cnip src -j ACCEPT
#关掉所有端口
iptables -P INPUT DROP

这时候就只有中国的IP能访问服务器了。

禁止规则内的ip访问

iptables -A INPUT -p tcp -m set --match-set cnip src -j DROP

每个国家的IP段汇总

https://www.ipdeny.com/ipblocks/

Linux计划任务命令crontab配置详解

1、任务命令配置说明

# .---------------- 分钟 (0 - 59)
# | .-------------- 小时 (0 - 23)
# | | .------------ 天 (1 - 31)
# | | | .---------- 月 (1 - 12) OR jan,feb,mar,apr ...
# | | | | .-------- 一周中的某一天(0-6)(星期日=0或7)或周日、周一、周二、周三、周四、周五、周六
# | | | | |
# * * * * * user-name command to be executed

2、任务命令例子-1

*/10 * * * * /usr/local/php/bin/php /usr/local/apache2/htdocs/oneindex/one.php cache:refresh  这个是每十分钟执行一次

3、任务命令例子-2

0 * * * * /usr/local/php/bin/php /usr/local/apache2/htdocs/oneindex/one.php token:refresh     每小时执行一次

4、编辑计划任务相关命令

crontab -l 输出当前的crontab任务命令列表。 
crontab -r 删除当前的crontab任务命令文件。 
crontab -e 使用VISUAL或者EDITOR环境变量所指的编辑器编辑当前的crontab文件。当结束编辑离开时,编辑后的文件将自动安装。