08 saltstack生产实例-apahce+php+redis
1、apache+php
前几章的LAMP: https://www.cnblogs.com/venicid/p/11276232.html#_label2
Php放在apache
1、目录结构
2、php安装.sls,配置file
安装
[root@linux-node1 /srv/salt/prod/modules/apache]# cat php.sls
php-install: pkg.installed: - pkgs: - php - php-pdo - php-mysql php-config: file.managed: - name: /etc/php.ini - source: salt://modules/apache/files/php.ini - user: root - group: root - mode: 644
配置文件
[root@linux-node1 /srv/salt/prod/modules/apache]# cp /etc/php.ini files/
3、apache安装.sls,配置file
安装
[root@linux-node1 /srv/salt/prod/modules/apache]# cat init.sls
include: - modules.apache.php apache-install: pkg.installed: - name: httpd apache-config: file.managed: - name: /etc/httpd/conf/httpd.conf - source: salt://modules/apache/files/httpd.conf - user: root - group: root - mode: 644 - template: jinja - defaults: IPADDR: {{ grains['fqdn_ip4'][0] }} PORT: 80 - watch_in: - service: apache-service apache-service: service.running: - name: httpd - enable: True - reload: True
配置文件
[root@linux-node1 files]# cp /etc/httpd/conf/httpd.conf .
[root@linux-node1 /srv/salt/prod/modules/apache]# vim files/httpd.conf
4、test
[root@# localhost ~]# salt 'linux-node1*' state.sls modules.apache.init saltenv=prod [root@# localhost ~]# salt 'linux-node2*' state.sls modules.apache.init saltenv=prod
5、问题
问题描述:grains获取minion的ip地址时,获取失败。
解决:
saltstack master端grains.item fqdn_ip4 获取不到fqdn_ip4 值原因以及解决办法
关于hostname和fqdn的区别和获取及设置
最后:
重启master、minion
2、shop-user业务分离,管理apahce php
产品线分级 shop
按业务分类:
功能模块写在modules,通用的
剩下的都是业务目录
不同的产品线对应不同的业务
1、目录结构
模块和业务目录
基本模块安装目录
业务对应的服务目录
2、php+apahce的基础安装配置
php基础安装.sls
[root@linux-node1 /srv/salt/prod/modules/apache]# cat php.sls php-install: pkg.installed: - pkgs: - php - php-pdo - php-mysql
apache基础安装.sls,如上
[root@linux-node1 /srv/salt/prod/modules/apache]# cat init.sls include: - modules.apache.php apache-install: pkg.installed: - name: httpd apache-config: file.managed: - name: /etc/httpd/conf/httpd.conf - source: salt://modules/apache/files/httpd.conf - user: root - group: root - mode: 644 - template: jinja - defaults: IPADDR: {{ grains['fqdn_ip4'][0] }} PORT: 80 - watch_in: - service: apache-service apache-service: service.running: - name: httpd - enable: True - reload: True
3、配置文件,修改如上
配置文件
[root@linux-node1 /srv/salt/prod/modules/apache]# cp /etc/php.ini files/
4、shop-user业务
业务对应的php+apahce的 sls文件
[root@linux-node1 /srv/salt/prod/shop-user]# cat web.sls include: - modules.apache.init php-config: file.managed: - name: /etc/php.ini - source: salt://shop-user/files/php.ini - user: root - group: root - mode: 644 web-config: file.managed: - name: /etc/httpd/conf.d/shop-user.conf - source: salt://shop-user/files/shop-user.conf - user: root - group: root - mode: 644 - watch_in: - service: apache-service
File将要放在的位置
业务对应的配置文件
php.ini如上
shop-user.conf 待续................
3、php使用redis实现session 共享
https://www.cnblogs.com/youjiaxing/p/10407361.html
1、shop-user下的php.conf
用来进行session共享的
2、shop-user的apahce+php的sls
[root@linux-node1 /srv/salt/prod/shop-user]# cat web.sls include: - modules.apache.init php-config: # php的conf file.managed: - name: /etc/php.ini - source: salt://shop-user/files/php.ini - user: root - group: root - mode: 644 php-redis-config: # session共享的
file.managed: - name: /etc/httpd/conf.d/php.conf - source: salt://shop-user/files/php.conf - user: root - group: root - mode: 644 web-config: # apache的conf file.managed: - name: /etc/httpd/conf.d/shop-user.conf - source: salt://shop-user/files/shop-user.conf - user: root - group: root - mode: 644 - watch_in: - service: apache-service
3、虚拟主机shop-user.conf
[root@linux-node1 /srv/salt/prod/shop-user]# cat files/shop-user.conf <VirtualHost *:8080> ServerAdmin admin@example.com DocumentRoot /var/www/html ServerName demo.example.com ErrorLog "logs/demo-error.log" CustomLog "logs/demo-access.log" common </VirtualHost>
4、修改apahce的8088端口
[root@linux-node1 /srv/salt/prod/modules/apache]# vim init.sls
5、启动
[root@linux-node1 /srv/salt/prod/shop-user]# salt \* state.sls shop-user.web saltenv=prod
容器,每个容器只跑一个虚拟主机
查看端口
6、配置php主页
node1,node2
[root@linux-node1 /srv/salt/prod/shop-user]# cd /var/www/html/ [root@linux-node1 /var/www/html]# cat info.php <?php phpinfo(); ?>
访问主页
php和redis连上了
我的未连接到redis上面???
未开启redis主从模式吗?
7、添加到top.sls中
启动
[root@linux-node1 /srv/salt/base]# salt \* state.highstate