def use_file(c, path=local.http_path, test=True): """ fab -H 192.168.0.81 source.use_file --path /home/repo """ c = conn(c) system.install(c, 'yum-plugin-priorities') use_repo(c, 'file.repo', local.file_repo, path, test=test) """ yum whatprovides parted
def file(c, path=local.http_path): """ fab -H 192.168.0.81 source.file --path /home/repo """ c = conn(c) print("make file repo on {}, path [{}]".format(c.host, path)) system.install(c, 'createrepo') c.run('createrepo {}'.format(path))
def use_epel(c): """ add epel and so on yum-fastestmirror wget -O /etc/yum.repos.d/CentOS-Base-aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo """ c = conn(c) system.install(c, 'source')
def install(c): c = hosts.one() download(c, local.name, source=local.source) copy_pack(c, dest=local.temp) system.install(0, 'java') hosts.execute('sudo rm -rf /opt/*{}*'.format(local.name)) for index in hosts.lists(): unpack(hosts.conn(index), local.name, path=package(local.temp)) configure(c)
def http(c, path=local.http_path, port=local.http_port): """ fab -H 192.168.0.81 source.http --path /home/repo --port 80 """ c = conn(c) print("make http repo on {}, path [{}]".format(c.host, path)) """ 准备 """ system.install(c, 'httpd createrepo') c.run('mkdir -p {path}'.format(path=path)) """ 配置 """ c.run(''' cd {home}; mkdir -p save cp -f conf/httpd.conf save mv conf.d/welcome.conf save rm conf.d/local.conf -rf'''.format(home=local.http_home)) c.run('''cat << EOF > {host} <VirtualHost *:{port}> DocumentRoot "{path}" <Directory "{path}"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost> EOF'''.format(host=local.http_host, path=path, port=port)) if port != local.http_port: sed.append(hosts.conn(2), 'Listen {port}'.format(port=port), 'Listen 80', local.http_conf) print("set http port [{}]".format(port)) """ 配置: root path不要配置在 /tmp下,无法识别 httpd -t """ if globing.invoke: c.run('''cat << EOF > /start.sh #!/bin/bash echo "start httpd ... [`date`]" #mkdir -p /run/httpd for count in {1..5} do echo "start $count" httpd -DFOREGROUND sleep 1 done EOF''') else: c.run('systemctl restart httpd')
def use_http(c, url, test=True): """ fab -H 192.168.0.81 source.use_http --url 192.168.0.81 yum repo 相关: yum repolist yum whatprovides parted yum --disablerepo="*" --enablerepo="http_repo" list available yum --downloadonly --downloaddir=./ install apt-cacher-ng """ c = conn(c) system.install(c, 'yum-plugin-priorities') use_repo(c, 'http.repo', local.http_repo, url, test=test) """ 测试是否成功
def install_master(c): c = hosts.conn(0) system.install(c, 'compile') unpack(c, name, path=package(local.temp), parent=local.compile) with c.cd(os.path.join(local.compile, 'redis')): if not file_exist(c, 'src', 'redis-server'): c.run("make MALLOC=libc -j5") c.run("mkdir -p {}".format(base(name))) with c.cd("src"): c.run("sudo \\cp redis-server redis-cli ../redis.conf {}".format( base(name))) configure(c)
def use_sshd(c, user='******', paww='111111'): set_invoke(True) c = conn(c) system.install(c, 'bash-completion tar sudo') system.install(c, 'passwd openssh-server openssh-clients') """ 方法1:此方法显示 chpasswd 无法找到 """ if user != 'root': c.run('/usr/sbin/useradd {user}'.format(user=user)) c.run("echo '{user}:{paww}' | /usr/sbin/chpasswd".format(user=user, paww=paww)) # c.run("echo '{paww}' | password {user} --stdin".format(user=user, paww=paww)) c.run(''' sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config sed -i 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config sed -i 's/^#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config sed -i 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N '' mkdir -p /root/.ssh/ cd /root/.ssh echo '' | ssh-keygen -t rsa -N '' echo "StrictHostKeyChecking=no" > /root/.ssh/config echo "UserKnownHostsFile=/dev/null" >> /root/.ssh/config ''') if globing.invoke: c.run('''cat << EOF > /start.sh #!/bin/bash echo "start sshd" /usr/sbin/sshd -D EOF''')
def install(c): c = conn(c) system.install(c, 'postgresql95-server.x86_64 postgresql95-contrib.x86_64') c.run('''cat << EOF > /var/lib/pgsql/.pgsql_profile export PGDATA={data} export PATH=\$PATH:/usr/pgsql-9.5/bin EOF'''.format(data=local.data)) """ 初始化 """ c.run('''su - postgres <<EOF source /var/lib/pgsql/.pgsql_profile rm /var/lib/pgsql/9.5/data -rf echo "{pasw}" > /tmp/pwfile initdb -U {user} --pwfile /tmp/pwfile rm /tmp/pwfile -rf EOF'''.format(user=local.user, pasw=local.pasw)) configure(c) c.run('systemctl enable postgresql-9.5.service') c.run('systemctl start postgresql-9.5.service')
def install(c): """ yum remove -y MariaDB-server MariaDB-client 官网:https://mariadb.com/kb/en/library/yum/ 配置:https://www.cnblogs.com/lclq/p/5760966.html """ c = conn(c) """ 更新源 """ c.run('''echo ' [mariadb] name = MariaDB baseurl=http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=0' > /etc/yum.repos.d/mariadb.repo ''') c.run('''sed -i 's#yum\.mariadb\.org#mirrors.ustc.edu.cn/mariadb/yum#' /etc/yum.repos.d/mariadb.repo''') system.install(c, 'MariaDB-server MariaDB-client') configure(c) initialize(c)
def prepare(c): system.install(0, 'java', 'unzip')
def prepare(c): system.install(hosts.one(), 'java', 'unzip git')
def proxy(c, path=local.proxy_path): """ fab -H 192.168.0.81 source.proxy --path /home/proxy yum remove -y apt-cacher-ng systemctl restart apt-cacher-ng.service tail -f /var/log/apt-cacher-ng/* https://www.pitt-pladdy.com/blog/_20150720-132951_0100_Home_Lab_Project_apt-cacher-ng_with_CentOS/ https://fabianlee.org/2018/02/11/ubuntu-a-centralized-apt-package-cache-using-apt-cacher-ng/ docker: https://hub.docker.com/r/minimum2scp/apt-cacher-ng """ c = conn(c) c.run('rm {conf} -rf'.format(conf=local.proxy_conf)) """ 这里需要分开安装:先安装 epel-release 之后,才能安装 其他server """ system.install(c, 'source') system.install(c, 'apt-cacher-ng') from common.disk import file_exist if not file_exist(c, local.proxy_conf): print("conf file {} not exist".format(local.proxy_conf)) exit(-1) c.run('mkdir -p {path}; chmod 777 {path}'.format(path=path)) c.run('''curl https://www.centos.org/download/full-mirrorlist.csv \ | sed 's/^.*"http:/http:/' | sed 's/".*$//' | grep ^http > /etc/apt-cacher-ng/centos_mirrors''' ) """ 修改配置 """ sed.path(local.proxy_conf) sed.grep(**{'sep': ': '}) sed.append( c, '''VfilePatternEx: ^(/\\\\?release=[0-9]+&arch=.*|.*/RPM-GPG-KEY-examplevendor)$''', '# WfilePatternEx:') # sed.append(c, '''VfilePatternEx: ^/\\\\?release=[0-9]+&arch=''', '# WfilePatternEx:') sed.append(c, 'Remap-centos: file:centos_mirrors \/centos', 'Remap-debrep', pos=-1) sed.append( c, 'PassThroughPattern: (mirrors\\\\.fedoraproject\\\\.org|some\\\\.other\\\\.repo|yet\\\\.another\\\\.repo):443', '# PassThroughPattern: private-ppa', pos=5) sed.update(c, 'CacheDir', path) """ 启动服务 """ if globing.invoke: c.run('''cat << EOF > /start.sh #!/bin/bash echo "start proxy" touch /var/log/apt-cacher-ng/a.log #/etc/init.d/apt-cacher-ng start /usr/sbin/apt-cacher-ng -c /etc/apt-cacher-ng pidfile=/var/run/apt-cacher-ng/pid SocketPath=/var/run/apt-cacher-ng/socket foreground=0 tail -f /var/log/apt-cacher-ng/* EOF''') else: c.run('systemctl restart apt-cacher-ng.service') system.help( c, ''' http://{host}:3142 http://{host}:3142/acng-report.html tail -f /var/log/apt-cacher-ng/*'''.format(host=c.host), 'you can visit') # proxy(hosts.conn(0))