海运的博客

制作OpenResty RPM包

发布时间:January 27, 2014 // 分类:CentOS // No Comments

创建rpmbuild目录:

mkdir -p ~/rpmbuild/{SOURCES,SPECS,SRPMS}

下载OpenResty源码:

wget -P ~/rpmbuild/SOURCE http://openresty.org/download/ngx_openresty-1.4.3.4.tar.gz

创建spec文件:

%define nginx_home %{_localstatedir}/cache/nginx
%define nginx_user nginx
%define nginx_group nginx
%define filename ngx_openresty-1.4.3.4

Summary: High performance web server
Name: openresty
Version: 1.4.3
Release: 4%{?dist}
Vendor: nginx inc.
URL: http://openresty.org/

Source0: http://openresty.org/download/%{filename}.tar.gz
Source1: logrotate
Source2: nginx.init
Source3: nginx.sysconf
Source4: nginx.conf
Source5: nginx.vh.default.conf
Source6: nginx.vh.example_ssl.conf

License: 2-clause BSD-like license
Group: System Environment/Daemons

BuildRequires: zlib-devel
BuildRequires: pcre-devel
BuildRequires: perl
BuildRequires: openssl-devel
BuildRequires: readline-devel
Requires: initscripts >= 8.36
Requires(pre): shadow-utils
Requires(post): chkconfig
Provides: webserver

%description
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.

%package debug
Summary: debug version of nginx
Group: System Environment/Daemons
Requires: openresty
%description debug
Not stripped version of nginx built with the debugging log support.

%prep
#解压文件到build目录,默认目录名名称+版本 -n进入到指定的目录,用于文件名和解压目录名不同
%setup -q -n %{filename}

%build
./configure \
        --sbin-path=%{_sbindir}/nginx \
        --conf-path=%{_sysconfdir}/nginx/nginx.conf \
        --error-log-path=%{_localstatedir}/log/nginx/error.log \
        --http-log-path=%{_localstatedir}/log/nginx/access.log \
        --pid-path=%{_localstatedir}/run/nginx.pid \
        --lock-path=%{_localstatedir}/run/nginx.lock \
        --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
        --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
    --without-http_scgi_module \
        --user=%{nginx_user} \
        --group=%{nginx_group} \
    --with-luajit \
        --with-http_ssl_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-file-aio \
        --with-ipv6 \
        --with-debug \
        $*
make %{?_smp_mflags}
#$RPM_BUILD_DIR为rpmbuild/BUILD目录,编译软件所在的目录
%{__mv} %{_builddir}/%{filename}/build/nginx-1.4.3/objs/nginx %{_builddir}/nginx.debug
./configure \
        --sbin-path=%{_sbindir}/nginx \
        --conf-path=%{_sysconfdir}/nginx/nginx.conf \
        --error-log-path=%{_localstatedir}/log/nginx/error.log \
        --http-log-path=%{_localstatedir}/log/nginx/access.log \
        --pid-path=%{_localstatedir}/run/nginx.pid \
        --lock-path=%{_localstatedir}/run/nginx.lock \
        --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
        --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
    --without-http_scgi_module \
        --user=%{nginx_user} \
        --group=%{nginx_group} \
    --with-luajit \
        --with-http_ssl_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-file-aio \
        --with-ipv6 \
        $*
make %{?_smp_mflags}

%install
#$RPM_BUILD_ROOT 虚拟安装的根目录,位于rpmbuild/BUILDROOT/名称+版本
%{__rm} -rf $RPM_BUILD_ROOT
%{__make} DESTDIR=$RPM_BUILD_ROOT install

%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/*.default
%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/scgi_params

%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/nginx
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/run/nginx
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/cache/nginx
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/www

%{__mv} $RPM_BUILD_ROOT/usr/local/openresty/nginx/html $RPM_BUILD_ROOT%{_localstatedir}/www
%{__rm} -rf $RPM_BUILD_ROOT/usr/local/openresty/nginx/

%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d
%{__rm} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
%{__install} -m 644 -p %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
%{__install} -m 644 -p %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/default.conf
%{__install} -m 644 -p %{SOURCE6} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/example_ssl.conf

%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
%{__install} -m 644 -p %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx

# install init
%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir}
%{__install} -m755 %{SOURCE2} $RPM_BUILD_ROOT%{_initrddir}/nginx

# install log rotation stuff
%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
%{__install} -m 644 -p %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx

# install debug
%{__install} -m644 %{_builddir}/nginx.debug $RPM_BUILD_ROOT%{_sbindir}/nginx.debug

#rpm build完成后删除虚拟安装目录
%clean
%{__rm} -rf $RPM_BUILD_ROOT

%files
#默认权限目录755,文件644
%defattr(-,root,root)

%{_sbindir}/nginx

#仅包含目录
%dir %{_sysconfdir}/nginx
%dir %{_sysconfdir}/nginx/conf.d
%{_localstatedir}/www/html/
#包含目录内所有文件
/usr/local/openresty/
%attr(0777,root,root) /usr/local/openresty/luajit/bin/luajit

#配置文件升级时不覆盖
%config(noreplace) %{_sysconfdir}/nginx/nginx.conf
%config(noreplace) %{_sysconfdir}/nginx/conf.d/default.conf
%config(noreplace) %{_sysconfdir}/nginx/conf.d/example_ssl.conf
%config(noreplace) %{_sysconfdir}/nginx/mime.types
%config(noreplace) %{_sysconfdir}/nginx/uwsgi_params
%config(noreplace) %{_sysconfdir}/nginx/fastcgi_params
%config(noreplace) %{_sysconfdir}/nginx/fastcgi.conf
%config(noreplace) %{_sysconfdir}/nginx/koi-utf
%config(noreplace) %{_sysconfdir}/nginx/koi-win
%config(noreplace) %{_sysconfdir}/nginx/win-utf

%config(noreplace) %{_sysconfdir}/logrotate.d/nginx
%config(noreplace) %{_sysconfdir}/sysconfig/nginx
%{_initrddir}/nginx

%attr(0755,root,root) %dir %{_localstatedir}/cache/nginx
%attr(0755,root,root) %dir %{_localstatedir}/log/nginx

%files debug
%attr(0755,root,root) %{_sbindir}/nginx.debug

%pre
#如安装httpd删除
rpm -q httpd > /dev/null && /sbin/service httpd stop > /dev/null 2>&1 && rpm -e httpd
#安装前添加运行nginx用户
getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group}
getent passwd %{nginx_user} >/dev/null || \
    useradd -r -g %{nginx_group} -s /sbin/nologin \
    -d %{nginx_home} -c "nginx user"  %{nginx_user}
exit 0

%post
# Register the nginx service
if [ $1 -eq 1 ]; then
    /sbin/chkconfig --add nginx
    # print site info
    cat <<BANNER
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
BANNER

    # Touch and set permisions on default log files on installation

    if [ -d %{_localstatedir}/log/nginx ]; then
        if [ ! -e %{_localstatedir}/log/nginx/access.log ]; then
            touch %{_localstatedir}/log/nginx/access.log
            %{__chmod} 640 %{_localstatedir}/log/nginx/access.log
            %{__chown} nginx:adm %{_localstatedir}/log/nginx/access.log
        fi

        if [ ! -e %{_localstatedir}/log/nginx/error.log ]; then
            touch %{_localstatedir}/log/nginx/error.log
            %{__chmod} 640 %{_localstatedir}/log/nginx/error.log
            %{__chown} nginx:adm %{_localstatedir}/log/nginx/error.log
        fi
    fi
fi

%preun
if [ $1 -eq 0 ]; then
    /sbin/service nginx stop > /dev/null 2>&1
    /sbin/chkconfig --del nginx
fi

%postun
if [ $1 -ge 1 ]; then
    /sbin/service nginx upgrade &>/dev/null || :
fi

build:

yum install readline-devel pcre-devel openssl-devel rpm-build
rpmbuild -ba openresty.spec 

安装打包的rpm程序:

rpm -ivh ~/rpmbuild/RPMS/x86_64/openresty-1.4.3-4.el6.x86_64.rpm 

SaltStack配置管理Nginx

发布时间:January 27, 2014 // 分类:Puppet // No Comments

配置仓库根目录:

file_roots:
  base:
    - /srv/salt

创建入口文件:

cat > /srv/salt/top.sls << EOF
base:
  '*':  #匹配所有受控主机
    - nginx
EOF

创建nginx sls:

mkdir -p /srv/salt/nginx
cat > /srv/salt/nginx/init.sls << EOF
nginx:
  pkg:
    - name: nginx
    - installed
  service:
    - running
    - enable: True
    - reload: True
    - require:
      - pkg: nginx
      - pkg: httpd
    - watch:
      - pkg: nginx
      - file: /etc/nginx/nginx.conf
      - file: /etc/nginx/conf.d/

httpd:
  pkg:
    - name: httpd
    - removed

/etc/nginx/nginx.conf:
  file.managed:
    - source: salt://nginx/nginx.conf
    - user: root
    - group: root
    - mode: 644
 
/etc/nginx/conf.d/:
  file.recurse:
    - source: salt://nginx/conf.d/
    - user: root
    - group: root
    - dir_mode: 755
    - file_mode: 644

/home/wwwlogs/:
  file.directory:
    - makedirs: True
    - user: nginx
    - group: nginx
    - mode: 0755
    - recurse:
      - user
      - group
      - mode
EOF

执行:

salt '*' state.highstate
或
salt '*' state.sls nginx

SaltStack通过SSH管理

发布时间:January 27, 2014 // 分类:Puppet // No Comments

cat > /etc/salt/roster << EOF
test:
  host: 192.168.1.1
  user: root
  password: redhat
EOF

通过salt-ssh执行,第一次执行后会添加auth key

salt-ssh '*' cmd.run "uptime"

自动化工具SaltStack

发布时间:January 27, 2014 // 分类:Puppet // No Comments

Master:

curl -L http://bootstrap.saltstack.org | sudo sh -s -- -M -N
yum search salt-ssh

Slave:

wget -O - http://bootstrap.saltstack.org | sudo sh
yum install salt-minion

客户端配置:

Master: 192.168.1.1
#识别ID
id: test

启动客户端:

/etc/init.d/salt-minion  start

服务器端确认:

salt-key -A

执行模块命令:

salt '*' test.ping

执行shell命令:

salt '*' cmd.run "uptime"

执行脚本命令:

mkdir -p /srv/salt/scripts/
cat > /srv/salt/scripts/test.sh << EOF
#!/bin/bash
echo  "test" > /tmp/test.txt
echo $1
echo $2
echo $3
EOF
salt '*' cmd.script salt://scripts/test.sh "aa bb cc"

同步服务器状态,安装git:

cat >/srv/salt/git.sls << EOF
git:
  pkg:
    - installed
EOF
salt '*' state.sls git

查看节点信息:

salt '*' grains.ls  查看grains分类
salt '*' grains.items 查看grains所有信息
salt '*' grains.item osrelease 查看grains某个信息

内置模块:http://docs.saltstack.com/ref/modules/all/index.html

CentOS使用remi源安装最新版PHP

发布时间:January 26, 2014 // 分类:CentOS // No Comments

remi:

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

CentOS5:

rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

CentOS7:

rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

安装后源默认禁用,如需启用可修改remi.repo或:

yum --enablerepo=remi-php55 install php

src:

http://rpms.famillecollet.com/SRPMS/

webtatic:

rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm 

src:

http://repo.webtatic.com/yum/el6/SRPMS/
分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
归档