文章目錄
源碼編譯安裝nginx
[root@server2 nginx]# pwd
/srv/salt/nginx
[root@server2 nginx]# cat init.sls
install-nginx:
pkg.installed:
- pkgs:
- gcc
- make
- pcre-devel
- openssl-devel
archive.extracted:
- name: /mnt
- source: salt://nginx/nginx-1.16.1.tar.gz
cmd.run:
- name: cd /mnt/nginx-1.16.1 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx --with-http_ssl_module &> /dev/null && make &> /dev/null && make install &> /dev/null
- creates: /usr/local/nginx # 判斷如果/usr/local/nginx存在,就不會再執行name的內容
[root@server2 nginx]# cat nginx.service # nginx的啓動腳本
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@server2 nginx]# cat init.sls
install-nginx:
pkg.installed:
- pkgs:
- gcc
- make
- pcre-devel
- openssl-devel
archive.extracted:
- name: /mnt
- source: salt://nginx/nginx-1.16.1.tar.gz
cmd.run:
- name: cd /mnt/nginx-1.16.1 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx --with-http_ssl_module &> /dev/null && make &> /dev/null && make install &> /dev/null
- creates: /usr/local/nginx
file.managed:
- name: /lib/systemd/system/nginx.service
- source: salt://nginx/nginx.service
(1)vim nginx.service
3.啓動nginx
[root@server2 nginx]# cat service.sls # 啓動nginx服務
/usr/local/nginx/conf/nginx.conf:
file.managed:
- source: salt://nginx/nginx.conf
service.running:
- name: nginx
- enable: true
- reload: true
- watch:
- file: /usr/local/nginx/conf/nginx.conf
[root@server2 nginx]# cat init.sls
install-nginx:
pkg.installed:
- pkgs:
- gcc
- make
- pcre-devel
- openssl-devel
archive.extracted:
- name: /mnt
- source: salt://nginx/nginx-1.16.1.tar.gz
cmd.run:
- name: cd /mnt/nginx-1.16.1 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx --with-http_ssl_module &> /dev/null && make &> /dev/null && make install &> /dev/null
- creates: /usr/local/nginx
file.managed:
- name: /lib/systemd/system/nginx.service
- source: salt://nginx/nginx.service
include:
- nginx.service
[root@server2 nginx]# salt server4 state.sls nginx
[root@server4 conf]# systemctl status nginx # nginx啓動成功
● nginx.service - The NGINX HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
優先級恢復正常
(方式2)
4.更改nginx的配置