海运的博客

制作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 

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/

CentOS6使用Yum源安装LNMP

发布时间:December 25, 2013 // 分类:Nginx,CentOS // No Comments

编译安装LNMP太繁琐,不易部署和管理,通过系统源安装最很方便,Centos官方源软件包较少,需先安装EPEL源
安装MysQL:

yum install mysql-server
/etc/init.d/mysqld start
chkconfig mysqld on
/usr/bin/mysqladmin -u root password 'newpasswd'

安装PHP:

yum install php-fpm php-cli php-mysqlnd php-pdo php-xml php-gd php-opcache
/etc/init.d/php-fpm start
chkconfig php-fpm on

安装Nginx:

yum install nginx
/etc/init.d/nginx start
chkconfig nginx on

VMware更新后Centos6网络device "eth0" does not seem to be present解决

发布时间:December 27, 2012 // 分类:CentOS,VMware // No Comments

VMware升级到9后顺便更新了下Virtual Machine,再次启动Centos6虚拟机后不能启动网络,提示以下错误:

device "eth0" does not seem to be present, delaying initialization

原因是Centos6使用udev动态管理设备文件将MAC地址和网卡名称对应记录在udev的规则脚本中,VMware升级后虚拟机网卡MAC会改变,这样系统会认为网卡是新增的并命名为eth1,查看如下:

ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:ce:c0:1e brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.13/24 brd 192.168.1.255 scope global eth1
    inet6 fe80::20c:29ff:fece:c01e/64 scope link 

解决方法1,修改网络配置文件设备eth0为eth1:

cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE="eth1"
BOOTPROSTO=static
IPADDR=192.168.1.13
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT="yes"

解决方法2,修改udev记录的mac与网卡名称对应规则:

cat /etc/udev/rules.d/70-persistent-net.rules 
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ce:c0:1e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

CentOS调整默认启动的TTY终端数量

发布时间:December 26, 2012 // 分类:CentOS // No Comments

CentOS默认启动6个TTY,在控制台下可用Alt+[F1—F6]键在不同的终端之间切换,通过SSH虚拟终端管理远程服务器是用不到这些的,可减少启动的TTY数量减少系统资源占用。
CentOS5修改配置文件注释禁止启动的TTY即可:

cat /etc/inittab
#2:2345:respawn:/sbin/mingetty tty2
#3:2345:respawn:/sbin/mingetty tty3
#4:2345:respawn:/sbin/mingetty tty4
#5:2345:respawn:/sbin/mingetty tty5
#6:2345:respawn:/sbin/mingetty tty6

CentOS6下修改启动的TTY数量:

sed -i 's/\/dev\/tty\[1-6\]/\/dev\/tty\[1-1\]/g' /etc/init/start-ttys.conf 
sed -i 's/\/dev\/tty\[1-6\]/\/dev\/tty\[1-1\]/g' /etc/sysconfig/init
#修改为启动1个TTY

关闭指定终端:

initctl stop tty TTY=/dev/ttyn

踢出指定终端用户:

pkill -kill -t ttyn
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...